# 164: READONLY (code 164)

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

Source: https://sqlly.app/errors/clickhouse/readonly
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error code: `164`
- Name: `READONLY`
- Category: Authentication and access

Error message:

```text
Cannot execute query in readonly mode. (READONLY)
```

## What it means

`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).

## Common causes

- 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.

## How to fix it

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

   ```sql
   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.

   ```sql
   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.

   ```sql
   GRANT SELECT ON my_db.* TO dashboard_ro;
   ```

## Reproduce it safely

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

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

## How SQLly helps

SQLly shows the connection name on every tab, so you can check you are editing the right user's profile when one server holds both readonly and read-write logins.

## Questions

### 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.

## Related errors

- [`242`](https://sqlly.app/errors/clickhouse/table-is-read-only): TABLE_IS_READ_ONLY (code 242)

The code and message text are from the [ClickHouse documentation (system.errors)](https://clickhouse.com/docs/en/operations/system-tables/errors).
