2021-01-25 14:13:29 +00:00
---
2022-04-09 13:29:05 +00:00
sidebar_position: 9
sidebar_label: EmbeddedRocksDB
2020-10-01 10:59:51 +00:00
---
2022-06-02 10:55:18 +00:00
# EmbeddedRocksDB Engine
2020-10-01 10:59:51 +00:00
This engine allows integrating ClickHouse with [rocksdb ](http://rocksdb.org/ ).
2020-11-08 15:41:16 +00:00
## Creating a Table {#table_engine-EmbeddedRocksDB-creating-a-table}
2020-10-01 10:59:51 +00:00
``` sql
CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1],
name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2],
...
2022-08-09 13:48:49 +00:00
) ENGINE = EmbeddedRocksDB([ttl, read_only]) PRIMARY KEY(primary_key_name)
2020-10-01 10:59:51 +00:00
```
2022-08-09 13:48:49 +00:00
Engine parameters:
2020-10-01 10:59:51 +00:00
2022-08-09 13:48:49 +00:00
- `ttl` - time to live. TTL is accepted in seconds. Not specifying/passing or non-positive TTL behaves like TTL = infinity.
2022-08-10 13:20:25 +00:00
- `read_only` - when `read_only` is set to `true` , read-only mode is used. For storage with TTL, compaction will not be triggered (neither manual nor automatic), so no expired entries are removed.
2021-07-26 18:17:39 +00:00
- `primary_key_name` – any column name in the column list.
2021-01-22 16:40:58 +00:00
- `primary key` must be specified, it supports only one column in the primary key. The primary key will be serialized in binary as a `rocksdb key` .
- columns other than the primary key will be serialized in binary as `rocksdb` value in corresponding order.
- queries with key `equals` or `in` filtering will be optimized to multi keys lookup from `rocksdb` .
2020-10-01 10:59:51 +00:00
Example:
``` sql
CREATE TABLE test
(
`key` String,
`v1` UInt32,
`v2` String,
2021-12-01 20:12:10 +00:00
`v3` Float32
2020-10-01 10:59:51 +00:00
)
2020-11-08 15:41:16 +00:00
ENGINE = EmbeddedRocksDB
2020-10-01 10:59:51 +00:00
PRIMARY KEY key
2021-01-26 19:24:06 +00:00
```
2021-07-26 18:17:39 +00:00
## Metrics
There is also `system.rocksdb` table, that expose rocksdb statistics:
```sql
SELECT
name,
value
FROM system.rocksdb
┌─name──────────────────────┬─value─┐
│ no.file.opens │ 1 │
│ number.block.decompressed │ 1 │
└───────────────────────────┴───────┘
```
2021-07-26 18:17:39 +00:00
## Configuration
You can also change any [rocksdb options ](https://github.com/facebook/rocksdb/wiki/Option-String-and-Option-Map ) using config:
```xml
< rocksdb >
< options >
< max_background_jobs > 8< / max_background_jobs >
< / options >
< column_family_options >
< num_levels > 2< / num_levels >
< / column_family_options >
< tables >
< table >
< name > TABLE< / name >
< options >
< max_background_jobs > 8< / max_background_jobs >
< / options >
< column_family_options >
< num_levels > 2< / num_levels >
< / column_family_options >
< / table >
< / tables >
< / rocksdb >
```
2021-09-19 20:05:54 +00:00
[Original article ](https://clickhouse.com/docs/en/engines/table-engines/integrations/embedded-rocksdb/ ) <!--hide-->