Skip to content

perf(db): checkpoint PostgreSQL every 15 minutes - #1337

Merged
nixuuu merged 1 commit into
devfrom
perf/postgres-checkpoints
Nov 27, 2026
Merged

nixuuu merged 1 commit into
devfrom
perf/postgres-checkpoints

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 27, 2026

Copy link
Copy Markdown
Member

Problem

PostgreSQL's default checkpoint_timeout is 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_journal and thread_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):

default (5 min, 1 GB, no compression) 15 min, 4 GB, lz4 (30 min sample)
full-page images 296 ~105 (−65%)
WAL bytes 1.83 MB 0.60 MB (−67%)

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

  • Desktop (local mode). apps/desktop/src/runtime/database.ts starts PostgreSQL with checkpoint_timeout=15min.
    • max_wal_size stays at the default 1 GB, so crash recovery on a laptop stays short.
    • Compression is left off, because an @embedded-postgres build is not guaranteed to include lz4 and the server would fail to start without it.
  • Compose. deploy/docker-compose.yml runs postgres with checkpoint_timeout=15min, max_wal_size=4GB and wal_compression=lz4.
  • Docs. docs/desktop.md and docs/deploy.md describe 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 with ALTER SYSTEM + pg_reload_conf() or to an existing Compose container.

Verification

  • postgres:17 with these flags reports checkpoint_timeout=900s, max_wal_size=4096MB and wal_compression=lz4.
  • docker compose config renders the command.
  • The production gateway runs the same three settings via ALTER SYSTEM; the numbers above come from there.
  • oxlint on the desktop file is clean.
  • Not run: a desktop local-mode start with the @embedded-postgres 18.7 binaries. checkpoint_timeout is a core setting accepted by every build. CI runs the full gate.

🤖 Generated with Claude Code

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]>
@nixuuu
nixuuu enabled auto-merge (squash) November 27, 2026 15:58
@nixuuu
nixuuu merged commit 53198bf into dev Nov 27, 2026
24 checks passed
@nixuuu
nixuuu deleted the perf/postgres-checkpoints branch November 27, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant