Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

A PostgreSQL table of 50 million shipment rows gets 5,000 status updates per second. WAL volume is 2 TB per day, replicas lag, and backup costs keep rising. The table has 9 indexes, including one on status and one on updated_at. How do you reduce the write load, and how do you work with the owning team?

First I would measure: with indexes on status and updated_at, every status update changes an indexed column, so none of them are HOT, and each one writes into all 9 indexes plus full-page images, which is what produces 2 TB of WAL a day. Then I would remove what blocks HOT (drop or replace the updated_at index, drop unused indexes, move the fast-changing columns into a narrow table), lower fillfactor so new versions fit on the same page, and cut WAL further with wal_compression, less frequent checkpoints and batched updates. All of it is agreed with the owning team using before-and-after WAL rates and query plans, and WAL per table goes on their dashboards.

Why this question is asked

2 TB of WAL per day is not only a storage problem: every byte is shipped to each replica, archived for point-in-time recovery and kept in backups, so it shows up as replica lag, backup cost and slower recovery. Interviewers like this scenario because the numbers can be explained precisely, and because the fix touches another team's schema, which tests how we work with people. In this answer, we will work out where the WAL comes from, change the indexes and storage settings to make updates cheap, reduce WAL at the server level, and plan the collaboration with the owning team.

1Where 2 TB a Day Comes From

Start with arithmetic. 5,000 updates per second is 432 million updates per day, and 2 TB divided by 432 million is about 4.6 KB of WAL per update. A status change is a few bytes, so something is multiplying it a thousand times. The usual suspects, as we know from write amplification, are index maintenance and full-page images.

We confirm it with statistics. pg_stat_user_tables shows how many updates were HOT, heap-only tuple updates that skip all index work. And pg_walinspect or pg_waldump can summarise WAL records by type and relation, showing how much volume is heap, how much each index and how much full-page images.

Java
SELECT n_tup_upd, n_tup_hot_upd FROM pg_stat_user_tables WHERE relname = 'shipment';
-- 432,118,000 | 1,204,000 -> 0.3% HOT: almost every update writes all 9 indexes
-- WAL per update = 2 TB / 432 M = about 4.6 KB
-- per update: heap record + 9 index inserts, plus 8 KB page images for pages first touched since the checkpoint

The reason HOT never happens is the two indexes in the question. A HOT update is only possible when no indexed column changes. Every status update changes status, which is indexed, and the application also sets updated_at, which is indexed too. So each update creates a new entry in all 9 indexes, and with random shipments being updated, many of those index pages are being touched for the first time since the last checkpoint, which adds a full 8 KB page image each time.

2Removing What Blocks HOT

We go through the indexes with the team. pg_stat_user_indexes shows idx_scan per index; indexes with no scans over a few weeks, checked on replicas as well, can be dropped, and each one removed is one less write per update. Then we look at the two culprits.

The updated_at index usually serves a job that finds recently changed shipments. If that job can use a different access path, for example a BRIN index, which since PostgreSQL 16 does not block HOT (check your version), or a change-data-capture stream instead of polling, we drop the B-tree. The status index is harder, because status changes on every update. A partial index such as WHERE status IN ('CREATED', 'IN_TRANSIT') makes the index much smaller and faster to scan, but notice that it still references the status column, so status updates still cannot be HOT. The structural fix is to move the fast-changing columns, status, updated_at and location, into a narrow table such as shipment_state with its own small set of indexes. The 50-million-row shipment table with its many indexes is then rarely updated, and the updates hit a narrow table with one or two indexes.

SQL
-- Narrow table for the columns that change 5,000 times a second
CREATE TABLE shipment_state (
shipment_id bigint PRIMARY KEY REFERENCES shipment (id),
status text NOT NULL,
updated_at timestamptz NOT NULL
) WITH (fillfactor = 80);
CREATE INDEX shipment_state_active ON shipment_state (status) WHERE status IN ('CREATED', 'IN_TRANSIT');
UPDATE shipment_state SET status = 'DELIVERED', updated_at = now() WHERE shipment_id = 881234;
-- touches 1 heap page, the primary key is unchanged, and one small partial index
Before and after for one status update
BeforeAfter
indexes written9 (no HOT possible)1 small partial index
table updatedwide shipment rownarrow shipment_state row
full-page imagesheap + up to 9 index pagesheap + 1 index page
WAL per update (measured on a test copy)about 4.6 KBtarget well under 1 KB
The exact numbers must come from a test run with production-like data.

3Leaving Room on the Page

Even an update that changes no indexed column can only be HOT if the new version fits on the same page. A table loaded at the default fillfactor of 100 has full pages, so new versions move to other pages. Setting fillfactor to 80 or 90 leaves room on each page. The setting applies to pages written after the change, so for an existing table we rewrite it, preferably online with pg_repack. After the change, n_tup_newpage_upd in pg_stat_user_tables (PostgreSQL 16 and later) shows whether updates still have to leave their page.

4Reducing WAL at the Server Level

Several settings reduce WAL without schema changes. wal_compression compresses full-page images, which are most of our volume; besides the older pglz, PostgreSQL 15 and later support lz4 and zstd (check your version), often cutting page image size by half or more for little CPU. Checkpoints that happen less often mean fewer first touches of each page, so fewer full-page images: raising checkpoint_timeout from 5 to 15 or 30 minutes and max_wal_size accordingly can cut WAL substantially, at the cost of longer crash recovery.

Finally, the application can help. If a shipment receives several status events within a second, batching them so the row is updated once, or skipping updates that do not change anything, reduces the update count itself, which is the cheapest WAL of all.

SQL
ALTER SYSTEM SET wal_compression = 'lz4'; -- compresses full-page images
ALTER SYSTEM SET checkpoint_timeout = '15min'; -- fewer checkpoints, fewer page images
ALTER SYSTEM SET max_wal_size = '64GB'; -- so checkpoints are driven by time, not WAL size
SELECT pg_reload_conf();

5Working With the Owning Team

These changes touch the team's schema and queries, so we do not impose them. We bring the measurements: the HOT ratio, the WAL breakdown by relation and the cost of replica lag and backups. We propose changes in order of risk: server settings first, then dropping unused indexes, then fillfactor, then the narrow table, which needs code changes. Each step is tested on a production-sized copy, with the WAL rate per hour and the plans of the team's important queries compared before and after, so nobody's report silently becomes a sequential scan.

We agree a target with them, for example below 500 GB of WAL per day and replica lag under 5 seconds, and add WAL volume per table and the HOT ratio to their dashboard, so a new index that blocks HOT next year is visible within a day instead of at the next incident.

Step throughThe plan with the owning team
  1. MeasureHOT ratio, WAL by relation, replica lag
  2. Server settingswal_compression, checkpoint interval
  3. Drop unused indexeschecked on primary and replicas
  4. Fillfactor and rewriteonline with pg_repack
  5. Narrow state tablecode change, tested on a copy
  6. Dashboards and targetsWAL per table, HOT ratio, alerts

6 steps in order. Play them, or step through them one at a time.

6Follow-up questions

How does checkpoint frequency affect WAL volume?

After each checkpoint, the first change to every page writes a full 8 KB image of that page into the WAL, because full_page_writes protects against torn pages. With checkpoints every 5 minutes, a page updated regularly gets an image every 5 minutes; with checkpoints every 30 minutes, only every 30. For a workload that keeps touching the same pages, less frequent checkpoints therefore remove a large part of the WAL, at the cost of more WAL to replay and longer recovery after a crash.

Could we turn off full_page_writes to save WAL?

Only on storage that guarantees atomic 8 KB writes, which is rare and hard to prove. Without page images, a crash during a page write can leave a torn page that WAL replay cannot repair, so this is not a safe way to reduce WAL.

Why does the WAL volume cause replica lag?

Every replica must receive and replay all WAL. Replay is mostly single-threaded per standby, so at 2 TB a day, about 23 MB per second, a standby can fall behind during peaks, and network bandwidth to remote replicas and archive storage costs grow with it.

7Conclusion

In this answer, we saw that 2 TB of WAL a day is about 4.6 KB per update, caused by indexes on status and updated_at that make every update non-HOT and force writes into all 9 indexes, plus full-page images. We fix it by dropping unused indexes, replacing the updated_at index, moving fast-changing columns into a narrow table (a partial index alone still blocks HOT), lowering fillfactor, and reducing WAL with lz4 or zstd compression, longer checkpoint intervals and batched updates, all agreed with the owning team on measured before and after results and tracked on dashboards.

What to say in the interviewAbout 100 seconds aloud

Open with

I would start with the arithmetic and the statistics. 5,000 updates a second is 432 million a day, so 2 TB of WAL is about 4.6 KB per update for a change of a few bytes.

Then, if they want more

In pg_stat_user_tables I expect n_tup_hot_upd to be almost zero, because HOT requires that no indexed column changes, and every update changes status and sets updated_at, both indexed. So each update writes a new entry into all nine indexes, and each newly touched index page adds a full 8 KB page image after a checkpoint. pg_walinspect would confirm the breakdown.

The fixes, in order of risk: enable wal_compression with lz4 or zstd and lengthen checkpoint_timeout with a larger max_wal_size, which reduces page images; drop indexes with no scans in pg_stat_user_indexes; replace the updated_at B-tree with a BRIN index or a CDC stream; lower fillfactor to 80 or 90 and rewrite the table with pg_repack.

A partial index on active statuses makes that index smaller, but it still references status, so status updates still are not HOT; the real structural fix is to move status and updated_at into a narrow shipment_state table with one small index, so the wide table is rarely updated.

I would also ask the team whether repeated status events can be batched. I would bring this to the owning team as measurements, test every step on a production-sized copy comparing WAL per hour and their query plans, agree a target, and add WAL per table and the HOT ratio to their dashboards.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 16, PostgreSQL 15
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A PostgreSQL table of 50 million shipment rows gets 5,000 status updates per second. WAL...": https://scrivio-interview-library.netlify.app/databases/storage-internals/dc0556fd99/