Saturday, November 14, 2026

PostgreSQL Process Architecture Diagram and Details


PostgreSQL Process Architecture Diagram

                           +------------------+
                           |    POSTMASTER    |
                           |   (Parent PID)   |
                           +---------+--------+
                                     |
       ----------------------------------------------------------------
       |            |            |            |            |            |
       v            v            v            v            v            v
+-------------+ +-----------+ +-----------+ +-----------+ +---------+ +---------+
| Background  | | WAL       | |Checkpointer| | Autovac  | | Archiver| | Startup |
| Writer      | | Writer    | |           | | Launcher | |         | | Process |
+-------------+ +-----------+ +-----------+ +-----------+ +---------+ +---------+
                                                        |
                                            ----------------------
                                            |         |          |
                                            v         v          v
                                      +----------+ +----------+ +----------+
                                      |Vacuum W1 | |Vacuum W2 | |Vacuum W3 |
                                      +----------+ +----------+ +----------+
                                        Client Connections
                                                |
       ----------------------------------------------------------------
       |                 |                    |                  |
       v                 v                    v                  v
+--------------+ +--------------+ +--------------+ +--------------+
| Backend PID  | | Backend PID  | | Backend PID  | | Backend PID  |
| User Session | | User Session | | User Session | | User Session |
+--------------+ +--------------+ +--------------+ +--------------+
Shared Memory:
--------------------------------------------------------
| Shared Buffers | WAL Buffers | Locks | Proc Array |
--------------------------------------------------------


How to See PostgreSQL Processes at OS Level

Find Postmaster (Parent Process)

ps -ef | grep postgres

Example:

postgres  1000     1  0 10:00 ? 00:00:00 postgres
postgres  1001  1000  0 10:00 ? 00:00:00 postgres: checkpointer
postgres  1002  1000  0 10:00 ? 00:00:00 postgres: background writer
postgres  1003  1000  0 10:00 ? 00:00:00 postgres: walwriter
postgres  1004  1000  0 10:00 ? 00:00:00 postgres: autovacuum launcher

Notice:

PID 1000 = Parent Process
PPID 1   = Started by OS

This is the Postmaster.


Better Process Tree

Linux

pstree -p | grep postgres

Example:

postgres(1000)
 ├─postgres(1001)
 ├─postgres(1002)
 ├─postgres(1003)
 ├─postgres(1004)
 ├─postgres(1200)
 ├─postgres(1201)
 └─postgres(1202)

Much easier to visualize.


1. Postmaster

Responsibility

  • Starts all PostgreSQL processes
  • Accepts client connections
  • Handles crash recovery
  • Monitors child processes

Check:

ps -fp <postmaster_pid>

Example:

ps -fp 1000


If Backend Crashes

Backend dies
      ↓
Postmaster detects
      ↓
May restart required processes

Postmaster acts like a supervisor process.


2. Backend Process

Every client connection gets a backend process.

Connect:

psql postgres

Run:

SELECT pg_backend_pid();

Example:

  pg_backend_pid
-----------------
      14567

At OS level:

ps -fp 14567

Output:

postgres: appuser mydb 10.0.0.10 idle


Find Active Queries

SELECT pid,
       usename,
       state,
       query
FROM pg_stat_activity;

Map PID to Linux:

top -Hp <pid>

or

ps -fp <pid>


3. WAL Writer

Responsibility

Writes WAL buffers to:

$PGDATA/pg_wal

Process appears as:

postgres: walwriter

Check:

ps -ef | grep walwriter

Example:

postgres 1003 1000 0 ? postgres: walwriter


Observe WAL Activity

Inside PostgreSQL:

SELECT *
FROM pg_stat_wal;

Important metrics:

wal_records
wal_fpi
wal_bytes


4. Checkpointer

Responsibility

Writes dirty pages from memory to data files.

Process:

postgres: checkpointer

View:

ps -ef | grep checkpointer


Monitor

SELECT *
FROM pg_stat_bgwriter;

Interesting columns:

checkpoints_timed
checkpoints_req
checkpoint_write_time
checkpoint_sync_time


5. Background Writer

Responsibility

Gradually writes dirty buffers before checkpoint.

Goal:

Reduce checkpoint spikes

