I manage a big (some hundreds of gigs) database containing tables with various roles, some of them holding millions of records. Some tables only receive large number of inserts and deletes, some other few inserts and large number of updates.
Database runs on PostgreSQL 8.4 on a Debian 6.0 amd64 system with 16 gigabytes of RAM.
The question is sometimes autovacuum process on a table, takes a very long time (days) to complete. I want to be able to roughly tell how much time a particular vacuum command will take, to be able to decide whether to cancel it or not. Also if there were a progress indicator for postgres vacuum operations, it would be really helpful.
Edit:
I'm not looking for a bullet-proof solution. Just a rough hint on the number of dead tuples or necessary I/O bytes is enough to decide. It is really annoying to have no clue when VACUUM will finish, whatsoever.
I've seen that pg_catalog.pg_stat_all_tables has a column for number of dead tuples. So it is possible to have an estimation, even if it means one has to ANALYZE the table before. On the other hand, autovacuum_vacuum_threshold and autovacuum_vacuum_scale_factor settings alone prove that postgres itself knows something about the amount of change on the tables and probably puts it in the hands of the DBA too.
I'm not sure what query to run, because when I run VACUUM VERBOSE, I see that not only tables, but indexes on them are being processed too.
VACUUM FULLon 9.0+, as it completely rewrites the table. It should work for regularVACUUM, too, but I haven't tested it yet. Forautovacuumit would work if You were able to catch the autovacuum worker process on given table, but I don't know how to achieve this. – Roman Hocke Mar 06 '17 at 10:05VACCUM ANALYSE VERBOSE bigtable, which has been running for 5.5 hours now. What I see in pg_total_relation_size() is 718GB for bigtable, butwhile true; do cat /proc/123/io | grep read_bytes; sleep 60;on theVACCUMpid shows 2256301645824 bytes read so far (over 2TB!). What am I missing? How do I estimate the remaining time for this long-runningVACCUM? – 100grams Feb 20 '20 at 10:33while true; do echo "$(sudo cat /proc/1234/io | grep read_bytes | tr -dc '0-9') * 100 / 50000000" | bc; sleep 30; donewhere50000000is the amount of bytes formSELECT pg_total_relation_size('table_name');– adriaan Oct 06 '20 at 21:46select * from pg_stat_progress_clusterto look up the progress ofVACUUM FULL. Source: https://severalnines.com/database-blog/progress-reporting-enhancements-postgresql-12 and https://www.postgresql.org/docs/current/progress-reporting.html – Gili Jun 03 '22 at 03:21