Repository navigation
perf(db): checkpoint PostgreSQL every 15 minutes - #1337
Merged
Merged
Conversation
PostgreSQL writes a full copy of every page changed after a checkpoint to WAL, and its default checkpoint runs every 5 minutes. On a production gateway full-page images were most of the WAL volume. Moving to a 15-minute checkpoint with lz4 WAL compression cut WAL per record by about two thirds. Desktop's local database now checkpoints every 15 minutes; it keeps the default max_wal_size for short crash recovery and skips compression, since an @embedded-postgres build may lack lz4. The Compose PostgreSQL also gets max_wal_size=4GB and wal_compression=lz4. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PostgreSQL's default
checkpoint_timeoutis 5 minutes. After each checkpoint, the first change to a page writes the whole page to WAL. On the production gateway these full-page images made up most of the WAL volume. The pages came from the tables that grow and shrink all the time:thread_events,thread_replication_journalandthread_items, which receive transcript events while retention deletes old rows.Measured on that gateway after the #1336 fix (same workload, values per 1000 WAL records):
Almost all of the gain comes from the longer checkpoint interval. Bytes per full-page image barely changed with lz4, most likely because most of these pages are already-compressed TOAST data.
Change
apps/desktop/src/runtime/database.tsstarts PostgreSQL withcheckpoint_timeout=15min.max_wal_sizestays at the default 1 GB, so crash recovery on a laptop stays short.@embedded-postgresbuild is not guaranteed to include lz4 and the server would fail to start without it.deploy/docker-compose.ymlrunspostgreswithcheckpoint_timeout=15min,max_wal_size=4GBandwal_compression=lz4.docs/desktop.mdanddocs/deploy.mddescribe the settings, their cost (up to ~4 GB of WAL files on disk, longer recovery after a crash) and how to apply them to an own PostgreSQL withALTER SYSTEM+pg_reload_conf()or to an existing Compose container.Verification
postgres:17with these flags reportscheckpoint_timeout=900s,max_wal_size=4096MBandwal_compression=lz4.docker compose configrenders the command.ALTER SYSTEM; the numbers above come from there.@embedded-postgres18.7 binaries.checkpoint_timeoutis a core setting accepted by every build. CI runs the full gate.🤖 Generated with Claude Code