PostgreSQL 16Dev & Eng

Content type: Concept

8 min read

PostgreSQL 16 Swaps SIGKILL for SIGABRT to Preserve Core Dumps of Stuck Processes

Article · Dev & Eng
Reading
8 min
Tables
1
Code
1
In short

Two parameters added to PostgreSQL 16 swap the signal that terminates processes during a crash for SIGABRT, trading silent discard for forensic evidence, at a disk and availability cost that the documentation summarizes but does not quantify.

What send_abort_for_crash and send_abort_for_kill Change

A recent article published on Planet PostgreSQL by a consultant at PGX Inc. dissects two parameters that exist for a single purpose: to deliberately make a crash worse, so that it leaves evidence behind. They are send_abort_for_crash and send_abort_for_kill, both available since PostgreSQL 16 (released in September 2023), both off by default, both adjustable via reload (they are sighup), and both hidden in the manual's Developer Options section, which means they don't appear in postgresql.conf.sample.

To understand what they change, you need to recall the default behavior. When a PostgreSQL child process dies by signal, or exits with a code other than 0 or 1, the postmaster sends SIGQUIT to all other children except the logger. Each backend responds with quickdie(), notifies the client, and exits via _exit(2); auxiliary processes do the same, without the notification. Whoever is still alive five seconds later receives SIGKILL. Only then is shared memory rebuilt and the WAL replayed.

send_abort_for_crash = on replaces that initial SIGQUIT with SIGABRT. send_abort_for_kill = on replaces the five-second SIGKILL with the same SIGABRT. The difference matters because PostgreSQL doesn't handle SIGABRT in any special way: no process installs a handler for it, and pqsignal.c guarantees it is never blocked. What takes over is the kernel's default action: write a core file and terminate. An ordinary crash leaves exactly one core, that of the process that broke; quickdie() and the subsequent SIGKILL destroy the state of everything else, including the process that actually mattered to investigate.

Where the Idea Came From

Tom Lane added both parameters in November 2022, after his NetBSD buildfarm animal, nicknamed mamba, had been failing replication tests intermittently and in a way that couldn't be reproduced in any other environment: a process would get stuck, and by the time anyone could look, the postmaster's SIGKILL had already erased any trace. He proposed SIGABRT in place of SIGKILL.

Andres Freund had already tried the same thing as a hardcoded #define while hunting a hang in asynchronous I/O work, and reported the result:

did cause a problematic flood of core files

Andres Freund, PostgreSQL developer

His suggestion was to turn that into a GUC, precisely so the operator could decide when to pay that price. In the same commit, the postmaster's old -T switch (which sent SIGSTOP to survivors, so a developer could collect the cores manually) became synonymous with send_abort_for_crash = on, and -n, which had done nothing for decades, was removed.

The Flood, in Numbers

The author reproduced the scenario on an 18.6 cluster with shared_buffers = 128MB: one client idle in a transaction, another in pg_sleep(), and a third backend receiving SIGSEGV. With default settings, the cluster resumed accepting connections within half a second, with a single 161 MB core. With send_abort_for_crash = on, the log showed something quite different:

LOG: client backend (PID 4420) was terminated by signal 11: Segmentation fault
LOG: terminating any other active server processes
DEBUG: sending signal 6/SIGABRT to client backend process with pid 4413
DEBUG: sending signal 6/SIGABRT to client backend process with pid 4412
DEBUG: sending signal 6/SIGABRT to background worker process with pid 4362
DEBUG: sending signal 6/SIGABRT to autovacuum launcher process with pid 4361
DEBUG: sending signal 6/SIGABRT to walwriter process with pid 4360
DEBUG: sending signal 6/SIGABRT to background writer process with pid 4359
DEBUG: sending signal 6/SIGABRT to checkpointer process with pid 4358
DEBUG: sending signal 6/SIGABRT to io worker process with pid 4356
DEBUG: sending signal 6/SIGABRT to io worker process with pid 4355
DEBUG: sending signal 6/SIGABRT to io worker process with pid 4354

Eleven cores, 1.8 GB in total, and 4.3 seconds until the cluster resumed accepting connections, because the postmaster only logs all server processes terminated; reinitializing after every child has terminated, and a process writing a core hasn't terminated yet. The size is no coincidence: Linux's default coredump_filter includes shared anonymous mappings, which is exactly what shared_buffers is.

With shared_buffers = 1GB, each core came out at 1.14 GB; the same idle cluster produced 12.5 GB of files and took about fifteen seconds to come back. Scaled to a real server, with 32 GB of shared_buffers and two hundred connections, the math exceeds six terabytes of core files per crash, written to the data directory exactly when the cluster is trying to recover.

