Home›Operate›Capacity calculator
Designs · capacity

Capacity calculator

How much memory, disk and log volume will this table need in a year?

You will learn: a first estimate of data size, working set, memory, disk and log volume, with every assumption written next to the number.

This is the arithmetic I do on a whiteboard before sizing a server, turned into a form. It gives a starting estimate, not a guarantee. Load a sample of real data and measure before you buy anything.

The assumptionsTable size is rows times row size plus 25 percent for page headers and free space. Each index, including the primary key, takes rows times entry size plus 40 percent for B-tree overhead. With a retention period, the row count levels off at new rows per day times retention days. Memory is the working set (the hot share of tables and indexes) plus 30 percent, plus 2 GB for the operating system, plus about 10 MB per connection. Disk keeps 30 percent free and adds 30 percent for logs, temporary files and growth surprises. Log volume is about 1.5 to 3 times the bytes changed per write (more with many indexes or random updates, because of full-page writes); measure with pg_wal / pg_stat_wal. These are round numbers for a first estimate. Measure on real data.
Your turn

Your estimate says 3,000 writes a second at peak. Before you trust it, which two numbers do you measure on real hardware, and how?

Write your answer down first. Then open mine.

Show my answer

1. The cost of one durable commit on your storage, with your real durability settings. pgbench or sysbench with one client and then with many, like Notebook 2. Network storage can be several times slower than the numbers you have in your head.

2. The real size of a row and its indexes. Load a million rows that look like production, then divide the table plus index size by the row count. The estimate's bytes-per-row is the number most often wrong by two or three times.

Then check the peak-to-average ratio against real traffic logs, not a guess.

Connected

Where this shows up

The same mechanism, sharding and partitioning, caches and memory, elsewhere on the site: in real incidents, in measurements, and in designs.

Part 4 of 4 · Operate · 15 pagesAll pages

How do I run it in production? What to check when it is slow or broken, where it runs and what it costs, how big it must be, pooling, backups, security, upgrades and other changes made safely.