Project: ClickHouse (App Definition and Development / Database)
File: replicas.md

slug: /en/operations/system-tables/replicas Contains information and status for replicated tables residing on the local server. This table can be used for monitoring. The table contains a row for every Replicated\* table. Example: ``` sql SELECT * FROM system.replicas WHERE table = 'test_table' FORMAT Vertical ``` ``` text Query id: dc6dcbcb-dc28-4df9-ae27-4354f5b3b13e Row 1: database: db table: test_table engine: ReplicatedMergeTree is_leader: 1 canbecomeleader: 1 is_readonly: 0 issessionexpired: 0 future_parts: 0 partstocheck: 0 zookeeperpath: /test/testtable replica_name: r1 replicapath: /test/testtable/replicas/r1 columns_version: -1 queue_size: 27 insertsinqueue: 27 mergesinqueue: 0 partmutationsin_queue: 0 queueoldesttime: 2021-10-12 14:48:48 insertsoldesttime: 2021-10-12 14:48:48 mergesoldesttime: 1970-01-01 03:00:00 partmutationsoldest_time: 1970-01-01 03:00:00 oldestparttoget: 117170 oldestparttomergeto: oldestparttomutateto: logmaxindex: 206 log_pointer: 207 lastqueueupdate: 2021-10-12 14:50:08 absolute_delay: 99 total_replicas: 5 active_replicas: 5 lostpartcount: 0 lastqueueupdate_exception: zookeeper_exception: replicaisactive: {'r1':1,'r2':1} ``` Columns: `database` (`String`) - Database name `table` (`String`) - Table name `engine` (`String`) - Table engine name `is_leader` (`UInt8`) - Whether the replica is the leader. Multiple replicas can be leaders at the same time. A replica can be prevented from becoming a leader using the `mergetree` setting `replicatedcanbecomeleader`. The leaders are responsible for scheduling background merges. Note that writes can be performed to any replica that is available and has a session in ZK, regardless of whether it is a leader. `canbecomeleader` (`UInt8`) - Whether the replica can be a leader. `is_readonly` (`UInt8`) - Whether the replica is in read-only mode. This mode is turned on if the config does not have sections with ClickHouse Keeper, if an unknown error occurred when reinitializing sessions in ClickHouse Keeper, and during session reinitialization in ClickHouse Keeper. `issessionexpired` (`UInt8`) - the session with ClickHouse Keeper has expired. Basically the same as `is_readonly`. `future_parts` (`UInt32`) - The number of data parts that will appear as the result of INSERTs or merges that havent been done yet. `partstocheck` (`UInt32`) - The number of data parts in the queue for verification. A part is put in the verification queue if there is suspicion that it might be damaged. `zookeeper_path` (`String`) - Path to table data in ClickHouse Keeper. `replica_name` (`String`) - Replica name in ClickHouse Keeper. Different replicas of the same table have different names. `replicapath` (`String`) - Path to replica data in ClickHouse Keeper. The same as concatenating zookeeperpath/replicas/replica_path. `columns_version` (`Int32`) - Version number of the table structure. Indicates how many times ALTER was performed. If replicas have different versions, it means some replicas havent made all of the ALTERs yet. `queuesize` (`UInt32`) - Size of the queue for operations waiting to be performed. Operations include inserting blocks of data, merges, and certain other actions. It usually coincides with

`insertsinqueue` (`UInt32`) - Number of inserts of blocks of data that need to be made. Insertions are usually replicated fairly quickly. If this number is large, it means something is wrong. `mergesinqueue` (`UInt32`) - The number of merges waiting to be made. Sometimes merges are lengthy, so this value may be greater than zero for a long time. `partmutationsin_queue` (`UInt32`) - The number of mutations waiting to be made. `queueoldesttime` (`DateTime`) - If `queue_size` greater than 0, shows when the oldest operation was added to the queue. `insertsoldesttime` (`DateTime`) - See `queueoldesttime` `mergesoldesttime` (`DateTime`) - See `queueoldesttime` `partmutationsoldesttime` (`DateTime`) - See `queueoldest_time` The next 4 columns have a non-zero value only where there is an active session with ZK. `logmaxindex` (`UInt64`) - Maximum entry number in the log of general activity. `logpointer` (`UInt64`) - Maximum entry number in the log of general activity that the replica copied to its execution queue, plus one. If `logpointer` is much smaller than `logmaxindex`, something is wrong. `lastqueueupdate` (`DateTime`) - When the queue was updated last time. `absolute_delay` (`UInt64`) - How big lag in seconds the current replica has. `total_replicas` (`UInt8`) - The total number of known replicas of this table. `active_replicas` (`UInt8`) - The number of replicas of this table that have a session in ClickHouse Keeper (i.e., the number of functioning replicas). `lostpartcount` (`UInt64`) - The number of data parts lost in the table by all replicas in total since table creation. Value is persisted in ClickHouse Keeper and can only increase. `lastqueueupdate_exception` (`String`) - When the queue contains broken entries. Especially important when ClickHouse breaks backward compatibility between versions and log entries written by newer versions aren't parseable by old versions. `zookeeper_exception` (`String`) - The last exception message, got if the error happened when fetching the info from ClickHouse Keeper. `replicaisactive` () Map between replica name and is replica active. If you request all the columns, the table may work a bit slowly, since several reads from ClickHouse Keeper are made for each row. If you do not request the last 4 columns (logmaxindex, logpointer, totalreplicas, active_replicas), the table works quickly. For example, you can check that everything is working correctly like this: ``` sql SELECT database, table, is_leader, is_readonly, issessionexpired, future_parts, partstocheck, columns_version, queue_size, insertsinqueue, mergesinqueue, logmaxindex, log_pointer, total_replicas, active_replicas FROM system.replicas WHERE is_readonly OR issessionexpired OR future_parts > 20 OR partstocheck > 10 OR queue_size > 20 OR insertsinqueue > 10 OR logmaxindex - log_pointer > 10 OR total_replicas < 2 OR activereplicas < totalreplicas ``` If this query does not return anything, it means that everything is fine.