Why Turning on Only One of the Two Is Worse Than Turning on Neither

That test with 1 GB of shared_buffers exposed a trap: the core of the backend that crashed finished before the postmaster even noticed the crash, but the other ten, written simultaneously, took more than five seconds. At the five-second mark, the postmaster does what it always does: sends SIGKILL to whoever hasn't exited yet. SIGKILL interrupts a core in progress. Ten of the eleven cores came out truncated, between 530 and 720 MB, and gdb rejected each one with has a segment extending past end of file.

With send_abort_for_kill = on also enabled, that second escalation signal turns into another SIGABRT, which a process already writing a core simply ignores, and all eleven cores come out complete. The practical breakdown looks like this:

ConfigurationEvidence collectedMain risk
Default (both off)Only the core of the process that crashedStuck processes vanish without a trace
Only send_abort_for_crash = onCores of everyone, but truncated if writing takes more than 5sCorrupted files, useless in gdb
Both onComplete cores of all processesDisk volume and, in some cases, an unavailable cluster

The Most Defensible Case: the Stuck Process

send_abort_for_kill, on its own, targets exactly the process that default behavior destroys without leaving anything: the one that's stuck and would simply be killed with SIGKILL five seconds after another backend crashes. The author built a C function that blocks SIGQUIT and sleeps, called it from a backend, and crashed another one with SIGSEGV. With default settings, the stuck backend took SIGKILL in about five seconds, leaving nothing behind.

With the parameter turned on, the log recorded issuing SIGABRT to recalcitrant children, and the resulting core carried the stuck_inner_loop function exactly where it should be, a few frames below standard_ExecutorRun. The same escalation runs during pg_ctl stop -m immediate, so this parameter also decides the fate of a backend that doesn't die during an immediate shutdown.

The Catch: SIGABRT Is Not SIGKILL

The problem is that SIGABRT can be blocked, caught, or ignored, and for a stopped process (SIGSTOP, or under an attached gdb) it simply stays pending, since SIGKILL is never blocked and always terminates even a stopped process. The postmaster escalates only once: after sending SIGABRT, it resets the timer, and with send_abort_for_kill = on there's no longer any path by which it would go on to send SIGKILL.

The author tested this: stopped a backend with SIGSTOP, crashed another, and thirty seconds later the stopped backend still had SIGABRT pending, with the entire cluster refusing connections. The core only came out, and the cluster only came back, the instant he sent SIGCONT. With default settings, the same experiment finished in about six seconds. It's worth noting that in PostgreSQL 19 (RC1 and stable branch as of November 6), this escalation after a crash can take up to sixty seconds on an idle cluster, and the delay applies to both SIGABRT and SIGKILL.

Two OS Settings That Decide Whether It Works

Neither parameter produces a core on its own; two OS settings come into play:

  • Core size limit: with ulimit -c 0 inherited by the postmaster, the SIGABRTs go out, but no core appears, and the only visible effect is the client losing the warning message. It's worth checking Max core file size in /proc/<postmaster pid>/limits before relying on the mechanism.
  • kernel.core_pattern: the kernel's default is the fixed name core, and the kernel deletes and recreates that file on every dump, so eleven processes writing at the same time produce a single survivor. If core_pattern points to a pipe into systemd-coredump, the files go compressed to /var/lib/systemd/coredump, under a cap that by default is ten percent of the filesystem and at most 4 GiB.

The practical advice is to configure a pattern with %p and %e in it, pointing to a place with room, before the crash happens, not after.

When It's Worth Turning On

The author's recommendation is to leave both parameters off in production. To hunt down a crash or a hang that doesn't reproduce, the suggestion is to do it on a replica nobody depends on, turn both on together via reload, check the core limit and core_pattern, wait for the event to happen, and turn the parameters off again while the cores are copied elsewhere.

For a single stuck process, on a system that needs to stay up, neither GUC is necessary: gcore -o /somewhere/pg <pid> pauses the backend only for the time it takes to write a complete core and then lets it continue, and pg_ctl kill ABRT <pid> forces a core of a specific process and starts the crash-restart cycle by choice, not by accident.

For those who operate PostgreSQL in production, the central point of the material is that the one Unix signal that always works, SIGKILL, stops being in the postmaster's hands as soon as send_abort_for_kill comes into play, and that trade needs to be deliberate, not a reflex from someone who just wants "more logging in case of error".

Translated from the Brazilian Portuguese original · Read the original