Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 11 min read Incident hardMaster

When SIGTERM Does Nothing: A Postgres Mystery

Creating a logical replication slot on a Postgres hot standby (v16+) can hang indefinitely and ignore pg_cancel_backend and pg_terminate_backend when a transaction is still open on the primary. The cause is XactLockTableWait: on a standby, LockAcquire returns immediately while TransactionIdIsInProgress still sees the primary's transaction via KnownAssignedXids. The function therefore spins in a 1ms pg_usleep loop with no interrupt check and no wait_event, which left a WAL-retaining slot that only a full restart could clear. A one-line CHECK_FOR_INTERRUPTS patch was accepted and backported to all supported versions, and a new wait event plus more efficient standby waiting are proposed for Postgres 19.

Related posts

  • Blocking cutovers to save replication slots

    PlanetScale mediumAdept

    PlanetScale Postgres blocks planned cutovers (resizes, parameter changes, maintenance) when logical replication slots aren't synchronized to the replica being promoted, because vanilla Postgres will promote a replica without the slot and silently break CDC consumers. To make slots promotion-ready, create them with failover = true (or ALTER_REPLICATION_SLOT ... (FAILOVER true)) and set hot_standby_feedback and sync_replication_slots to on. The operator detects misconfiguration, alerts users, waits for slots to be ready, and manages synchronized_standby_slots. Enabling hot_standby_feedback pins the primary's vacuum horizon and can add bloat, which is why both settings are off by default.

  • Patching the PostgreSQL JDBC Driver

    Zalando Engineering mediumAdept

    Postgres 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.

  • PostgreSQL Stories: A simple query with a big problem

    Render mediumAdept

    A seemingly simple indexed join with LIMIT 1 ran for over four hours on Render's staging PostgreSQL, holding a lock that blocked CREATE OR REPLACE VIEW migrations and stalled deploys. The team traced it by watching oldest-transaction age, querying pg_stat_activity for long-running active queries, and using pg_blocking_pids() to map which backends blocked which migrations. The culprit was an engineer's ad-hoc psql query: pressing Ctrl+C in psql stopped reading results but left the server-side query running. Killing the backend fixed it immediately. Key lessons are to keep transactions short, because they block locks, autovacuum and risk XID wraparound, and to set application_name and inspect usename so queries can be traced to their source.

  • 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.

  • ClickPipes for Postgres now supports failover replication slots

    ClickHouse mediumAdept

    Postgres ClickPipes can now create logical replication slots with failover enabled, so CDC pipelines into ClickHouse survive a primary-to-standby promotion. The feature depends on Postgres 17 logical replication failover. Both primary and standby must run Postgres 17+, with the standby using a physical replication slot and synchronous commit configured. hot_standby_feedback and sync_replication_slots must be enabled on the standby, and the standby's physical slot must be added to synchronized_standby_slots on the primary so the standby never lags the ClickPipe. You can confirm it works by checking pg_replication_slots on the standby for a mirror_ slot with synced and failover set to true.

The quest for software engineering knowledge.

Look:
Layout: