# query_only

> Refuse statements that change database files: this connection can read but not write.

Source: https://sqlly.app/sql-configuration/sqlite/query-only
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).

**Default**

`0 (off)`

**Range**

0, 1

**Restart needed**

No

**Default checked on**

SQLite 3.5x

## What it does

CREATE, DELETE, DROP, INSERT and UPDATE fail with SQLITE_READONLY while it is on. The database is not truly read-only: checkpoints and COMMIT still run, and sqlite3_db_readonly() does not report the database as read-only.

## Default value

`0 (off)`. Off (a stock SQLite 3.5x build).

## Check the current value

```
PRAGMA query_only;

SELECT * FROM pragma_query_only;   -- table-valued form, usable in queries
```

## Change it

```
PRAGMA query_only = ON;   -- this connection only
```

No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

## When to change it

In tools and report runners that must never write, and around code paths that should only read, such as a health check or a dashboard.

## What can go wrong

It is a tripwire, not a permission system: the connection can still checkpoint and COMMIT, so never present it to a user as proof of read-only access. It also blocks schema migrations until turned back off.

## Questions about query_only

### What is the default value of query_only in SQLite?

0 (off). Off (a stock SQLite 3.5x build).

### Does changing query_only require a restart?

No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

### When should I change query_only?

In tools and report runners that must never write, and around code paths that should only read, such as a health check or a dashboard.

Back to all [SQLite settings](https://sqlly.app/sql-configuration/sqlite), or check the [SQLite manual](https://www.sqlite.org/pragma.html) for every option.

## Related SQLite settings

- [`locking_mode` Whether the connection releases file locks after each transaction (NORMAL) or keeps them (EXCLUSIVE).](https://sqlly.app/sql-configuration/sqlite/locking-mode)
- [`trusted_schema` Whether SQL functions and virtual tables used in the schema (views, triggers, CHECK constraints) are trusted to run.](https://sqlly.app/sql-configuration/sqlite/trusted-schema)
