aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/heap
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2020-02-19 20:37:26 +0900
committerFujii Masao <fujii@postgresql.org>2020-02-19 20:38:38 +0900
commit16e6c968be64db82a9680961e2e69d38cdfbd408 (patch)
treef4db6009fd85ecfe307b167b596e1251d3f4e47a /src/backend/access/heap
parent59112f235549171dfc8418edf5184c104e14610c (diff)
downloadpostgresql-16e6c968be64db82a9680961e2e69d38cdfbd408.tar.gz
postgresql-16e6c968be64db82a9680961e2e69d38cdfbd408.zip
Fix mesurement of elapsed time during truncating heap in VACUUM.
VACUUM may truncate heap in several batches. The activity report is logged for each batch, and contains the number of pages in the table before and after the truncation, and also the elapsed time during the truncation. Previously the elapsed time reported in each batch was the total elapsed time since starting the truncation until finishing each batch. For example, if the truncation was processed dividing into three batches, the second batch reported the accumulated time elapsed during both first and second batches. This is strange and confusing because the number of pages in the table reported together is not total. Instead, each batch should report the time elapsed during only that batch. The cause of this issue was that the resource usage snapshot was initialized only at the beginning of the truncation and was never reset later. This commit fixes the issue by changing VACUUM so that the resource usage snapshot is reset at each batch. Back-patch to all supported branches. Reported-by: Tatsuhito Kasahara Author: Tatsuhito Kasahara Reviewed-by: Masahiko Sawada, Fujii Masao Discussion: https://postgr.es/m/CAP0=ZVJsf=NvQuy+QXQZ7B=ZVLoDV_JzsVC1FRsF1G18i3zMGg@mail.gmail.com
Diffstat (limited to 'src/backend/access/heap')
-rw-r--r--src/backend/access/heap/vacuumlazy.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index a3c4a1df3b4..8acb8b8eb69 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -1874,11 +1874,8 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
{
BlockNumber old_rel_pages = vacrelstats->rel_pages;
BlockNumber new_rel_pages;
- PGRUsage ru0;
int lock_retry;
- pg_rusage_init(&ru0);
-
/* Report that we are now truncating */
pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
PROGRESS_VACUUM_PHASE_TRUNCATE);
@@ -1888,6 +1885,10 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
*/
do
{
+ PGRUsage ru0;
+
+ pg_rusage_init(&ru0);
+
/*
* We need full exclusive lock on the relation in order to do
* truncation. If we can't get it, give up rather than waiting --- we