Sample Header Ad - 728x90

Why vacuum analyze takes much time in an empty table?

0 votes
0 answers
86 views
I have a table in my database that used to have data long time ago, but now data have been deleted and is empty and no new data are inserted on it. Once a day I run vacuum analyze for several tables and for this specific one I noticed that it takes much time. Below is the verbose output 2024-10-03 07:12:22,217 INFO Vacuum/Analyze output: [INFO: vacuuming "public.activity_by_cgi_rat" INFO: index "activity_sec_by_cgi_rat_pk" now contains 0 row versions in 10940559 pages DETAIL: 0 index row versions were removed. 10940553 index pages have been deleted, 10940553 are currently reusable. CPU: user: 18.87 s, system: 52.19 s, elapsed: 2627.28 s. INFO: "activity_by_cgi_rat": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 1176039973 There were 0 unused item identifiers. Skipped 0 pages due to buffer pins, 0 frozen pages. 0 pages are entirely empty. CPU: user: 18.87 s, system: 52.19 s, elapsed: 2627.28 s. INFO: vacuuming "pg_toast.pg_toast_21943" INFO: index "pg_toast_21943_index" now contains 0 row versions in 1 pages DETAIL: 0 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.03 s. INFO: "pg_toast_21943": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 1176065166 There were 0 unused item identifiers. Skipped 0 pages due to buffer pins, 0 frozen pages. 0 pages are entirely empty. CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.06 s. INFO: analyzing "public.activity_by_cgi_rat" INFO: "activity_by_cgi_rat": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows ] 2024-10-03 07:12:22,218 INFO msgtype=PERF component=analytics.rdb operation=db_expire.vacuum_db_table elapsed_sec=2627.60 db_table=activity_by_cgi_rat Almost 1h for an empty is much time isn't it? Why is this happening? I notice this line in the verbose output: INFO: index "activity_sec_by_cgi_rat_pk" now contains 0 row versions in 10940559 pages which looks suspicious: Why in an empty table so much pages? --- EDIT --- I read in docs the following: In PostgreSQL 7.4 and later, index pages that have become completely empty are reclaimed for re-use. There is still a possibility for inefficient use of space: if all but a few index keys on a page have been deleted, the page remains allocated. So a usage pattern in which all but a few keys in each range are eventually deleted will see poor use of space. For such usage patterns, periodic reindexing is recommended. Is it possible that I have to reindex the table?
Asked by leas (109 rep)
Oct 4, 2024, 07:38 AM
Last activity: Oct 4, 2024, 08:40 AM