Search code examples
clickhouse

How to set clickhouse replica to readonly mode for a given table


I want to simulate a scenario where I have to recover a cluster where some replicas are in read-only mode. What can I do to set a table replica to read-only so that the following query returns at least one line ?

SELECT
    database,
    `table`
FROM system.replicas
WHERE is_readonly = 1

Solution

  • DETACH TABLE db.table;
    SYSTEM DROP REPLICA '{replica}' FROM ZKPATH ...;
    ATTACH TABLE db.table;
    SELECT * FROM system.replicas WHERE is_readonly = 1 FORMAT Vertical;