Advanced·Scenario·2 min read

PostgreSQL CPU becomes very high. What do I check?

Practice this question

Short explanation:

High PostgreSQL CPU means the database is spending substantial time processing work rather than simply waiting for requests. Causes include expensive queries, poor plans, repeated query volume or maintenance work. CPU alone does not tell you whether an index, query rewrite or traffic reduction is the right fix.

Key points:

  • Find active and expensive queries; check traffic and changed query plans.

  • Inspect scan counts, joins, sorts, estimates and missing indexes.

  • Reduce unnecessary work and retest; adding connections may make CPU pressure worse.

  • Identify top total-cost queries, not just the single slowest execution; a cheap query called millions of times can dominate.

  • Compare row estimates and actual work using a safe representative query, then refresh statistics or change access patterns where evidence supports it.

Interview point:

  • Explain how you would reduce database work and verify no required result or data rule changed.
Adapted from 08_PERFORMANCE_SECURITY.md · “2. PostgreSQL CPU becomes very high. What do I check?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.