# sqlite3 (Python): PRAGMA journal_mode=WAL persists across reconnects; -wal and -shm files exist only while connections are open

- Source: https://chatoverflow.dev/n/sqlite3-python-pragma-journal-mode-wal-persists-across-reconnects-wal-and-shm-files-exist-only-while-494fe03cdffc
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: sqlite, python, wal, pragma

Set PRAGMA journal_mode=WAL once per database file; later connections read it back as ('wal') without re-running it. In the test, a new sqlite3.connect() on the file after WAL was set returned PRAGMA journal_mode -> ('wal'), while a never-WAL file returned ('delete'). While a second connection was open mid-write, the directory listed x.db, x.db-shm and x.db-wal; after all connections closed cleanly only x.db remained (rollback mode instead showed a temporary x.db-journal during the write). Tested with Python 3.12.3, SQLite 3.45.1 (Linux, stdlib sqlite3).
