Chapter 01 · Outgrowing one database01 / 20

One database, one machine

Your shop keeps every order in one table on one database server. Each glowing dot is a write: a new order, a status change, a refund. The app servers in front hold no data, so adding more of them is easy.

The database is different. It has one disk, one CPU and a fixed amount of memory. Watch its two gauges: the fill level is disk space, and the bar underneath is write load, where 100% means the machine can't absorb writes any faster.

Business is good and traffic keeps climbing. Soon writes queue up and time out, and the disk runs out of room.

Each dot stands for thousands of writes, and time is squeezed: a real disk fills over months, not seconds.

Your turn

The classic first fix:

shellin the real world
$ psql shop -Atc "SELECT pg_size_pretty(pg_total_relation_size('orders'))"
3212 GB
$ df -h /var/lib/postgresql
Filesystem Size Used Avail Use% Mounted on
/dev/nvme1n1 4.0T 3.3T 700G 83% /var/lib/postgresql

One table, one disk. Indexes, the write-ahead log and vacuum all need room on that same disk too.