The Nightly Report Is Slow. Just Run It in One Big Transaction?
A nightly report holds one Postgres transaction open for hours and writes are bloating. A teammate wants a bigger box and higher timeouts. Defend the real fix.
Answer key reviewed by Branko Petric
Read first: AWS Databases: RDS and DynamoDB
Your decision
A nightly analytics job holds one long-running Postgres transaction open for hours, and now writes are bloating and autovacuum can't keep up. A teammate says just give the DB more resources and raise timeouts so the long transaction can finish. What do you do, and why?
The situation
A nightly reporting job runs inside a single transaction that stays open for hours, and lately production sees growing table bloat and lock contention. During the day, previously fast OLTP queries are getting slower, indexes are ballooning, and autovacuum seems to be running constantly without ever catching up.
Context
The report is a big analytics query wrapped in one BEGIN that is not committed until the whole thing finishes, hours later, on the primary database. A teammate proposes bumping the instance size and increasing statement and idle-in-transaction timeouts so the transaction is allowed to run to completion without being killed.
Related challenges
- Add a NOT NULL Column to a 50M-Row Prod Table
A migration adds a NOT NULL column to a huge live table. A teammate wants to run the ALTER directly. Defend the safe path.
- Failover Lost 5 Minutes of Writes. Promise Zero Data Loss?
An async-replica failover dropped five minutes of committed writes. Leadership demands zero data loss with zero performance impact. Defend the honest trade-off.
- Nightly Backups Run. Are You Actually Covered?
Automated backups have run for months. A teammate says you are fully covered for disasters. Defend whether you agree.
- Your Primary Region Is Down. Fail Over Now?
The primary region is degraded. A teammate wants to flip DNS to the standby immediately. Defend whether and how you fail over.
More: Database scenario interview questions for DevOps and SRE