Waiting for PostgreSQL 18 – Add delay time to VACUUM/ANALYZE (VERBOSE) and autovacuum logs.

On 14th of February 2025, Nathan Bossart committed patch:

Add delay time to VACUUM/ANALYZE (VERBOSE) and autovacuum logs.
 
Commit bb8dff9995 added this information to the
pg_stat_progress_vacuum and pg_stat_progress_analyze system views.
This commit adds the same information to the output of VACUUM and
ANALYZE with the VERBOSE option and to the autovacuum logs.
 
Suggested-by: Masahiro Ikeda <ikedamsh@oss.nttdata.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/ZmaXmWDL829fzAVX%40ip-10-97-1-34.eu-west-3.compute.internal

Just couple of days ago I wrote that now we will have delay information in view showing progress of vacuums, where I wrote:

Kinda makes me wish this value was also logged (at the end of vacuum) to pg logs…

and now – we got it!

Ran two tests, similar setup (though size of table was only 10% of previously used), and then, in first case ran vacuum manually:

  1. =$ vacuum verbose test_it;
  2. INFO:  vacuuming "depesz.public.test_it"
  3. INFO:  finished vacuuming "depesz.public.test_it": index scans: 1
  4. pages: 0 removed, 12736 remain, 12736 scanned (100.00% of total), 0 eagerly scanned
  5. tuples: 750324 removed, 249676 remain, 0 are dead but not yet removable
  6. removable cutoff: 2159, which was 0 XIDs old when operation ended
  7. frozen: 0 pages from table (0.00% of total) had 0 tuples frozen
  8. visibility map: 12706 pages set all-visible, 799 pages set all-frozen (0 were all-visible)
  9. index scan needed: 12698 pages from table (99.70% of total) had 750324 dead item identifiers removed
  10. index "test_it_pkey": pages: 2745 in total, 0 newly deleted, 0 currently deleted, 0 reusable
  11. delay time: 2493.787 ms
  12. I/O timings: read: 8.274 ms, write: 11.363 ms
  13. avg read rate: 7.771 MB/s, avg write rate: 7.760 MB/s
  14. buffer usage: 38215 hits, 2752 reads, 2748 dirtied
  15. WAL usage: 40843 records, 7 full page images, 6766991 bytes, 0 buffers full
  16. system usage: CPU: user: 0.17 s, system: 0.02 s, elapsed: 2.76 s
  17. INFO:  vacuuming "depesz.pg_toast.pg_toast_798487"
  18. INFO:  finished vacuuming "depesz.pg_toast.pg_toast_798487": index scans: 0
  19. pages: 0 removed, 0 remain, 0 scanned (100.00% of total), 0 eagerly scanned
  20. tuples: 0 removed, 0 remain, 0 are dead but not yet removable
  21. removable cutoff: 2159, which was 0 XIDs old when operation ended
  22. new relfrozenxid: 2159, which is 3 XIDs ahead of previous value
  23. frozen: 0 pages from table (100.00% of total) had 0 tuples frozen
  24. visibility map: 0 pages set all-visible, 0 pages set all-frozen (0 were all-visible)
  25. index scan not needed: 0 pages from table (100.00% of total) had 0 dead item identifiers removed
  26. delay time: 5.580 ms
  27. I/O timings: read: 0.031 ms, write: 0.000 ms
  28. avg read rate: 1.351 MB/s, avg write rate: 0.000 MB/s
  29. buffer usage: 25 hits, 1 reads, 0 dirtied
  30. WAL usage: 1 records, 0 full page images, 254 bytes, 0 buffers full
  31. system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  32. VACUUM

Please check line 26 above – delay time: 5.580ms 🙂

Then I redid the setup, and left it so autovacuum will pick it.

To make sure that I will get it logged, made sure to have log_autovacuum_min_duration set to 0. After some time, in logs, I got this:

  1. 2025-02-19 12:32:04.690 CET @ 379450  LOG:  automatic vacuum of table "depesz.public.test_it": index scans: 1
  2.         pages: 0 removed, 115008 remain, 115008 scanned (100.00% of total), 0 eagerly scanned
  3.         tuples: 7500218 removed, 2499782 remain, 0 are dead but not yet removable
  4.         removable cutoff: 2175, which was 0 XIDs old when operation ended
  5.         frozen: 114185 pages from table (99.28% of total) had 2499726 tuples frozen
  6.         visibility map: 114976 pages set all-visible, 114962 pages set all-frozen (0 were all-visible)
  7.         index scan needed: 114962 pages from table (99.96% of total) had 7500218 dead item identifiers removed
  8.         index "test_it_pkey": pages: 27422 in total, 0 newly deleted, 0 currently deleted, 0 reusable
  9.         delay time: 57002.466 ms
  10.         I/O timings: read: 384.980 ms, write: 1032.635 ms
  11.         avg read rate: 27.745 MB/s, avg write rate: 30.244 MB/s
  12.         buffer usage: 146632 hits, 225888 reads, 246238 dirtied
  13.         WAL usage: 487219 records, 223217 full page images, 1224286719 bytes, 11605 buffers full
  14.         system usage: CPU: user: 3.74 s, system: 2.41 s, elapsed: 63.60 s

This time, line 9: delay time: 57002.466 ms.

This is absolutely awesome. Thanks a lot to everyone involved.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.