On a PostgreSQL 18 server, ps lists many postgres processes: what is the postmaster, and what do the other processes do?
answer
- supervisor that forks, never serves
- one child per connection
- checkpointer, background writer, walwriter
- 18 adds io workers
- parallel worker for PID
basics
~20 sThe postmaster is PostgreSQL's supervisor: it creates shared memory, listens for connections and forks one backend process per client. The other processes are helpers such as the checkpointer, background writer, walwriter and autovacuum launcher, plus background workers.
solid answer
~40 sThe postmaster is the first `postgres` process. It creates shared memory, listens on the port and socket, and `fork()`s a child for every connection; that child authenticates the client and then serves the session as its **backend** until disconnect, so backends are never reused without an external pooler. The postmaster also starts and supervises the helpers: the `checkpointer`, the `background writer`, the `walwriter`, the `autovacuum launcher` with its workers, and the `logical replication launcher`. On PostgreSQL 18 you also see `io worker` processes, because `io_method = worker` is the default. Others such as `archiver`, `walsender`, `walreceiver` and `startup` appear only when archiving or replication is in play, and parallel query adds short-lived `parallel worker for PID n` processes drawn from `max_worker_processes`.
go deeper
Recall that the postmaster forks one backend process per connection, and name three or four helper processes with a one-line job each.
Explain that the forked child authenticates the client, that backends are never reused, and how auxiliary processes differ from background workers drawn from max_worker_processes.
Read a real ps listing: separate feature-dependent processes from always-on ones, spot io workers as an 18 marker, and explain why the postmaster stays out of shared memory.
Weigh what process-per-connection costs in memory and fork overhead against the isolation it buys, and when that pushes a design toward an external pooler.
## The postmaster: a supervisor that stays out of the way When PostgreSQL starts, the first process is the **postmaster**: the `postgres` binary launched by `pg_ctl` or a service manager. In `ps` it keeps its original command line (for example `/usr/lib/postgresql/18/bin/postgres -D /var/lib/postgresql/18/main`), while every child rewrites its title to `postgres: ...` (with the `cluster_name` inserted when that setting is set). The postmaster: - creates the **shared memory** segment and semaphores at startup; - listens on the configured TCP port and Unix-domain socket; - **forks** a child for every incoming connection and for every helper process; - watches its children, restarts helpers that exit, and resets the whole server when a child crashes. The source describes it as creating shared memory but, as a rule, not touching it: the postmaster is not in the array of backend processes and takes no locks. That restraint is deliberate. A supervisor that never touches shared state cannot be dragged down by a child that left that state half-changed, so it survives to clean up. ## One backend process per connection On Unix-like systems the postmaster calls `fork()` as soon as a connection arrives. The **child** runs authentication itself (pg_hba.conf rules, password exchange, TLS), then becomes that session's **backend** for the rest of the connection. Its title becomes `postgres: <user> <database> <host>(<port>) <activity>`, for example `postgres: booking_app hotel 10.0.4.17(51522) idle`. Consequences an interviewer expects you to draw: - one connection equals one operating-system process with its own private memory for sorts, hashes and catalog caches; - a backend exits with its session; reuse across connections is an external pooler's job, such as PgBouncer; - a slow TLS or PAM exchange stalls only that child, never the listener. What each connection costs and how to set `max_connections` belong to the connection-tuning topic. ## Helper processes on a PostgreSQL 18 primary Most of these are **auxiliary processes** with fixed jobs; the logical replication launcher is technically a background worker (next section). | ps title | Job | |---|---| | `checkpointer` | Performs checkpoints: writes every dirty shared buffer to the data files so older WAL can be recycled | | `background writer` | Writes some dirty, not recently used buffers ahead of the clock sweep, so backends rarely write before reusing a buffer | | `walwriter` | Writes and flushes WAL buffers in the background | | `autovacuum launcher` | Schedules `autovacuum worker` processes across databases | | `logical replication launcher` | Starts the apply workers for subscriptions | | `io worker` | New in 18: executes asynchronous reads when `io_method = worker`, the default (`io_workers` defaults to 3) | Others appear only when a feature is on: `archiver` with `archive_mode`, `logger` with `logging_collector`, one `walsender` per connected standby or logical consumer, `startup` and `walreceiver` on a standby or during recovery, and `walsummarizer` (since 17) when `summarize_wal = on`. There is no statistics collector process in current releases: cumulative statistics are collected in shared memory. ## Background workers, including parallel query A second family is **background workers**, also forked by the postmaster but drawn from a pool capped by `max_worker_processes` (default 8, changed only by a restart). Parallel query uses them: a line such as `postgres: parallel worker for PID 4711` is a worker helping the query that backend 4711 is running, and it exits when that work is done. Parallel workers are additionally capped by `max_parallel_workers` (default 8). Core uses the same mechanism for the logical replication launcher, and extensions register their own, such as pg_prewarm's autoprewarm worker. When the pool is exhausted, a parallel query simply runs with fewer workers than it planned; the per-query planner knobs are a separate topic. ## Shared memory ties them together Every child attaches the same main shared memory: the shared buffer pool, WAL buffers, the lock table, the array of backend process slots and the cumulative statistics. The view `pg_shmem_allocations` lists the named allocations with their sizes. Parallel query also creates **dynamic shared memory** segments on demand, typically `posix` on Linux (`dynamic_shared_memory_type`). Private memory, in contrast, belongs to one backend and dies with it. ## What a strong answer sounds like 1. Name the postmaster as the supervisor that forks, restarts and resets, but never serves a query. 2. Say one backend per connection, authenticated by the forked child, and link that to external pooling. 3. Name the checkpointer, background writer, walwriter and autovacuum launcher with a one-line job each. 4. Mark the release: `io worker` processes are an 18 sign, `walsummarizer` a 17 one. 5. Tell auxiliary processes from background workers, and know where `parallel worker for PID n` comes from.
- Why does the PostgreSQL postmaster deliberately avoid touching shared memory itself?Because it must outlive a child's crash. It creates the segment but is not in the backend array and takes no locks, so a backend that dies holding a lock or mid-update cannot leave the postmaster stuck or corrupted. That is what lets it notice the crash, stop the remaining children, reinitialise shared memory and run crash recovery instead of failing with them.
- What does a ps line reading postgres: parallel worker for PID 4711 tell you, and what limits how many exist?It is a background worker the postmaster started for the query running in backend 4711; it exits when that part of the plan finishes. Parallel workers come from the pool sized by `max_worker_processes` (default 8, restart only) and are capped by `max_parallel_workers` (default 8). When slots run out, the query runs with fewer workers than planned.
- Which processes appear on a PostgreSQL streaming standby that a primary without replicas does not run?A `startup` process that replays WAL for as long as the server stays in recovery, and a `walreceiver` that streams WAL from the primary. The primary, in turn, runs one `walsender` per connected standby. The `checkpointer` and `background writer` run on the standby too; there the checkpointer performs restartpoints instead of checkpoints.
The postmaster is like a hotel duty manager who never carries luggage: each arriving guest is handed to a dedicated porter (a backend), specialists are called in for set jobs, and because the manager's own hands stay free, they can clear the building and reopen it if one porter causes an accident.
- Each client connection is a thread inside the postmaster process.
- The postmaster runs queries and takes locks like any other backend.
- PostgreSQL hands an idle backend to the next client without any pooler.
- The background writer is the process that performs checkpoints.
- A separate statistics collector process still gathers the pg_stat counters.
Assumes PostgreSQL 18: io worker processes exist only from 18 (io_method = worker), and walsummarizer from 17.