---
title: "When SIGTERM Does Nothing: A Postgres Mystery"
description: "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."
url: "https://swe.quest/articles/when-sigterm-does-nothing-a-postgres-mystery-0ecf6df7cd549d22"
canonical: "https://clickhouse.com/blog/sigterm-postgres-mystery"
source: "ClickHouse"
published: "2025-07-08"
difficulty: "hard"
kind: "Incident"
reading_minutes: 11
tags: ["postgres","replication","debugging","event-driven"]
---

# When SIGTERM Does Nothing: A Postgres Mystery

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2025-07-08, 11 min read, Incident. Original: [https://clickhouse.com/blog/sigterm-postgres-mystery](https://clickhouse.com/blog/sigterm-postgres-mystery)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)
- [Event-driven architecture](https://swe.quest/tags/event-driven.md) (Backend & APIs)

## Prerequisites

- Postgres logical replication ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Write-ahead logging ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))
- Postgres hot standbys ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Unix signals

## Keywords

PostgreSQL, ClickPipes, PeerDB, XactLockTableWait, KnownAssignedXids, pg\_create\_logical\_replication\_slot, strace, CHECK\_FOR\_INTERRUPTS

## Related posts

- [Blocking cutovers to save replication slots](https://swe.quest/articles/blocking-cutovers-to-save-replication-slots-d52d9d5fcc4a6789.md): PlanetScale · 2026-09-21 · Medium · 5 min read · PostgreSQL, Replication, Event-driven architecture, Deployment
  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.
- [Patching the PostgreSQL JDBC Driver](https://swe.quest/articles/patching-the-postgresql-jdbc-driver-47e9400eaa77f0d2.md): Zalando Engineering · 2023-11-08 · Medium · 10 min read · PostgreSQL, Replication, Event-driven architecture, Java & JVM, Open source
  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.
- [PostgreSQL Stories: A simple query with a big problem](https://swe.quest/articles/postgresql-stories-a-simple-query-with-a-big-problem-6dd72fff3c9a1d47.md): Render · 2024-04-03 · Medium · 10 min read · PostgreSQL, Debugging, Incidents & postmortems, Schema migrations
  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.
- [Read your writes: WAIT FOR in PostgreSQL 19](https://swe.quest/articles/read-your-writes-wait-for-in-postgresql-19-ead8d2a645bd23c3.md): ClickHouse · 2026-08-25 · Medium · 6 min read · PostgreSQL, Replication, Consistency models
  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\`.
- [ClickPipes for Postgres now supports failover replication slots](https://swe.quest/articles/clickpipes-for-postgres-now-supports-failover-replication-slots-63903c6595faed76.md): ClickHouse · 2025-11-11 · Medium · 3 min read · PostgreSQL, Replication, Event-driven architecture, Analytics & OLAP
  Postgres ClickPipes can now create logical replication slots with failover enabled, so CDC pipelines into ClickHouse survive a primary-to-standby promotion.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
