One, Two, Skip a Few...
Postgres sequences pre-log 32 values to the WAL (SEQ_LOG_VALS), so replicas see sequence state as it would be after a primary crash. When incident.io promoted a follower during a database upgrade, every per-organisation incident ID sequence jumped forward by up to 32, producing gaps like #INC-7 to #INC-39. Sequences guarantee monotonic values but not gap-free ones, and rollbacks can also skip numbers. The fix replaced them with a BEFORE INSERT trigger computing MAX(external_id)+1 per organisation, backed by an index, and the post recommends keeping external IDs separate from internal primary keys.
Related posts
- Patching the PostgreSQL JDBC Driver
Zalando Engineering mediumAdeptPostgres logical replication slots for clients watching low-traffic tables never advance, so the server retains all WAL generated by other tables until disk fills and the node goes read-only. Zalando fixed this upstream in PgJDBC: the driver now tracks the last received and last confirmed replication LSNs, and when they match and a KeepAlive message reports a higher server LSN, it confirms that LSN, safely advancing the slot without skipping relevant events. The fix, merged for PgJDBC 42.7.0, removes the need for the common dummy-write workaround and was validated by comparing WAL size graphs before and after a patched Debezium image rollout across hundreds of event streams.
- Sequences and other volatiles in Neki
PlanetScale hardMasterNeki, PlanetScale's sharded Postgres, implements Postgres sequences by classifying sequence operations like nextval() as router-only, with an authoritative shard hosting all sequences so values are never duplicated across shards. The planner relies on Postgres's immutable/stable/volatile expression classification: immutable expressions can be pushed to shards, stable ones like now() or to_char() need consistent clocks or GUCs such as lc_time, and volatile ones must run exactly once per row of the table expression. Determining that cardinality correctly under cross-shard joins, filter reordering and shard-local join pushdown is the hard part, because optimizations that deduplicate join-multiplied rows are invalid for volatile expressions.
- Why Your Staging Database Never Matches Production
Neon mediumAdept
Staging databases drift from production continuously in three ways: data drift (stale dumps, sequence values that diverge so the same ID points to different records), schema drift (hotfixes, skipped migrations, mismatched indexes and extensions causing query plan divergence), and transformation drift (anonymization that breaks uniqueness, referential integrity and determinism). Scheduled pg_dump refreshes only cap staleness while adding lock windows and slow restores at scale, and logical replication doesn't carry DDL. The proposed fix is ephemeral copy-on-write database branches created at test time, inheriting production schema, data and sequences, with optional per-column masking, as offered by Neon.
- Mitigating Deadlocks in high concurrency environments
Shopify Engineering mediumAdeptConcurrent batch upserts into an InnoDB table keyed by a sequential id can deadlock even when processes touch different rows, because the gap locks taken on unique-key collisions span neighbouring index entries that other processes also need. Shopify mitigated this by changing the primary key to a composite (account, id), so rows are physically clustered per account and each per-account ETL process's gap locks stay within its own range. An extra unique index on id preserves existing joins with no application changes. The fix let them remove artificial delays added to avoid deadlocks and significantly increased import job throughput.
- Production Postgres on Railway: From First Deploy to High Availability
Railway mediumAdeptRailway Postgres can grow from a single private-networked database to a production setup with volume backups, point-in-time recovery, PgBouncer connection pooling and Patroni-based high availability, demonstrated with an orders API that uses idempotency keys so retries stay safe. PITR restores into a separate service for validation, and the guide stresses measuring RPO/RTO end to end, including validation and reconnection time. Transaction pooling breaks session settings, LISTEN, advisory locks and named prepared statements, so migrations should use an unpooled URL. In one small planned switchover test (primary, two replicas, etcd, HAProxy), writes were interrupted for about 17 seconds. That is a single observation, not a guaranteed failover time.