title_wip

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/engines/database-engines/atomic.md)

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](/docs/cloud/reference/shared-catalog#shared-database-engine) is used by default and also supports
the above mentioned operations.

## Creating a database[​](#creating-a-database "Direct link to Creating a database")

```
CREATE DATABASE test [ENGINE = Atomic] [SETTINGS disk=...];
```

## Specifics and recommendations[​](#specifics-and-recommendations "Direct link to Specifics and recommendations")

### Table UUID[​](#table-uuid "Direct link to Table UUID")

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

```
/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:

```
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](/docs/operations/settings/settings#show_table_uuid_in_table_create_query_if_not_nil) setting to display the UUID with the `SHOW CREATE` query.

### RENAME TABLE[​](#rename-table "Direct link to RENAME TABLE")

[`RENAME`](/docs/sql-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.

### DROP/DETACH TABLE[​](#drop-detach-table "Direct link to DROP/DETACH TABLE")

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`](/docs/operations/server-configuration-parameters/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`](/docs/operations/settings/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.

### EXCHANGE TABLES/DICTIONARIES[​](#exchange-tables "Direct link to EXCHANGE TABLES/DICTIONARIES")

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

```
RENAME TABLE new_table TO tmp, old_table TO new_table, tmp TO old_table;
```

you can use an atomic one:

```
EXCHANGE TABLES new_table AND old_table;
```

### ReplicatedMergeTree in atomic database[​](#replicatedmergetree-in-atomic-database "Direct link to ReplicatedMergeTree in atomic database")

For [`ReplicatedMergeTree`](/docs/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`](/docs/operations/server-configuration-parameters/settings#default_replica_path) and [`default_replica_name`](/docs/operations/server-configuration-parameters/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.

### Metadata disk[​](#metadata-disk "Direct link to Metadata disk")

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

```
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.

## See also[​](#see-also "Direct link to See also")

- [system.databases](/docs/operations/system-tables/databases) system table

- [Creating a database](#creating-a-database)- [Specifics and recommendations](#specifics-and-recommendations)
    - [Table UUID](#table-uuid)- [RENAME TABLE](#rename-table)- [DROP/DETACH TABLE](#drop-detach-table)- [EXCHANGE TABLES/DICTIONARIES](#exchange-tables)- [ReplicatedMergeTree in atomic database](#replicatedmergetree-in-atomic-database)- [Metadata disk](#metadata-disk)- [See also](#see-also)

Was this page helpful?