SQLite PRAGMA and Administration Cheatsheet

High-signal PRAGMA commands for foreign keys, cache, synchronous settings, page size, temp storage, health checks, and general SQLite administration.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Integrity and connection behavior

Enable important safety settings and inspect database health.

Enable foreign key enforcement

Turn on FK checks for the current connection.

sqlANYsqliteforeign_keys
sql
PRAGMA foreign_keys = ON;

Foreign key enforcement is connection-specific and should usually be enabled explicitly by applications.

Check current foreign key setting

Read whether FK enforcement is enabled.

sqlANYsqliteforeign_keysinspect
sql
PRAGMA foreign_keys;

Useful when debugging unexpected orphan rows or migration behavior.

Find foreign key violations

Report rows that violate FK constraints.

sqlANYsqliteforeign_key_check
sql
PRAGMA foreign_key_check;

A great migration verification step.

Run a quick integrity check

Perform a lighter-weight consistency scan.

sqlANYsqlitequick_check
sql
PRAGMA quick_check;

Faster than a full integrity check and handy for routine validation.

Performance and file settings

Inspect or tune journaling, cache, and storage behavior.

Inspect page size

Read the database page size.

sqlANYsqlitepage_size
sql
PRAGMA page_size;

Page size is part of the file format and relevant for some performance and storage investigations.

Set cache size

Adjust the number of pages or kibibytes used for page cache.

sqlANYsqlitecache_sizememory
sql
PRAGMA cache_size = -20000;

Negative values are interpreted as kibibytes, making sizing easier in some deployments.

Set synchronous mode

Control durability vs speed tradeoffs.

sqlANYsqlitesynchronous
sql
PRAGMA synchronous = NORMAL;

A common setting in WAL mode when balancing performance and durability.

Control temporary storage location

Choose file-backed or memory temp storage.

sqlANYsqlitetemp_store
sql
PRAGMA temp_store = MEMORY;

Can help workloads that build temporary btrees, sorts, or transient intermediate results.

Track application schema version

Read or set the user-defined schema version number.

sqlANYsqliteuser_versionmigrations
sql
PRAGMA user_version;
PRAGMA user_version = 12;

A simple and popular migration bookkeeping mechanism in SQLite apps.

Recommended next

No recommendations yet.