Process:

postgres: background writer

Check:

ps -ef | grep "background writer"


Why Important

Without BGWriter:

Checkpoint writes millions of dirty pages

causing:

High I/O
Slow performance


6. Autovacuum Launcher

Responsibility

Monitors all databases.

Starts worker processes when necessary.

OS command:

ps -ef | grep autovacuum

Example:

postgres: autovacuum launcher


7. Autovacuum Workers

Process:

postgres: autovacuum worker

Check:

ps -ef | grep "autovacuum worker"

Example:

postgres: autovacuum worker mydb


Monitor Current Vacuum

SELECT *
FROM pg_stat_progress_vacuum;

Output:

pid
phase
heap_blks_total
heap_blks_scanned


8. Archiver Process

Only if:

archive_mode = on

Process:

postgres: archiver

Check:

ps -ef | grep archiver


Monitoring

SELECT *
FROM pg_stat_archiver;

Example:

archived_count
failed_count


9. Startup Process

Visible during:

Database startup
Crash recovery
Standby recovery

OS:

ps -ef | grep startup

Example:

postgres: startup recovering


During Recovery

Logs:

tail -f $PGDATA/log/postgresql.log

Example:

redo starts at ...
redo done at ...


10. WAL Sender

Primary Server Replication.

Process:

postgres: walsender

Check:

ps -ef | grep walsender


Monitoring

SELECT *
FROM pg_stat_replication;

Example:

application_name
client_addr
state
sync_state


11. WAL Receiver

Standby Server.

Process:

postgres: walreceiver

OS:

ps -ef | grep walreceiver


Monitoring

SELECT *
FROM pg_stat_wal_receiver;


Real Production Troubleshooting

Check Entire Process Architecture

ps -ef | grep postgres


Check Process Tree

pstree -p | grep postgres


Check CPU Consumer

top -p $(pgrep postgres | tr '\n' ',')


Match PostgreSQL PID with Query

SELECT pid,
       usename,
       state,
       wait_event,
       query
FROM pg_stat_activity;

Then:

ps -fp <pid>


Check Shared Memory

ipcs -m

Or:

cat /proc/<postmaster_pid>/status


Oracle vs PostgreSQL Process Mapping

PostgreSQLOracle
PostmasterPMON (roughly supervisor role)
Backend ProcessDedicated Server Process
WAL WriterLGWR
CheckpointerCKPT
Background WriterDBWR
Startup RecoverySMON
WAL SenderData Guard Transport
WAL ReceiverManaged Recovery Process
ArchiverARCn
AutovacuumNo direct equivalent

Interview Answer (2-Minute Version)

PostgreSQL uses a process-based architecture. The Postmaster is the parent process that starts and monitors all child processes. For each client connection, a dedicated backend process is created. Key background processes include WAL Writer (writes WAL records for durability), Checkpointer (flushes dirty pages to disk), Background Writer (reduces checkpoint I/O spikes), Autovacuum Launcher and Workers (clean dead tuples and freeze old rows), Archiver (archives WAL files), and WAL Sender/Receiver (streaming replication). At the OS level these can be viewed using commands such as:

ps -ef | grep postgres
pstree -p | grep postgres
top -H -p <pid>

and correlated with database views like:

pg_stat_activity
pg_stat_progress_vacuum
pg_stat_replication
pg_stat_bgwriter






No comments:

Post a Comment

About the Author : Anurag Pandey | Database cloud Architect | Oracle | SQL Server | PostgreSQL | AI and Data Platform Enthusiast

Anurag Pandey is a Database Architect with expertise in Oracle, PostgreSQL, SQL Server, Linux, and enterprise database platforms and specializes in database architecture, performance tuning, high availability, disaster recovery, cloud modernization, and operational excellence. With extensive experience in enterprise-scale environments, Anurag is passionate about leveraging AI, automation, and modern data platforms to improve reliability, scalability, and business outcomes. He actively contributes to technical communities through knowledge sharing, architecture guidance, and thought leadership in database and data engineering domains.

Follow more articles at

Visit Blog

PostgreSQL Process Architecture Diagram and Details

PostgreSQL Process Architecture Diagram                            +------------------+                            |    POSTMASTER    |     ...