grafclouds.com / documents / insights / training / devops-challenges / postgres-long-running-transaction

The Nightly Report Is Slow. Just Run It in One Big Transaction?

Advanced ~13 min read
Databases

Scenario

Every night an analytics job runs against the Postgres primary, and it wraps hours of reads and aggregations in a single long transaction. The consequences show up in daylight: tables and indexes keep growing, autovacuum runs but can't reclaim space, OLTP queries during business hours slow down, and occasionally something blocks on a lock the report is holding. The job frequently overruns into the morning, so "nightly" is increasingly a courtesy title.

The proposal on the table works with the design instead of against it: give the database bigger hardware, and raise the statement and idle-transaction timeouts so the report can always run to completion without being killed. The transaction stays; the environment adapts around it.

The Quick Fix on the Table

Scale the instance up and lift the timeouts so nothing interrupts the big transaction. No changes to the report code, and the overnight failures from timeout kills stop immediately.

Interview · Round 1

The quick fix is on the table and the room is waiting for your call. Would you sign off on it? Take a position and justify it — out loud or on paper — before revealing the analysis.