Skip to content
Ameen Abozaid
Planned lessonMID-014-L05

Demo: an idle transaction blocking vacuum

  • Lesson 5 of 5
  • Mid-level
On This Lesson 3 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

create bloat with an idle transaction and fix it.

Draft outline details

Step by step

  1. Create a hot table stock_log and a loop that updates rows continuously; show baseline size and n_dead_tup.
  2. In another session run BEGIN; SELECT count(*) FROM stock_log; and leave it open.
  3. Run VACUUM (VERBOSE) stock_log; it reports dead rows "not yet removable".
  4. Planned mistake: disable autovacuum to "fix" growth; bloat gets worse. Fix: re-enable it.
  5. Terminate the idle session (or set idle_in_transaction_session_timeout) and vacuum again; dead tuples drop.
  6. Note table size stays large (reusable space, not returned to the OS).

Prepares MID-014-LAB1.

Check your understanding

Which message in VACUUM VERBOSE reveals the culprit?

Show answer

Dead row versions "not yet removable" because of an old transaction.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.