Skip to content

DSN flags

Every _* DSN flag mattn supported is translated transparently — usually into the equivalent PRAGMA. _strict=1 turns any unknown flag into an error (helpful during migration to flush typos out). The modern alternative to DSN strings is the typed sqlite.Config.

Flag (aliases)Underlying action
_pragma=foo(1)PRAGMA foo=1 (multi-value)
_foreign_keys / _fkPRAGMA foreign_keys=
_busy_timeout / _timeoutPRAGMA busy_timeout=
_journal_mode / _journalPRAGMA journal_mode=
_synchronous / _syncPRAGMA synchronous=
_locking_mode / _lockingPRAGMA locking_mode=
_secure_deletePRAGMA secure_delete=
_recursive_triggers / _rtPRAGMA recursive_triggers=
_cache_sizePRAGMA cache_size=
_auto_vacuum / _vacuumPRAGMA auto_vacuum=
_defer_foreign_keys / _defer_fkPRAGMA defer_foreign_keys=
_ignore_check_constraintsPRAGMA ignore_check_constraints=
_case_sensitive_like / _cslikePRAGMA case_sensitive_like=
_query_onlyPRAGMA query_only=
_writable_schemaPRAGMA writable_schema=
_localiased to _timezone (auto → Local)
_time_format, _time_integer_format, _inttotime, _texttotime, _timezoneinherited from modernc
_txlocksets transaction begin mode
cache, mode, immutable, vfsURI-level, passed through
_auth*rejected — userauth was removed upstream
_strict=1unknown flags become hard errors

For new code, prefer the typed sqlite.Config over a DSN string — it’s compile-checked and self-documenting. The common flags map to fields on Config.Pragmas (with typed enum values); anything without a dedicated field goes through Pragmas.Extra, which fires PRAGMA <key> = <value> exactly like _pragma=.

DSN flagTyped fieldValues
_journal / _journal_modePragmas.JournalModeJournalWAL · JournalDelete · JournalTruncate · JournalPersist · JournalMemory · JournalOff
_sync / _synchronousPragmas.SynchronousSynchronousNormal · SynchronousOff · SynchronousFull · SynchronousExtra
_busy_timeout / _timeoutPragmas.BusyTimeouta time.Duration (mapped to ms)
_fk / _foreign_keysPragmas.ForeignKeystrue / false
_cache_sizePragmas.CacheSizepages (positive) or KiB (negative)
mode (URI)Config.ModeModeReadWriteCreate · ModeReadWrite · ModeReadOnly · ModeMemory
cache (URI)Config.CacheCacheShared · CachePrivate
vfs (URI)Config.VFSa registered VFS name
any other _pragma=foo(v)Pragmas.Extramap[string]stringPRAGMA foo = v

Typed-only (no legacy DSN flag): Pragmas.TempStore (TempStoreMemory · TempStoreFile · TempStoreDefault) and Config.Encryption (transparent at-rest encryption via the crypto VFS). Config.Pragmas is applied in struct-declaration order after open; RecommendedPragmas() is the production preset (WAL + busy_timeout=5s + foreign_keys=on). Full field semantics live in the Configuration guide and pkg.go.dev/gosqlite.org.