Quick revision
The short answer
I would turn bloat handling from per-team firefighting into a platform program with five parts: central monitoring and alerts for bloat, dead tuples, autovacuum lag, transaction id age and long transactions; standard autovacuum defaults for hot tables with documented overrides; runbooks and automation for REINDEX CONCURRENTLY and pg_repack in low-traffic windows, rate limited to protect replicas; guardrails such as idle_in_transaction_session_timeout and slot alerts; and tracking of incidents and disk use to prove it works and to fix the design patterns that keep producing bloat.
What to remember
In this answer, we designed a maintenance program for 150 PostgreSQL clusters. Central monitoring tracks bloat, dead tuples, autovacuum lag, transaction id age, long transactions and slots, with alerts per cluster. Standard autovacuum defaults for hot tables are shipped with documented overrides. Automation runs REINDEX CONCURRENTLY and pg_repack in low-traffic windows, rate limited to protect replicas. Guardrails such as idle_in_transaction_session_timeout and slot alerts remove common causes, and we track incidents and disk use to show the program works and to fix design patterns that keep producing bloat.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would turn bloat handling from per-team firefighting into a platform program with five parts: central monitoring and alerts for bloat, dead tuples, autovacuum lag, transaction id age and long transactions; standard autovacuum defaults for hot tables with documented overrides; runbooks and automation for REINDEX CONCURRENTLY and pg_repack in low-traffic windows, rate limited to protect replicas; guardrails such as idle_in_transaction_session_timeout and slot alerts; and tracking of incidents and disk use to prove it works and to fix the design patterns that keep producing bloat.
Why this question is asked
Monthly bloat incidents across 150 clusters are a sign that the knowledge exists but is not shared. Each team rediscovers the same causes, fixes them under pressure and moves on, and the next team meets the same problem a month later. Interviewers ask this leadership question to see whether we can design a program that prevents incidents rather than just handling them faster. In this answer, we will look at where bloat incidents really come from, then build the monitoring, the defaults, the automation, the guardrails and the measurement, and describe how to roll it out without slowing teams.
1Where Bloat Incidents Come From
Bloat in PostgreSQL comes from dead row versions and dead index entries that vacuum has not removed, or that left space vacuum could not give back. Incidents follow a few repeating patterns: autovacuum settings too lazy for a hot table, a long-running or idle-in-transaction session holding back the xmin horizon (the oldest snapshot that vacuum must respect), a replication slot or a replica with hot_standby_feedback doing the same, and design patterns such as queue tables and frequently updated indexed columns. The visible symptoms are slow queries and disks filling up. A related danger is transaction id wraparound: if vacuum cannot freeze old rows, PostgreSQL eventually forces emergency vacuums and, in the worst case, stops accepting writes.
Because the causes repeat, a central program can address them once for all clusters.
2Central Monitoring and Alerts
Every cluster reports the same metrics to one place: estimated table and index bloat, dead tuples per table, time since the last autovacuum on large tables, autovacuum workers busy, the age of the oldest transaction id per database (age(datfrozenxid)), the oldest running transaction, and replication slots with their retained WAL. Alerts are per cluster and routed to the owning team, with thresholds that catch a problem days before it becomes an incident, for example a transaction older than 30 minutes, or transaction id age above 500 million.
Dashboards show the same views everywhere, so an engineer who moves between teams already knows where to look.
- Measureincidents, disk growth, bloat trends per cluster
- Monitor and alertbloat, dead tuples, vacuum lag, xid age, long transactions, slots
- Guardrailstimeouts, slot alerts, replica feedback limits
- AutomationREINDEX CONCURRENTLY and pg_repack in windows, rate limited
- Standard defaultsautovacuum settings for hot tables, documented overrides
5 layers, from the top down. Step through them one at a time.
Each layer reduces the work left for the one above it.
3Standard Autovacuum Defaults
PostgreSQL's default autovacuum settings suit modest tables, not hot ones with hundreds of millions of rows. We ship a standard configuration through the platform: cluster-wide values for workers and cost limits sized for modern storage, and a documented profile for hot tables, applied per table through migrations.
The values are starting points that we revisit with data. Teams can override them for a specific table, but the override goes into the migration with a comment that says why, so the next person can understand it.
4Runbooks and Automation for Rebuilds
When bloat does build up, the fix should be a routine job, not a late-night improvisation. The platform provides a tool that finds indexes and tables above a bloat threshold, schedules REINDEX CONCURRENTLY for indexes and pg_repack for tables in each cluster's low-traffic window, runs one at a time, pauses if replica lag passes a limit, checks free disk space for the second copy first, and cleans up invalid indexes left by a failed build. Runbooks cover the manual cases, such as an emergency on a disk that is nearly full, step by step.
Rate limiting matters. A rebuild generates as much WAL as writing the index from scratch, and on 150 clusters, uncontrolled rebuilds would create the replica lag and I/O problems we are trying to prevent.
5Guardrails Against the Causes
The cheapest incident is the one that cannot start. We set idle_in_transaction_session_timeout for application roles, so a forgotten transaction is ended after a minute or so, and statement_timeout to bound runaway queries. We alert on replication slots whose consumers are gone, because an abandoned slot retains WAL and holds back cleanup until the disk fills. For replicas used for long reports, we either turn off hot_standby_feedback and accept cancellations, or move those reports to a separate replica or warehouse.
6Measuring and Improving the Design
We track the number of bloat-related incidents per month, disk usage growth, and bloat percentages across clusters, and report them to engineering leadership. If incidents drop from monthly to rare, the program has paid for itself. We also look for repeating sources: queue tables that should be partitioned, hot columns that should not be indexed, services with long transactions. Those become design guidance and review points for new schemas, which prevents the next generation of incidents.
- Inventory 150 clustersversions, settings, top bloat
- Ship monitoring firstvisibility before changes
- Apply guardrails and defaultsin waves, with team owners
- Enable automated rebuildsstart with low-risk clusters
- Review incidents monthlyupdate defaults and design guidance
5 steps in order. Play them, or step through them one at a time.
7Follow-up questions
How do you avoid the platform team becoming a bottleneck?
By providing defaults, tools and data, not approvals. Teams keep owning their schemas and decide overrides in their own migrations. The platform ships the standard settings, the monitoring, the rebuild tool and the runbooks, and is consulted for unusual cases. Most improvements then happen without anyone waiting on the platform team.
What would you alert on first if you could pick only one metric?
The age of the oldest open transaction, including idle-in-transaction sessions and replica feedback. It is the single most common reason vacuum stops working, it causes both bloat and wraparound risk, and it is easy to fix once seen.
8Conclusion
In this answer, we designed a maintenance program for 150 PostgreSQL clusters. Central monitoring tracks bloat, dead tuples, autovacuum lag, transaction id age, long transactions and slots, with alerts per cluster. Standard autovacuum defaults for hot tables are shipped with documented overrides. Automation runs REINDEX CONCURRENTLY and pg_repack in low-traffic windows, rate limited to protect replicas. Guardrails such as idle_in_transaction_session_timeout and slot alerts remove common causes, and we track incidents and disk use to show the program works and to fix design patterns that keep producing bloat.
Open with
I would treat this as a platform program rather than leaving each team to firefight. First, monitoring the same way on every cluster: table and index bloat estimates, dead tuples, time since last autovacuum, transaction id age, the oldest running transaction, and replication slots, with alerts per cluster routed to the owning team well before things break.
Then, if they want more
Second, standard autovacuum settings: cluster defaults sized for current hardware, and a hot-table profile with lower scale factors that teams apply in their migrations, with overrides documented.
Third, automation for the cleanup itself: a tool that finds bloated indexes and tables and runs REINDEX CONCURRENTLY or pg_repack in each cluster's quiet window, one at a time, checks disk space, pauses on replica lag and removes invalid indexes after failures, plus runbooks for emergencies.
Fourth, guardrails against the root causes: idle_in_transaction_session_timeout and statement timeouts for application roles, alerts on inactive replication slots, and care with hot_standby_feedback on reporting replicas.
Fifth, measurement: incidents per month, disk growth and bloat trends, reported to leadership, and a regular look at the design patterns, like queue tables or indexed hot columns, that keep causing bloat, so they become review guidance for new schemas. Teams keep ownership; the platform provides defaults and tools, so nobody waits on us.
About this answer
- Last updated
- 12 November 2026
- 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.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
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 "Your team runs 150 PostgreSQL clusters. Bloat-related incidents (slow queries, disk...": https://scrivio-interview-library.netlify.app/databases/indexing/994e27d3af/