// ClickHouse error reference

242: TABLE_IS_READ_ONLY (code 242)

The table refuses writes because the server flagged it read-only; most often a ReplicatedMergeTree replica lost its Keeper session.

오류 코드
242
이름
TABLE_IS_READ_ONLY
카테고리
Resource limits
오류 메시지
Table is in readonly mode

의미

TABLE_IS_READ_ONLY (242) is raised on INSERT or ALTER when the table engine put the table in read-only mode. For ReplicatedMergeTree the common trigger is a lost or expired session with ZooKeeper or ClickHouse Keeper: without a live session the replica cannot safely write. Plain MergeTree tables do not raise 242: a table with table_readonly = 1 fails INSERT with TABLE_IS_PERMANENTLY_READ_ONLY (774), and an unwritable data directory fails with code 1001 (std::exception). It is a table state, not a permission issue; that is ACCESS_DENIED (497), and a session-level limit is READONLY (164).

일반적인 원인

  • A ReplicatedMergeTree replica lost its ZooKeeper or Keeper session, or cannot reinitialize it after a restart.
  • The filesystem holding the data path is mounted read-only or has no space left.
  • A data part failed the check at startup and the server marked the table read-only.

Find the cause

`system.replicas` (`is_readonly`, `is_session_expired`, `zookeeper_exception`) for replicated tables, `system.disks` for space and mount state, `system.parts` and `system.detached_parts` for part health, and the server log for the message that set read-only.

해결 방법

  1. See which tables are read-only and why: is_session_expired and the exception columns separate a Keeper problem from a local one.

    SELECT database, table, is_readonly, is_session_expired, total_replicas, active_replicas, zookeeper_exception, last_queue_update_exception FROM system.replicas WHERE is_readonly;
  2. For an expired Keeper session, restore connectivity to the Keeper cluster, then reinitialize the replica; it compares its state with Keeper and rebuilds its queue.

    SYSTEM RESTART REPLICA my_db.my_table;
  3. For a local cause, fix the disk or the damaged part first; system.detached_parts shows what the server set aside and why.

    SELECT name, reason FROM system.detached_parts WHERE database = 'my_db' AND table = 'my_table';
  4. When the cause is fixed but the server still refuses the table, the documented recovery is the force_restore_data flag: touch the flag file in the server's flags/ directory (or create the node under the table's flags/ path in Keeper), restart, then confirm the table is writable again:

    SELECT database, table, is_readonly, is_session_expired FROM system.replicas WHERE database = 'my_db' AND table = 'my_table';

Other ways to handle it

No client-side workaround clears the flag. Route writes to another replica meanwhile, and use force_restore_data only when the flagged parts are safe to lose.

안전하게 재현하세요

The replicated read-only state clears when the Keeper session reinitializes; nothing has to be deleted.

On a scratch server, run ALTER TABLE scratch_mt MODIFY SETTING table_readonly = 1 on a MergeTree table and INSERT fails with 774 (TABLE_IS_PERMANENTLY_READ_ONLY), not 242. Code 242 needs a ReplicatedMergeTree table, which needs a ClickHouse Keeper or ZooKeeper ensemble; the docs say replicated tables switch to read-only when Keeper is unavailable at startup.

질문

Is this the same as read-only user mode?

아니요. READONLY (164) is a user session setting. 242 is the table itself refusing writes.

Does the table recover by itself?

A replica leaves read-only mode on its own once the Keeper session is back and its queue drains; for disk and part causes, fix the cause and restart.

관련 오류

More resource limits errors

코드와 메시지 텍스트의 출처는 다음과 같습니다 ClickHouse documentation (system.errors). 전체 목록은 ClickHouse error list 또는 모든 데이터베이스 오류 검색.

// 오류는 줄이고, 수정은 빠르게

Work on ClickHouse in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for ClickHouse and the other databases you use.

이 페이지의 텍스트와 데이터: CC BY 4.0, 출처: SQLly (sqlly.app). 코드와 SQL 스니펫: MIT. 라이선스 세부 정보 인용된 오류 메시지 텍스트의 권리는 해당 데이터베이스 공급업체에 있습니다.