PostgreSQL Architecture and Installation
Processes and memory
PostgreSQL uses a process-per-connection model: the postmaster (postgres) listens on port 5432, forks a backend per client, and supervises background workers - checkpointer, background writer, WAL writer, autovacuum launcher, logical replication launcher. Shared memory holds shared_buffers and WAL buffers; each backend additionally gets private work_mem regions. Durability comes from WAL (write-ahead log): changes reach pg_wal before data pages are flushed.
On-disk layout
initdb creates a database cluster inside PGDATA, containing base/ (one directory per database), global/, pg_wal/, pg_xact/, and the config files postgresql.conf, pg_hba.conf, pg_ident.conf. Tablespaces map logical names to directories outside PGDATA through pg_tblspc.
Traps
- "Cluster" in PostgreSQL means one PGDATA run by one postmaster - not a high-availability cluster. A cluster holds many databases, but a single statement cannot query across databases.
CREATE DATABASEcopiestemplate1;template0is the pristine template to use when restoring a dump with a different encoding or locale.- Version numbering changed at 10: 9.6 → 10, then 10, 11, 12… so 13.4 → 14.1 is a major upgrade requiring
pg_upgradeor dump/restore. pg_xlogwas renamedpg_wal(andpg_clog→pg_xact) in v10; older material still uses old names.
Rule of thumb
Never start a server against a PGDATA from a different major version - check the PG_VERSION file first. Start with pg_ctl -D $PGDATA start or systemd, and find logs via log_destination / logging_collector.