Skip to content
RED SAGSkills
mediumDatabase Administrator interview question

A query that ran in 50 ms yesterday now takes 20 seconds. Nothing in the code changed. How do you investigate?

What the interviewer wants to hear

  • Check if it is blocked by locks or the server is overloaded
  • Compare the current execution plan with the old one
  • Look for stale or changed statistics and run ANALYZE
  • Check data growth, bloat or a dropped index
  • Consider parameter-sensitive plans

Model answer

First I check whether the query itself is slow or just waiting. I look at pg_stat_activity or SHOW PROCESSLIST for lock waits, and at CPU and disk IO in monitoring. If it is not blocked, I run EXPLAIN ANALYZE and compare with the old plan if we store plans, for example with auto_explain. A sudden change usually means the planner picked a different plan. Common reasons are stale statistics after a big data load, so I run ANALYZE; an index that was dropped or became invalid; table bloat; or data that grew past a point where the planner switches to a sequential scan or a different join type. I also check for parameter-sensitive plans, where a generic prepared statement plan is bad for some values. Then I fix the root cause and add monitoring for it.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Database Administrator questions