Postgres LISTEN/NOTIFY Actually Scales
Postgres NOTIFY takes a global exclusive lock from commit start through fsync so notifications enqueue in commit order, which serializes every notifying transaction and blocks group commit. A trigger-per-insert stream design therefore capped at about 2.9K writes/sec with idle CPU and disk. Because notifications only signal readers to re-check a table that remains the source of truth, buffering them in memory and flushing in periodic batches removes the contention, with low-frequency reader polling covering notifications lost to crashes. The batched design reached about 60K stream writes/sec on one server, 20x the original, with CPU saturated instead of lock-bound; the upcoming Postgres 19 patch does not remove this lock.
Related posts
- What's New with Monitoring in PostgreSQL 19
ClickHouse mediumAdept
PostgreSQL 19 (in beta) brings a batch of monitoring improvements. log_lock_waits is now on by default, log_min_messages accepts per-process-type levels, and autoanalyze gets its own log_autoanalyze_min_duration threshold. A new wal_fpi_bytes counter is exposed in pg_stat_wal, per backend, in EXPLAIN and in VACUUM/ANALYZE logs. Other additions are new wait events for WAL LSN waits and file/pipe COPY I/O, remote-server messages routed through normal log formatting, a pg_get_multixact_stats() function, and an earlier 100M-transaction wraparound warning. The post closes with an upgrade checklist for log parsers, metric collectors, wait-event dictionaries, config UIs and age(datfrozenxid) alert thresholds.
- Rebuilding Linear’s delta sync read path
Linear mediumAdept
Linear moved its delta sync read path, which lets reconnecting local-first clients fetch only changes since their last checkpoint, from a Postgres table to turbopuffer inverted indexes. On Postgres, the reconnect query combined a widening ID range with array-overlap predicates for sync groups and subscriptions, which drove up CPU and made p95/p99 latency volatile. Read replicas didn't help because the per-request intersection work stayed the same. turbopuffer stores per-workspace posting lists of sync action IDs and intersects them directly, fed by a custom CDC pipeline with about 1s p50 replication lag. Reads run as a metadata scan with late payload enrichment from Postgres, Postgres serves an overlapping authoritative head slice with deduplication and fallback, and shadow-mode comparison verified correctness. Tail latency now stays flat as workspaces grow.
- From v0.7 to v0.8: How group commit changed Turso's tail latency
Turso mediumAdeptTurso v0.8 adds group commit to its MVCC write path so that concurrent committers share a single fsync of the logical log instead of each paying for their own. In v0.7 a commit lock was held across pwrite and fsync, so with k concurrent committers the last waited for k flushes. Under a 1,000 TPS Poisson load, tail latency ballooned to seconds (p99.9 up to 157 s at 32 connections). In v0.8 committers enqueue log records and get tickets, and the first to take the lock leads, writing all queued records and fsyncing once while the others park until their ticket is durable. That cuts p50 to about 1 ms and p99.9 to 2.4–14 ms, below SQLite's in every configuration, with tail latency improving as connections increase.
- How savepoints quietly throttled our Postgres queue
incident.io hardMasterUsing a SAVEPOINT per tick in a Postgres-backed job queue made every locked row carry a MultiXact ID in xmax. FOR UPDATE SKIP LOCKED scans then contended on the LWLock-guarded pg_multixact cache, so adding workers made acquisition slower. incident.io fixed it by moving the queue to a slim escalation_jobs table, replacing subtransactions with a claimed_until lease (one transaction per tick), keeping claimed_until unindexed with fillfactor 85 to allow HOT updates, and running one dispatcher goroutine per pod that feeds workers over a channel. Together these raised peak escalation capacity 3.5x, at the cost of up to 10 seconds of delay if a pod dies mid-claim.
- Read your writes: WAIT FOR in PostgreSQL 19
ClickHouse mediumAdept
PostgreSQL 19 adds a top-level `WAIT FOR LSN` command that blocks a session until a standby has written, flushed or replayed WAL up to a given LSN, giving read-your-writes consistency on asynchronous replicas without the per-commit cost of `synchronous_commit = remote_apply`. The pattern is to capture `pg_current_wal_insert_lsn()` after a write on the primary, then run `WAIT FOR` on the standby before reading. Options include MODE (standby_replay, standby_flush, standby_write, primary_flush), TIMEOUT and NO_THROW. It must run as a snapshot-free utility command outside functions and above READ COMMITTED, because a held snapshot can stall WAL replay and self-deadlock. The feature took about 10 years and three reverts to land. Timeline changes after promotion are not tracked, and connection poolers and proxies are natural places to inject it transparently.