// ClickHouse error reference

164: READONLY (code 164)

The session runs under the readonly setting, so INSERT, CREATE, ALTER and other writes are refused at the server.

錯誤碼
164
名稱
READONLY
類別
Authentication and access
錯誤訊息
Cannot execute query in readonly mode. (READONLY)

它的意義

READONLY (164) means the session's readonly setting blocks data changes: readonly = 1 allows reads only, so SET is blocked too; readonly = 2 allows reads and SET but still blocks data changes. The value comes from the user's profile or the connection string, not from the table; a table refusing writes is TABLE_IS_READ_ONLY (242).

常見原因

  • The user's profile sets readonly = 1 or 2, common for dashboards and the HTTP interface.
  • The connection string or driver appends readonly=1 and the application then sends writes.
  • A proxy or managed service hands out a readonly profile the user never asked for.

Find the cause

`system.settings` for the session value, `SHOW GRANTS FOR app_user` and `system.users` for the profile, and the server's users.xml or access-control storage for where readonly is set.

如何修正

  1. See what the session enforces and whether it was changed on the fly.

    SELECT name, value, changed FROM system.settings WHERE name = 'readonly';
  2. Ask an administrator to move the user into a writable profile; do not try to escape the restriction.

    ALTER USER app_user SETTINGS PROFILE default;
  3. Split workloads: keep dashboards on their readonly user and run writes as a separate read-write user.

    GRANT SELECT ON my_db.* TO dashboard_ro;

Other ways to handle it

ACCESS_DENIED (497) fails one statement for missing grants; 164 blocks all writes for the session. A readonly = 1 session that tries SET gets 164 (Cannot modify 'max_threads' setting in readonly mode); a readonly = 2 session may SET other settings, but changing readonly itself also returns 164.

安全地重現問題

The same INSERT succeeds for an unrestricted user, which proves the block is the session profile, not the table.

clickhouse-client --setting readonly=1, then INSERT INTO scratch_f VALUES (1) returns 164; the same INSERT as an unrestricted user succeeds.

問題

What is the difference between readonly 1 and 2?

readonly = 1 blocks data changes and SET; readonly = 2 allows SET but still blocks data changes. Remove the managed-service sentence unless it is sourced.

Is this the same as a table in read-only mode?

No. 164 is the session setting, 242 TABLE_IS_READ_ONLY is a per-table state. The message and code tell you which one you hit.

相關錯誤

More authentication and access 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. 授權詳情 引用的錯誤訊息文字歸其資料庫廠商所有。