query_only
Refuse statements that change database files: this connection can read but not write.
- По умолчанию
0 (off)- Range
- 0, 1
- Restart needed
- Нет
- Default checked on
- SQLite 3.5x
Что оно делает
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.
Значение по умолчанию
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, or check the SQLite manual for every option.
Check query_only on your own server
SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.
Текст и данные на этой странице: CC BY 4.0, с указанием SQLly (sqlly.app). Код и фрагменты SQL: MIT. Подробнее о лицензии