Problem Statement
Why are long-running transactions harmful in MVCC systems, and how do you mitigate the damage?
Explanation
Long transactions hold snapshots open. The engine must keep old row versions and cannot reclaim space or freeze visibility easily. This increases table and index bloat and slows vacuum or purge cycles. It can also block truncation and keep conflict fields hot.
Mitigate by breaking work into smaller commits, moving pure reads to a replica, and avoiding idle-in-transaction connections. Schedule vacuum or maintenance windows and monitor age metrics to intervene before wraparound risks.
Code Solution
SolutionRead Only
SET idle_in_transaction_session_timeout = '5min';
Practice Sets
This question appears in the following practice sets:
