> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> The `Atomic` engine supports non-blocking `DROP TABLE` and `RENAME TABLE` queries, and atomic `EXCHANGE TABLES`queries. The `Atomic` database engine is used by default.

# Atomic

The `Atomic` engine supports non-blocking [`DROP TABLE`](#drop-detach-table) and [`RENAME TABLE`](#rename-table) queries, and atomic [`EXCHANGE TABLES`](#exchange-tables) queries. The `Atomic` database engine is used by default in open-source ClickHouse.

<Note>
  On ClickHouse Cloud, the [`Shared` database engine](/products/cloud/features/infrastructure/shared-catalog#shared-database-engine) is used by default and also supports
  the above mentioned operations.
</Note>

<h2 id="creating-a-database">
  Creating a database
</h2>

```sql theme={null}
CREATE DATABASE test [ENGINE = Atomic] [SETTINGS disk=...];
```

<h2 id="specifics-and-recommendations">
  Specifics and recommendations
</h2>

<h3 id="table-uuid">
  Table UUID
</h3>

Each table in the `Atomic` database has a persistent [UUID](/reference/data-types/uuid) and stores its data in the following directory:

```text theme={null}
/clickhouse_path/store/xxx/xxxyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy/
```

Where `xxxyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy` is the UUID of the table.

By default, the UUID is generated automatically. However, users can explicitly specify the UUID when creating a table, though this is not recommended.

For example:

```sql theme={null}
CREATE TABLE name UUID '28f1c61c-2970-457a-bffe-454156ddcfef' (n UInt64) ENGINE = ...;
```

<Note>
  You can use the [show\_table\_uuid\_in\_table\_create\_query\_if\_not\_nil](/reference/settings/session-settings#show_table_uuid_in_table_create_query_if_not_nil) setting to display the UUID with the `SHOW CREATE` query.
</Note>

<h3 id="rename-table">
  RENAME TABLE
</h3>

[`RENAME`](/reference/statements/rename) queries do not modify the UUID or move table data. These queries execute immediately and do not wait for other queries that are using the table to complete.

<h3 id="drop-detach-table">
  DROP/DETACH TABLE
</h3>

When using `DROP TABLE`, no data is removed. The `Atomic` engine just marks the table as dropped by moving it's metadata to `/clickhouse_path/metadata_dropped/` and notifies the background thread. The delay before the final table data deletion is specified by the [`database_atomic_delay_before_drop_table_sec`](/reference/settings/server-settings/settings#database_atomic_delay_before_drop_table_sec) setting.
You can specify synchronous mode using `SYNC` modifier. Use the [`database_atomic_wait_for_drop_and_detach_synchronously`](/reference/settings/session-settings#database_atomic_wait_for_drop_and_detach_synchronously) setting to do this. In this case `DROP` waits for running `SELECT`, `INSERT` and other queries which are using the table to finish. The table will be removed when it's not in use.

<h3 id="exchange-tables">
  EXCHANGE TABLES/DICTIONARIES
</h3>

The [`EXCHANGE`](/reference/statements/exchange) query swaps tables or dictionaries atomically. For instance, instead of this non-atomic operation:

```sql title="Non-atomic" theme={null}
RENAME TABLE new_table TO tmp, old_table TO new_table, tmp TO old_table;
```

you can use an atomic one:

```sql title="Atomic" theme={null}
EXCHANGE TABLES new_table AND old_table;
```

<h3 id="replicatedmergetree-in-atomic-database">
  ReplicatedMergeTree in atomic database
</h3>

For [`ReplicatedMergeTree`](/reference/engines/table-engines/mergetree-family/replication) tables, it is recommended not to specify the engine parameters for the path in ZooKeeper and the replica name. In this case, the configuration parameters [`default_replica_path`](/reference/settings/server-settings/settings#default_replica_path) and [`default_replica_name`](/reference/settings/server-settings/settings#default_replica_name) will be used. If you want to specify engine parameters explicitly, it is recommended to use the `{uuid}` macros. This ensures that unique paths are automatically generated for each table in ZooKeeper.

<h3 id="metadata-disk">
  Metadata disk
</h3>

When `disk` is specified in `SETTINGS`, the disk is used to store table metadata files.
For example:

```sql theme={null}
CREATE TABLE db (n UInt64) ENGINE = Atomic SETTINGS disk=disk(type='local', path='/var/lib/clickhouse-disks/db_disk');
```

If unspecified, the disk defined in `database_disk.disk` is used by default.

<h2 id="see-also">
  See also
</h2>

* [system.databases](/reference/system-tables/databases) system table
