Problem Statement
What are the risks of long-running transactions and how do you mitigate them?
Explanation
They hold locks and versions for a long time, increasing contention and bloat. In MVCC, old versions cannot be reclaimed, which inflates storage and slows scans. Checkpoint and log retention also grow.
Mitigate by committing in smaller units, breaking work into batches, and using snapshot reads for reporting. Keep interactive transactions short and avoid idle-in-transaction sessions.
Code Solution
SolutionRead Only
-- Batch pattern DELETE FROM events WHERE created_at < :cutoff LIMIT 10000; COMMIT; -- loop
Practice Sets
This question appears in the following practice sets:
