All jobs / Database administrator / Performance
Database administrator interview question · 1–3 years
The sessions belong to a reporting service that opens a transaction, then waits for a slow external API.
Several sessions sit “idle in transaction” for hours. Why does that matter and what do you do?
The strongest answer
They hold locks and stop clean-up of old row versions, so tables bloat and others block; I find the code path that opens a transaction and then waits, and set an idle-in-transaction timeout
Why it works
Exactly — an open transaction is a lock holder and a vacuum blocker even when it is doing nothing.
What a good answer covers
- Idle transactions hold locks.
- They block old-version clean-up.
- Find the code path.
- Set an idle-in-transaction timeout.
Answers that fall short
- Close, but not the strongest: It wastes a connection each, so I would raise the connection limit
Wasted connections are the smallest of the problems. - Weak: It is harmless as long as they eventually commit
Hours of held locks and blocked clean-up are not harmless. - Red flag: I kill them every morning with a scheduled job
A daily kill job hides a code bug and drops whatever the transaction had done.
Who gets asked this
More Performance questions
- A query that ran in milliseconds now takes minutes, right after a large data load. First suspect?
- The database shows thousands of identical tiny queries per page load. What is happening and what do you…
- What is a covering index and when is it worth it?
- Hundreds of application pods each keep a pool of twenty connections. The database is out of connections. Fix?
- The same parameterised query is fast for most customers and terribly slow for one large customer. What is…
- The plan cache is full of thousands of near-identical statements that differ only by literal values. Impact…
- A nightly job updating a few million rows locks the entire table and blocks the application. Why, and what do…
- One row holding a global counter is updated by every request and has become the bottleneck. Options?