Databases 5 min read

Why PostgreSQL Keeps Working After the Main Process Crashes

This article explains how PostgreSQL’s process architecture allows existing connections to continue operating and persist data even when the postmaster (main) process crashes, demonstrates the behavior with step‑by‑step experiments, and discusses the limitations and monitoring implications.

dbaplus Community
dbaplus Community
dbaplus Community
Why PostgreSQL Keeps Working After the Main Process Crashes

PostgreSQL’s design separates the postmaster (the main server process) from backend processes that handle client sessions. The postmaster only listens for new connections, while each backend maintains its own session and can perform WAL writes, buffer flushes, and other operations independently.

Experiment Setup

A test table is created, then the postmaster process is deliberately killed. Screenshots show the state of the system after the kill, leaving only the backend and logger processes running (the WAL and shared buffers remain in memory).

While the postmaster is down, a client connected through an existing backend session continues to execute INSERT statements successfully, demonstrating that the backend can still write to the database.

Observations After Restart

When the database is restarted, the previously inserted rows are missing. The loss occurs because the transaction was asynchronous and the WAL writer process, which periodically flushes the WAL buffer, was not running; the backend only flushes the buffer when it cannot obtain one, so the WAL entry was never persisted.

Using a synchronous transaction (setting synchronous_commit = on) ensures that the WAL is flushed before the transaction completes, preventing data loss even after the postmaster crash.

Limitations of Backend‑Only Operations

Although a backend can write to the WAL and shared buffers, it cannot perform a checkpoint; that responsibility belongs to the checkpoint process. If a large operation triggers a checkpoint while the postmaster is down, the log will show an error indicating the checkpoint could not be performed.

Other auxiliary processes such as autovacuum and the statistics collector also disappear when the postmaster is killed, causing related maintenance tasks and statistics collection to fail.

Monitoring Implications

Relying on long‑lived connections to monitor database health may not reveal postmaster failures. Short‑lived connections can detect whether the postmaster is alive, but they risk exhausting connection slots. A combined approach using both long and short connections provides more comprehensive monitoring.

Crash‑Restart Parameter

PostgreSQL provides the restart_after_crash (boolean) setting, which controls automatic restart behavior after a crash. Certain code paths in src/backend/postmaster/postmaster.c can trigger a restart under specific conditions.

For example, if the autovacuum process is killed, all backend processes are disconnected, and the autovacuum launcher must be restarted manually.

Overall, PostgreSQL’s multi‑process architecture ensures that ongoing sessions can survive a postmaster crash, but certain background tasks and durability guarantees depend on the presence of the main process and its auxiliary workers.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PostgreSQLData Persistenceprocess crashdatabase reliabilitybackend process
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.