You add a composite B-tree index, yet a query still eats a third of your replica's CPU. You set statement_timeout = '5s', yet a synchronous INSERT hangs for two minutes. Here are five fresh production stories from the PostgreSQL world: a 175× query speedup, WAIT FOR LSN in PG 19, moving 17 TB to Kubernetes, PG 20's conflict log table, and Pinecone's move to FoundationDB.
How incident.io cut a query from 34% down to 0.3% CPU
At incident.io, the "who is on call right now?" query burned 33.8% of a replica's CPU: ~23 million calls over 3.5 days, 280.7 hours of total runtime, averaging 44 ms. Adding a five-column composite B-tree index barely moved production latency. The planner kept picking an older GiST index from an EXCLUDE constraint (used to block overlapping shifts), assumed the columns were independent, read the entire layer history, and sorted it just for LIMIT 1.
The fix was row comparison paired with ORDER BY DESC across all five columns. GiST stores ranges without a linear sort order and can't satisfy that operation, forcing Postgres onto a B-tree Index Scan Backward:
CREATE INDEX CONCURRENTLY
idx_schedule_entries_org_schedule_rotation_layer_start_at
ON schedule_entries (
organisation_id, schedule_id, rotation_id, layer_id, start_at
);
-- Row comparison + ORDER BY DESC rules out GiST
SELECT e.*
FROM unnest($1::text[], $2::text[], $3::text[], $4::text[])
AS g(organisation_id, schedule_id, rotation_id, layer_id)
CROSS JOIN LATERAL (
SELECT se.*
FROM schedule_entries se
WHERE (
se.organisation_id, se.schedule_id,
se.rotation_id, se.layer_id, se.start_at
) < (
g.organisation_id, g.schedule_id,
g.rotation_id, g.layer_id, $5
)
ORDER BY se.organisation_id DESC, se.schedule_id DESC,
se.rotation_id DESC, se.layer_id DESC, se.start_at DESC
LIMIT 1
) e
WHERE e.organisation_id = g.organisation_id
AND e.schedule_id = g.schedule_id
AND e.rotation_id = g.rotation_id
AND e.layer_id = g.layer_id
AND e.end_at > $6;
Latency dropped from 44 ms to 0.26 ms, buffer reads fell from 8,359 to 71, and CPU share sank to 0.3%—freeing ~10% of total DB capacity. The takeaway: a new index won't help if an old constraint index skews planner stats. Remember that this trick only works on B-tree and needs an outer equality filter on leading columns so < doesn't return another org's row.
WAIT FOR LSN in PostgreSQL 19 instead of fighting synchronous replication
Synchronous replication for read-your-writes hurts when a replica stalls: your entire primary stalls with it. In Percona's tests, an INSERT with statement_timeout = '5s' hung for two minutes until manually canceled. PostgreSQL 19 (released November 19, 2026) adds WAIT FOR LSN: grab the WAL position after commit and wait for it on the replica with a timeout. Supported MODEs are standby_replay (visibility), standby_flush (fsync on replica), standby_write, and primary_flush; NO_THROW returns success, timeout, or not in recovery instead of throwing:
-- On primary in a separate query after COMMIT
SELECT pg_current_wal_insert_lsn();
-- On replica: wait for LSN replay without throwing
WAIT FOR LSN '0/0306EE20'
WITH (MODE 'standby_replay', TIMEOUT '500ms', NO_THROW);
-- Primary tuning with synchronous_commit = off (no restart needed)
ALTER SYSTEM SET wal_writer_flush_after = 0;
ALTER SYSTEM SET wal_writer_delay = '10ms';
SELECT pg_reload_conf();
Pairing synchronous_commit = off with standby_flush guarantees disk durability on both nodes without blocking the primary, and tuning wal_writer jumps throughput from 108 to >2,000 TPS. Watch the limits: it only runs at top level (not inside functions or active snapshots), TIMEOUT '0' or <=0.5 ms waits forever, timeline switches aren't tracked, and connection load shifts onto the replica (24 of 32 clients vs 7 on primary). For critical production, wait for 19.1—a pg_current_wal_insert_lsn() bug at WAL page boundaries remains in 19.0.
Migrating 26 databases and 17 TB from AWS RDS to CloudNativePG with zero downtime
By December 2026, Stream had moved 26 of ~50 databases (17 TB) from AWS RDS to CloudNativePG (CNPG) on GCP with zero unplanned downtime. To isolate risks, they staged databases in CloudSQL first, then cut over to CNPG via pgcopydb and a mirroring proxy. They skipped cheap read replicas: shared_buffers already served reads, and on failover any node must handle full write load.
The biggest surprise was WAL volume sizing: during COPY and index builds, disks filled up even on single-node clusters with backups disabled. CNPG still runs a no-op archive step per WAL segment and hits cleanup limits, so they provisioned much larger WAL volumes for the move. Instead of 3–5 minutes of write-frozen downtime, v2 pod switching ran alongside WAL catch-up—shrinking the both-write overlap window to <20 seconds with timestamp checks on critical tables (zero data loss). That requires schemas able to handle brief dual writes without giant transactions.
PostgreSQL 20: logging logical replication conflicts to a real table
Previously, resolved LOG-level conflicts in logical replication (where a subscriber edit silently overwrote or skipped a row) vanished into text logs. On November 24, 2026, PostgreSQL 20 merged a patch: setting conflict_log_destination = 'table' or 'all' creates pg_conflict.pg_conflict_log_<subid> for five conflict types (update_origin_differs, update_missing, update_deleted, delete_origin_differs, delete_missing):
ALTER SUBSCRIPTION my_sub
SET (conflict_log_destination = 'table');
-- Query conflicts by subscription OID (e.g., 16396)
SELECT remote_xid, relname, conflict_type, apply_origin,
replica_identity,
local_conflicts[1] ->> 'xid' AS local_xid
FROM pg_conflict.pg_conflict_log_16396;
The table has 12 columns including JSON fields replica_identity and local_conflicts. Keys over 64 KB aren't silently truncated (so JOINs don't lie); they're replaced with {"omitted":true,"length":...} and has_omitted_values = true. ERROR-level conflicts (unique violations) still stay in logs only, REPLICA IDENTITY FULL leaves replica_identity as NULL, and pg_upgrade migration for the conflict table will land in a follow-up patch.
Why Pinecone moved its data plane off PostgreSQL onto FoundationDB
In 2024, Pinecone's data plane ran on ~77 managed PostgreSQL databases across AWS, GCP, and Azure. By September 29, 2026, they deleted all of them along with ~40K lines of code, cutting storage costs roughly 20×. Their workload was a distributed key-value catalog without JOINs running inside customer Kubernetes clusters (BYOC). A validation bug spawned ~17K indexes a day, left millions of empty tables behind, and forced 40+ hours of manual VACUUM FREEZE to avoid XID wraparound.
Vector catalogs and WAL moved to S3, while metadata moved to FoundationDB (3× cheaper than the replaced PG nodes). They skipped dual-write and migrated the critical mappings table one index at a time with <1s pauses (3.5s max), verifying the state machine in TLA+ across 1.5M states. Leaving Postgres had a real cost: no SQL, built-in indexes, or psql (they wrote fdbsql on Apache DataFusion); single-row reads were 1.4–2× faster in PG (masked by a 98% cache); and FDB already caused a 25-minute outage from a bug in fdb-kubernetes-operator v2.22.0 plus a 4-minute e-brake slowdown at 660K rows/min.


