Home›Learn›PostgreSQL 5: running it as a DBRE
PostgreSQL · Chapter 5

Running PostgreSQL as a DBRE

What do I watch, which settings matter, and where do I look first?

Knowing how PostgreSQL works is half the job. The other half is running it: the signals I watch, the logs I read, the handful of parameters that decide most outcomes, and the commands that show the truth on a live server.

Chapter 5 · Running it

What I watch on every PostgreSQL server

A DBRE's job is to know about a problem before the app does. These are the signals I put on a dashboard and alert on, and why each one matters.

Latency and errorswhat users feelp99 within target
Connectionsprocesses in usealert at 80% of max
Oldest transactionholds back vacuumalert past 1 hour
Replication lagwhat a failover losesalert past 30 s
Dead rows, XID agebloat and wraparoundalert at 1 billion age
Checkpoints, WALrequested vs timedmostly timed
Disk and backupsfree space, last restore testrestore never tested

Example dashboard: the thresholds are starting points I would tune per system, and the colors are made up for the picture.

SignalWhy I watch itWhere it comes from
Query latency and errorsThe only numbers your users feel. Everything else explains these.pg_stat_statements, the app's own metrics
Connections in useEach one is a process. Near max_connections, new requests fail.pg_stat_activity
Oldest open transactionHolds back vacuum for the whole server (Chapter 3).pg_stat_activity.xact_start
Replication lag and slotsA failover loses what the replica did not have; a forgotten slot fills the disk.pg_stat_replication, pg_replication_slots
Dead rows and transaction ID ageBloat slows every scan; wraparound age stops writes if ignored.pg_stat_user_tables, age(datfrozenxid)
Checkpoints and WAL rateRequested checkpoints mean max_wal_size is too small.pg_stat_checkpointer, pg_stat_wal
Disk free, and the last good backupThe two things that end careers. A backup counts only once a restore has been tested.The OS, your backup tool

Run the same checks on your own server in two minutes with the health check. Backups and upgrades have their own pages: backups and restore time, major version upgrades.

Every log file a DBA needs to know

These are the exact names. They sit in the locations from the file trees above. Each log has one job. Each log has one thing to check during an incident. The deep dive on the five data logs is in The log files. This table adds the operational logs a DBA reads first: server, error, slow.

LogExact file nameWhere it sits (on-prem)What it doesWhat to check in it
PostgreSQL
Write-ahead log
pg_wal/000000010000000000000003pg_wal/ inside the data directoryEvery change, recorded before the data file changes. Commit means this log is fsynced. It also feeds replicas and point-in-time recovery.Total size (du -sh pg_wal) and archive_status/. A growing pile of .ready files means archiving is failing.
PostgreSQL
Server log
postgresql-18-main.log/var/log/postgresql/ (Debian) or log/ in the data directoryThe server's own diary. Checkpoints. Slow statements, if enabled. Errors. Crash recovery.Checkpoint frequency. "duration:" lines for slow statements. The first error at the incident's start time.

The parameters DBAs actually touch during outages

This is not the full configuration reference. It is the short list that comes up in real incidents. Each row states what the parameter does and the outage rule for it. Safe live lever means change it during the incident. Planned change means it needs a restart or a window. Do not improvise it mid-incident. Do not touch means changing it converts the incident into data loss or a longer outage.

PostgreSQL Outage parameters

ParameterWhat it doesDuring an outage
shared_buffersSize of the page cache. Start at about 25% of RAM.Planned change. It requires a restart. Never use it as the mid-incident lever. If the working set outgrew it, that is next week's change. Size it from pg_stat_bgwriter evidence.
work_memMemory per sort or hash operation. Per operation, not per connection. Total use is work_mem times operations times connections.Safe live lever, per session: SET work_mem='256MB' for the one reporting query that is spilling. A global raise mid-incident is an OOM risk at full concurrency.
max_connectionsHard cap on backend processes. Each one costs memory and bookkeeping.Do not raise to fix "pool exhausted" It admits more load into an already overloaded server. It needs a restart anyway. The fix is a pooler (PgBouncer) and killing idle-in-transaction sessions.
wal_levelHow much information the WAL carries: minimal, replica, or logical.Do not touch. It needs a restart. Replicas and logical subscribers are built on the current level. Changing it mid-incident breaks the copies you may be about to fail over to.
max_wal_sizeWAL volume that triggers a checkpoint. Default 1 GB.Safe live lever (reload, no restart) Use it when num_requested in pg_stat_checkpointer (17 and later; checkpoints_req in pg_stat_bgwriter before 17) shows size-triggered checkpoint storms. Raise it and reload.
checkpoint_timeoutTime trigger for checkpoints. Default 5 min. Whichever fires first wins, size or time.Safe live lever (reload) alongside max_wal_size. Lengthening it spreads the flush I/O. The price is longer crash recovery.
autovacuum_*Naptime, max workers, and per-table vacuum and analyze scale factors. They set how aggressively dead tuples and stale stats are cleaned.Safe live lever for bloat: Raise workers, lower the scale factor on the one hot table (ALTER TABLE … SET). Never disable autovacuum to "help". That is how bloat and wraparound start.
-- check SHOW shared_buffers; SHOW work_mem; SHOW wal_level; SHOW max_wal_size; -- change the safe levers (reloadable, no restart) ALTER SYSTEM SET max_wal_size = '16GB'; ALTER SYSTEM SET checkpoint_timeout = '15min'; SELECT pg_reload_conf(); -- per-session + per-table levers SET work_mem = '256MB'; -- this session only ALTER TABLE orders SET (autovacuum_vacuum_scale_factor = 0.05);
See it yourself · copy-paste commands

Open a real database and check every claim on this page

Every mechanism above is observable on a running server in under two minutes. These commands are grouped by the question they answer. Where are the files. Where is the log position. How far behind are the copies. Is cleanup keeping up. Run them against any install. The output either confirms the model on this page or shows you the specific place your system deviates from it.

PostgreSQL · psql + shell
-- where is everything?
SHOW data_directory;
SELECT pg_relation_filepath('users');
-- → base/16384/16397

-- the WAL: where are we writing?
SELECT pg_current_wal_lsn();
$ ls $PGDATA/pg_wal
$ pg_waldump $PGDATA/pg_wal/000000010000000000000003

-- replicas and their lag
SELECT client_addr, state, replay_lag
  FROM pg_stat_replication;

-- dead row versions piling up?
SELECT relname, n_dead_tup
  FROM pg_stat_user_tables;
Next · chapter 6When it breaksPlaybooks, from the symptom to the fix← Chapter 4: High availability
Part 1 of 4 · Learn · 56 pagesAll pages

How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect