Home›Learn›PostgreSQL 6: when it breaks
PostgreSQL · Chapter 6

When PostgreSQL breaks

Something is wrong right now. Where do I start?

Every incident I have worked starts the same way: confirm what is really happening, find the cause, then fix the smallest thing that works. These playbooks follow that order.

Chapter 6 · When it breaks

Start from what you see

Each playbook starts from a symptom, confirms it with read-only commands, names the likely causes in the order I see them, and only then suggests a fix with its risk. The same playbooks drive the DBA agent.

PlaybookToo many connectionsNew connections fail with "too many connections" (MySQL) or "sorry, too many clients already" (PostgreSQL), or the app's pool times out waiting for one. Often right after a deploy, a failover or a traffic spike.PlaybookCPU at 100%The database CPU is pinned and everything is slower. Often no single query looks slow on its own.PlaybookThe disk is filling upFree space is falling faster than the data is growing, or an alert fired at 85%.PlaybookA replica is far behindReads from replicas return old data, or the lag alert fired. A failover now would lose more, or take longer.PlaybookQueries waiting on locks, or timing outRequests hang, then fail with lock wait timeouts or deadlock errors. CPU may be low: things are waiting, not working.PlaybookOne query suddenly got slowA query that took milliseconds yesterday takes seconds today. The code did not change.PlaybookEverything is slow and the disk is busyRead latency is up across many queries. Disk reads per second climbed, and CPU waits on I/O.PlaybookOut of memory, or the server restartedThe database process was killed by the operating system, or restarted on its own. Clients saw connection errors.PlaybookWrites and commits are slowReads are fine, but inserts and updates take longer. Commit latency rose while CPU is low.PlaybookTables grow but rows do notTable size keeps rising while the row count is flat. Scans get slower over weeks.PlaybookPatroni: no leader, or the primary went read-onlyWrites fail with "cannot execute ... in a read-only transaction". patronictl shows no Leader, or every member as a Replica.PlaybookPatroni: an unexpected failover, or failovers that keep happeningThe primary moved without anyone asking. Apps saw a burst of errors. Maybe it happened several times.PlaybookPatroni: the old primary will not rejoin as a replicaAfter a failover, the old primary shows as stopped or start failed, with errors about timelines or missing WAL.
Practice before it is real

Rehearse an outage

Reading a playbook is not the same as running one with your heart rate up. On call tonight gives you incidents that branch on what you check, and the lab notebooks show what these failures look like on a real server, with the captured output.

← Chapter 5: Running it as a DBREYou finished the PostgreSQL trackBack to chapter 1Or pick another database in the Learn menu.
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