ClickHouse stores system tables in the system database. These tables are created automatically when the ClickHouse server starts, and most are held in random access memory (RAM). You can read from system tables and detach them from other tables, but you cannot drop or alter them.
This topic describes the six most commonly used system tables in E-MapReduce (EMR).
system.clusters
Stores information about the clusters defined in the configuration file and the servers in each cluster.
| Column | Type | Description |
|---|---|---|
cluster | String | Cluster name |
shard_num | UInt32 | Shard number within the cluster, starting from 1 |
shard_weight | UInt32 | Relative weight of the shard when writing data |
replica_num | UInt32 | Replica number within the shard, starting from 1 |
host_name | String | Hostname as specified in the configuration file |
host_address | String | Host IP address resolved from the Domain Name System (DNS) |
port | UInt16 | Port used to connect to the host |
user | String | Username used to connect to the host |
errors_count | UInt32 | Number of times the host failed to reach the replica |
slowdowns_count | UInt32 | Number of replica switches caused by slow connections during peer-to-peer requests |
estimated_recovery_time | UInt32 | Seconds remaining until the replica error count resets to zero |
Example: list all replicas in a cluster
SELECT * FROM system.clusters LIMIT 2 FORMAT Vertical;Output:
Row 1:
──────
cluster: cluster_emr
shard_num: 1
shard_weight: 1
replica_num: 1
host_name: emr-header-1.cluster-24****
host_address: 192.168.**.**
port: 9000
is_local: 1
user: default
default_database:
errors_count: 0
estimated_recovery_time: 0
Row 2:
──────
cluster: cluster_emr
shard_num: 1
shard_weight: 1
replica_num: 2
host_name: emr-worker-1.cluster-24****
host_address: 192.168.**.**
port: 9000
is_local: 0
user: default
default_database:
errors_count: 0
estimated_recovery_time: 0system.query_log
Stores metadata for executed queries, including start time, duration, error messages, and resource usage. It does not store query results.
Each query creates one or two rows depending on the outcome:
Successful query: two rows with
type=QueryStartandQueryFinishError during execution: two rows with
type=QueryStartandExceptionWhileProcessingError before execution: one row with
type=ExceptionBeforeStart
The table records two query categories:
Initial queries: sent directly by a client
Subqueries: initiated by another query for distributed execution; parent query details appear in the
initial_*columns
| Column | Type | Description |
|---|---|---|
type | Enum8 | Query lifecycle event: QueryStart (1), QueryFinish (2), ExceptionBeforeStart (3), ExceptionWhileProcessing (4) |
event_date | Date | Date the event occurred |
event_time | DateTime | Time the event occurred |
event_time_microseconds | DateTime64 | Event time with microsecond precision |
query_start_time | DateTime | Time query execution started |
query_start_time_microseconds | DateTime64 | Query start time with microsecond precision |
query_duration_ms | UInt64 | Query execution duration, in milliseconds |
read_rows | UInt64 | Total rows read from all tables and table functions, including subqueries for IN and JOIN. For distributed queries, aggregates values from all replicas. Cache does not affect this value. |
read_bytes | UInt64 | Total bytes read from all tables and table functions, including subqueries for IN and JOIN. For distributed queries, aggregates values from all replicas. Cache does not affect this value. |
written_rows | UInt64 | Rows written by INSERT queries; 0 for all other query types |
written_bytes | UInt64 | Bytes written by INSERT queries; 0 for all other query types |
result_rows | UInt64 | Rows in the result of a SELECT or INSERT query |
result_bytes | UInt64 | RAM used to store the query result, in bytes |
memory_usage | UInt64 | Memory consumed by the query |
query | String | Query text |
exception | String | Exception message, if any |
exception_code | Int32 | Exception code |
stack_trace | String | Stack trace; empty if the query completed without error |
is_initial_query | UInt8 | 1 if initiated by a client; 0 if initiated by another query for distributed execution |
user | String | User who initiated the query |
query_id | String | Query ID |
address | IPv6 | Client IP address |
port | UInt16 | Client port number |
initial_user | String | User who ran the initial query in a distributed execution |
initial_query_id | String | ID of the initial query in a distributed execution |
initial_address | IPv6 | IP address where the parent query originated |
initial_port | UInt16 | Port of the client that initiated the parent query |
interface | UInt8 | Interface used: 1 = TCP, 2 = HTTP |
os_user | String | Operating system username on the machine running clickhouse-client |
client_hostname | String | Hostname of the machine running clickhouse-client or another TCP client |
client_name | String | Name of clickhouse-client or another TCP client |
client_revision | UInt32 | Revision of clickhouse-client or another TCP client |
client_version_major | UInt32 | Major version of clickhouse-client or another TCP client |
client_version_minor | UInt32 | Minor version of clickhouse-client or another TCP client |
client_version_patch | UInt32 | Patch version of clickhouse-client or another TCP client |
http_method | UInt8 | HTTP method: 0 = TCP interface, 1 = GET, 2 = POST |
http_user_agent | String | UserAgent HTTP header from HTTP queries |
quota_key | String | Quota key from the quota configuration |
revision | UInt32 | ClickHouse server revision |
ProfileEvents | Map(String, UInt64) | Performance counters for various metrics. See the system.events table for descriptions. |
Settings | Map(String, String) | Settings changed when the client ran the query. Set log_query_settings = 1 to enable recording. |
thread_ids | Array(UInt64) | IDs of threads that participated in query execution |
Settings.Names | Array(String) | Names of changed settings. Set log_query_settings = 1 to enable recording. |
Settings.Values | Array(String) | Values corresponding to the names in Settings.Names |
Example: find slow queries
SELECT
query_id,
query_duration_ms,
read_rows,
memory_usage,
substring(query, 1, 100) AS query_preview
FROM system.query_log
WHERE type = 'QueryFinish'
ORDER BY query_duration_ms DESC
LIMIT 10
FORMAT Vertical;Example: find failed queries
SELECT
type,
query_start_time,
exception_code,
exception,
substring(query, 1, 100) AS query_preview
FROM system.query_log
WHERE type IN ('ExceptionBeforeStart', 'ExceptionWhileProcessing')
ORDER BY query_start_time DESC
LIMIT 10;Example: check a single log entry
SELECT * FROM system.query_log LIMIT 1 FORMAT Vertical;Output:
Row 1:
──────
type: QueryStart
event_date: 2021-08-12
event_time: 2021-08-12 14:11:58
query_start_time: 2021-08-12 14:11:58
query_duration_ms: 0
read_rows: 0
read_bytes: 0
written_rows: 0
written_bytes: 0
result_rows: 0
result_bytes: 0
memory_usage: 0
current_database: default
query: SELECT * FROM system.query_log LIMIT 1 FORMAT Vertical;
exception_code: 0
exception:
stack_trace:
is_initial_query: 1
user: default
query_id: 08e1336c-696f-4fad-b01b-255b77e56b1f
address: ::ffff:127.0.0.1
port: 60500
initial_user: default
initial_query_id: 08e1336c-696f-4fad-b01b-255b77e56b1f
initial_address: ::ffff:127.0.0.1
initial_port: 60500
interface: 1
os_user: root
client_hostname: emr-header-1.cluster-235053
client_name: ClickHouse
client_revision: 54438
client_version_major: 20
client_version_minor: 8
client_version_patch: 12
http_method: 0
http_user_agent:
quota_key:
revision: 54438
thread_ids: []
ProfileEvents.Names: []
ProfileEvents.Values: []
Settings.Names: ['use_uncompressed_cache','load_balancing','max_memory_usage']
Settings.Values: ['0','random','10000000000']system.zookeeper
Stores information about nodes in ZooKeeper. This table exists only when ZooKeeper is configured.
Every query against system.zookeeper must include a WHERE clause with either a path = or path IN condition, corresponding to the ZooKeeper path whose child nodes you want to retrieve. If the specified path does not exist, an exception is thrown.
| Column | Type | Description |
|---|---|---|
name | String | Node name |
path | String | Path to the node |
value | String | Node value |
dataLength | Int32 | Length of the node value |
numChildren | Int32 | Number of child nodes |
czxid | Int64 | Transaction ID that created the node |
mzxid | Int64 | Transaction ID of the last modification |
pzxid | Int64 | Transaction ID of the last change to child nodes (addition or deletion) |
ctime | DateTime | Time the node was created |
mtime | DateTime | Time the node was last modified |
version | Int32 | Node version; increments with each change |
cversion | Int32 | Transaction ID of the last deletion or addition of child nodes |
aversion | Int32 | Number of changes to the access control list (ACL) |
ephemeralOwner | Int64 | Transaction ID of the owner of this ephemeral node |
Example queries
Retrieve all child nodes under a specific path:
SELECT *
FROM system.zookeeper
WHERE path = '/clickhouse/tables/01-08/visits/replicas'
FORMAT Vertical;Retrieve child nodes under multiple paths in a single query:
SELECT *
FROM system.zookeeper
WHERE path IN ('/', '/clickhouse');Output for the first query:
Row 1:
──────
name: example01-08-1.yandex.ru
value:
czxid: 932998691229
mzxid: 932998691229
ctime: 2015-03-27 16:49:51
mtime: 2015-03-27 16:49:51
version: 0
cversion: 47
aversion: 0
ephemeralOwner: 0
dataLength: 0
numChildren: 7
pzxid: 987021031383
path: /clickhouse/tables/01-08/visits/replicas
Row 2:
──────
name: example01-08-2.yandex.ru
value:
czxid: 933002738135
mzxid: 933002738135
ctime: 2015-03-27 16:57:01
mtime: 2015-03-27 16:57:01
version: 0
cversion: 37
aversion: 0
ephemeralOwner: 0
dataLength: 0
numChildren: 7
pzxid: 987021252247
path: /clickhouse/tables/01-08/visits/replicassystem.replicas
Stores status information for all replicated tables on the local server. Use this table to monitor replica health.
Only one replica can hold the leader role at a time. The leader schedules background merge operations. Write operations can run on any replica that is available and has an active ZooKeeper session, regardless of whether it is the leader.
A replica enters read-only mode in any of these situations:
The configuration has no ZooKeeper session defined
An unknown error occurs when reinitializing a ZooKeeper session
ZooKeeper is reinitialized mid-session
| Column | Type | Description |
|---|---|---|
database | String | Database name |
table | String | Table name |
engine | String | Table engine name |
is_leader | UInt8 | 1 if this replica is currently the leader |
can_become_leader | UInt8 | 1 if this replica is eligible to become the leader |
is_readonly | UInt8 | 1 if this replica is in read-only mode |
is_session_expired | UInt8 | 1 if the ZooKeeper session has expired; similar behavior to is_readonly |
future_parts | UInt32 | Number of data parts expected from pending inserts or merges |
parts_to_check | UInt32 | Number of data parts queued for integrity verification |
zookeeper_path | String | ZooKeeper path for the table data |
replica_name | String | Name of this replica in ZooKeeper; unique across replicas of the same table |
replica_path | String | ZooKeeper path for replica data; equivalent to zookeeper_path/replicas/replica_path |
columns_version | Int32 | Table schema version; counts the number of ALTER operations applied. Replicas with different values have not all applied the same ALTER operations. |
queue_size | UInt32 | Number of pending operations (inserts and merges); same value as future_parts |
inserts_in_queue | UInt32 | Number of data blocks waiting to be inserted. A large value may indicate a problem. |
merges_in_queue | UInt32 | Number of data blocks waiting to be merged. Merges can take time, so this may stay above zero for extended periods. |
part_mutations_in_queue | UInt32 | Number of pending mutations |
queue_oldest_time | DateTime | Timestamp of the oldest queued operation, if queue_size > 0 |
inserts_oldest_time | DateTime | Timestamp of the oldest queued insert |
merges_oldest_time | DateTime | Timestamp of the oldest queued merge |
part_mutations_oldest_time | DateTime | Timestamp of the oldest queued mutation |
log_max_index | UInt64 | Highest entry number in the general activity log. Non-zero only when an active ZooKeeper session exists. |
log_pointer | UInt64 | Highest log entry number the replica has copied to its execution queue, plus one. If log_pointer < log_max_index, the replica is behind. Non-zero only when an active ZooKeeper session exists. |
last_queue_update | DateTime | Time the queue was last updated. Non-zero only when an active ZooKeeper session exists. |
absolute_delay | UInt64 | Current replication lag for this replica, in seconds. Non-zero only when an active ZooKeeper session exists. |
total_replicas | UInt8 | Total number of known replicas for the table |
active_replicas | UInt8 | Number of replicas with an active ZooKeeper session |
Example: check replica status for a table
SELECT * FROM system.replicas WHERE table = 'visits' FORMAT Vertical;Example: identify lagging replicas
SELECT
database,
table,
replica_name,
absolute_delay,
queue_size,
inserts_in_queue,
merges_in_queue
FROM system.replicas
WHERE absolute_delay > 0
ORDER BY absolute_delay DESC;Output for the first query:
Row 1:
──────
database: cltest
table: flat_xl_customer_local
engine: ReplicatedMergeTree
is_leader: 1
can_become_leader: 1
is_readonly: 0
is_session_expired: 0
future_parts: 0
parts_to_check: 0
zookeeper_path: /cltest/cluster_emr-1/flat_xl_customer_local
replica_name: emr-header-1.cluster-235053
replica_path: /cltest/cluster_emr-1/flat_xl_customer_local/replicas/emr-header-1.cluster-235053
columns_version: -1
queue_size: 0
inserts_in_queue: 0
merges_in_queue: 0
part_mutations_in_queue: 0
queue_oldest_time: 1970-01-01 08:00:00
inserts_oldest_time: 1970-01-01 08:00:00
merges_oldest_time: 1970-01-01 08:00:00
part_mutations_oldest_time: 1970-01-01 08:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index: 100157
log_pointer: 100158
last_queue_update: 1970-01-01 08:00:00
absolute_delay: 0
total_replicas: 2
active_replicas: 2
zookeeper_exception:system.storage_policies
Stores the storage policies and volume priorities defined in the server configuration file.
| Column | Type | Description |
|---|---|---|
policy_name | String | Storage policy name |
volume_name | String | Volume name within the storage policy |
volume_priority | UInt64 | Volume order in the configuration file |
disks | String | Names of disks assigned to this volume |
max_data_part_size | UInt64 | Maximum size of a data part that can be stored on this volume's disks |
move_factor | Float64 | Ratio of free disk space to total disk space. If the ratio exceeds this value, ClickHouse moves data to the next volume. |
Example: list all storage policies
SELECT * FROM system.storage_policies;Output:
┌policy_name─┬─volume_name─┬─volume_priority─┬─disks────────────┬─volume_type─┬─max_data_part_size┬─move_factor─┐
│ default │ default │ 1 │ ['default'] │ JBOD │ 0 │ 0 │
│ hdd_in_order │ single │ 1 │ ['disk1','disk2','disk3','disk4'] │ JBOD │ 0 │ 0.1 │
└───────┴──────┴─────────┴─────────────────┴───────┴─────────┴─────────┘system.disks
Stores information about the disks defined in the server configuration file.
| Column | Type | Description |
|---|---|---|
name | String | Disk name as defined in the configuration file |
path | String | Mount path of the disk in the file system |
free_space | UInt64 | Available disk space, in bytes |
total_space | UInt64 | Total disk capacity, in bytes |
keep_free_space | UInt64 | Disk space reserved and kept free, in bytes. Set by the keep_free_space_bytes parameter in the disk configuration. |
Example: check disk space across all configured disks
SELECT
name,
path,
formatReadableSize(free_space) AS free,
formatReadableSize(total_space) AS total,
round(free_space / total_space * 100, 1) AS free_pct
FROM system.disks;Example: list raw disk information
SELECT * FROM system.disks;Output:
┌─name─┬─path─────────┬──free_space┬─total_space┬─keep_free_space┬─type──┐
│ default │ /var/lib/clickhouse/ │ 17236594688 │ 84014424064 │ 0 │ local │
│ disk1 │ /mnt/disk1/clickhouse/ │ 17226108928 │ 84003938304 │ 10485760 │ local │
│ disk2 │ /mnt/disk2/clickhouse/ │ 28623364096 │ 84003938304 │ 10485760 │ local │
│ disk3 │ /mnt/disk3/clickhouse/ │ 34770505728 │ 84003938304 │ 10485760 │ local │
│ disk4 │ /mnt/disk4/clickhouse/ │ 59107045376 │ 84003938304 │ 10485760 │ local │
└────┴─────────────┴───────┴──────┴────────┴─────┘