// 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. 许可详情 引用的错误消息文本归其数据库厂商所有。