Skip to main content

PRAGMA Statements

PRAGMA statements are special commands used to query or modify database configuration, retrieve metadata, and control database behavior. Unlike standard SQL, PRAGMAs are specific to SQLite and Turso.

Syntax

Database Metadata

database_list

Returns one row for each attached database.

page_count

Returns the total number of pages in the database file.

page_size

Returns or sets the page size of the database. The page size can only be set before any tables are created.

max_page_count

Returns or sets the maximum number of pages allowed in the database file.

freelist_count

Returns the number of unused pages in the database file.

encoding

Returns the text encoding used by the database.

schema_version

Returns the schema version number. This value is incremented each time the schema changes.

application_id

Returns or sets the application ID stored in the database header. Applications can use this 32-bit integer to identify the database file format.

user_version

Returns or sets the user version number. This is a 32-bit integer available for application use.

Schema Introspection

table_info

Returns one row for each column in the named table.

table_xinfo

Similar to table_info but also includes hidden columns and additional metadata.
Returns the same columns as table_info plus a hidden column (0 for normal columns, non-zero for hidden columns in virtual tables).

table_list

Returns one row for each table and view in the database.

index_list

Returns one row for each index on the named table.

index_info

Returns one row for each column in the named index.

index_xinfo

Similar to index_info but includes additional columns.

function_list

Returns one row for each SQL function available.

pragma_list

Returns the list of all supported PRAGMA commands.

Database Configuration

journal_mode

Returns or sets the journal mode.
Turso supports WAL (Write-Ahead Logging) mode. Rollback journal modes (DELETE, TRUNCATE, PERSIST, MEMORY) are not supported.
Turso Extension: Turso supports an experimental MVCC journal mode for concurrent writes:
When MVCC mode is active, you can use BEGIN CONCURRENT for optimistic concurrent write transactions. See Transactions for details.

cache_size

Returns or sets the suggested maximum number of database pages held in memory.

cache_spill

Enables or disables cache spilling (writing dirty pages to the WAL before the cache is full).

synchronous

Controls the fsync behavior for durability guarantees.
Only OFF and FULL are supported in Turso.

temp_store

Controls where temporary tables and indexes are stored.

busy_timeout

Sets the busy timeout in milliseconds. When a table is locked, Turso waits up to this many milliseconds before returning SQLITE_BUSY.

query_only

When enabled, prevents any changes to the database.

foreign_keys

Enables or disables foreign key constraint enforcement.
Foreign key enforcement is off by default for SQLite compatibility.

legacy_file_format

Returns the legacy file format flag.

ignore_check_constraints

When enabled, CHECK constraints are not enforced.

data_sync_retry

Controls whether Turso retries a disk sync (fsync) after a failure instead of treating it as fatal.

require_where

Turso Extension: a safety pragma with no SQLite equivalent.
When enabled, Turso rejects any UPDATE or DELETE that does not include a WHERE clause, guarding against accidental full-table modifications. i_am_a_dummy is an alias that enables the same behavior.

Integrity Checks

integrity_check

Performs a thorough integrity check of the entire database.
Returns ok if no problems are found, otherwise returns one row per error.

quick_check

Performs a faster but less thorough integrity check than integrity_check.

WAL Operations

wal_checkpoint

Forces a WAL checkpoint.
A checkpoint writes pages from the WAL file back to the database file.

MVCC Tuning

Turso Extension: these pragmas apply only when MVCC mode is enabled (PRAGMA journal_mode = mvcc).

mvcc_checkpoint_threshold

Sets the amount of committed work that accumulates before Turso triggers an MVCC checkpoint.

mvcc_gc_threshold

Sets the threshold that controls how aggressively Turso garbage-collects obsolete MVCC row versions.

Change Data Capture

Turso Extension: Change Data Capture (CDC) is a Turso-specific feature that tracks all data changes for replication, auditing, and reactive applications.

capture_data_changes_conn

Enables CDC for the current connection. Changes are captured to a designated table.
The legacy name unstable_capture_data_changes_conn is still accepted for backwards compatibility.

Capture Modes

CDC Table Structure

The CDC table contains the following columns:

CDC Examples

CDC respects transaction boundaries. Changes are only recorded when a transaction commits. If a transaction rolls back, no CDC entries are created.

Encryption

Turso Extension: At-rest encryption is a Turso-specific feature. This feature is experimental and must be enabled before use.

cipher

Sets the encryption cipher for the database.
Supported ciphers:

hexkey

Sets the encryption key as a hexadecimal string.

Encryption Example

Alternatively, specify encryption parameters in the database URI:
To open an existing encrypted database, the cipher and key must be provided as URI parameters.

Custom Types

Turso Extension: Custom types are a Turso-specific feature.

list_types

Lists all available types (built-in and custom) with their metadata.
See CREATE TYPE for creating custom types.

See Also