postgres.git / summary / log / commit / refs
commit 5fd77f6bb60b1906ef23676d3e443701c32940b0
Author: Masahiko Sawada <msawada@postgresql.org>
Date: Thu Sep 24 17:31:53 2026 +0000
First released in: 19.0
Don't fully empty GIN pending list in parallel autovacuum workers.
Autovacuum doesn't necessarily fully empty the GIN pending list. It
stops at the tail as of the start of cleanup, so that it doesn't keep
chasing pages appended by concurrent inserters. GIN decided this with
AmAutoVacuumWorkerProcess(), which returns false in parallel vacuum
workers launched by an autovacuum worker, so those workers tried to
fully empty the list as a manual VACUUM does.
Fix this by adding an is_autovacuum field to IndexVacuumInfo, set from
the shared parallel vacuum state in parallel workers, and using it in
GIN instead of checking the process type.
Oversight in commit 1ff3180ca01.
Reported-by: Jingtang Zhang <mrdrivingduck@gmail.com>
Author: Jingtang Zhang <mrdrivingduck@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Yuhang Qiu <iamqyh@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/CAPsk3_DiF2i1o=JRXRk1YPVMv1VzJaCAbfiEqgwCva4=ZewVAw@mail.gmail.com
Backpatch-through: 19
src/backend/access/gin/ginvacuum.c | 12 ++++++------
src/backend/access/heap/vacuumlazy.c | 2 ++
src/backend/catalog/index.c | 1 +
src/backend/commands/analyze.c | 1 +
src/backend/commands/vacuumparallel.c | 1 +
src/include/access/genam.h | 1 +
src/include/miscadmin.h | 1 +
7 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/backend/access/gin/ginvacuum.c b/src/backend/access/gin/ginvacuum.c
index 2cd4e50aa61..2955553f368 100644
--- a/src/backend/access/gin/ginvacuum.c
+++ b/src/backend/access/gin/ginvacuum.c
@@ -659,11 +659,11 @@ ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
* us to remove from the index. We must force cleanup of the pending list
* now, before vacuuming proper begins, to make sure nothing is missed.
*
- * When running in an autovacuum worker, we won't necessarily _fully_
- * empty the pending list. This is still safe; concurrent inserters
- * cannot insert new tuples whose TIDs VACUUM needs us to remove.
+ * When called by autovacuum, we won't necessarily _fully_ empty the
+ * pending list. This is still safe; concurrent inserters cannot insert
+ * new tuples whose TIDs VACUUM needs us to remove.
*/
- ginInsertCleanup(&gvs.ginstate, !AmAutoVacuumWorkerProcess(),
+ ginInsertCleanup(&gvs.ginstate, !info->is_autovacuum,
false, true, stats);
/* we'll re-count the tuples each time */
@@ -775,7 +775,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
*/
if (info->analyze_only)
{
- if (AmAutoVacuumWorkerProcess())
+ if (info->is_autovacuum)
{
initGinState(&ginstate, index);
ginInsertCleanup(&ginstate, false, true, true, stats);
@@ -791,7 +791,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
{
stats = palloc0_object(IndexBulkDeleteResult);
initGinState(&ginstate, index);
- ginInsertCleanup(&ginstate, !AmAutoVacuumWorkerProcess(),
+ ginInsertCleanup(&ginstate, !info->is_autovacuum,
false, true, stats);
}
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 25483651fa1..ed7301c69ec 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -3043,6 +3043,7 @@ lazy_vacuum_one_index(Relation indrel, IndexBulkDeleteResult *istat,
ivinfo.index = indrel;
ivinfo.heaprel = vacrel->rel;
ivinfo.analyze_only = false;
+ ivinfo.is_autovacuum = AmAutoVacuumWorkerProcess();
ivinfo.report_progress = false;
ivinfo.estimated_count = true;
ivinfo.message_level = DEBUG2;
@@ -3093,6 +3094,7 @@ lazy_cleanup_one_index(Relation indrel, IndexBulkDeleteResult *istat,
ivinfo.index = indrel;
ivinfo.heaprel = vacrel->rel;
ivinfo.analyze_only = false;
+ ivinfo.is_autovacuum = AmAutoVacuumWorkerProcess();
ivinfo.report_progress = false;
ivinfo.estimated_count = estimated_count;
ivinfo.message_level = DEBUG2;
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 07f8749be79..32fb6c217f5 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -3528,6 +3528,7 @@ validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
ivinfo.index = indexRelation;
ivinfo.heaprel = heapRelation;
ivinfo.analyze_only = false;
+ ivinfo.is_autovacuum = false;
ivinfo.report_progress = true;
ivinfo.estimated_count = true;
ivinfo.message_level = DEBUG2;
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index c4fb2677207..4853877fac9 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -727,6 +727,7 @@ do_analyze_rel(Relation onerel, const VacuumParams *params,
ivinfo.index = Irel[ind];
ivinfo.heaprel = onerel;
ivinfo.analyze_only = true;
+ ivinfo.is_autovacuum = AmAutoVacuumWorkerProcess();
ivinfo.estimated_count = true;
ivinfo.message_level = elevel;
ivinfo.num_heap_tuples = onerel->rd_rel->reltuples;
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index 767d162e578..4532da60c84 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -1087,6 +1087,7 @@ parallel_vacuum_process_one_index(ParallelVacuumState *pvs, Relation indrel,
ivinfo.index = indrel;
ivinfo.heaprel = pvs->heaprel;
ivinfo.analyze_only = false;
+ ivinfo.is_autovacuum = pvs->shared->is_autovacuum;
ivinfo.report_progress = false;
ivinfo.message_level = DEBUG2;
ivinfo.estimated_count = pvs->shared->estimated_count;
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68bfe405db3..3e33c1d4ae4 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -54,6 +54,7 @@ typedef struct IndexVacuumInfo
Relation index; /* the index being vacuumed */
Relation heaprel; /* the heap relation the index belongs to */
bool analyze_only; /* ANALYZE (without any actual vacuum) */
+ bool is_autovacuum; /* VACUUM/ANALYZE initiated by autovacuum */
bool report_progress; /* emit progress.h status reports */
bool estimated_count; /* num_heap_tuples is an estimate */
int message_level; /* ereport level for progress messages */
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 11a7d2f1542..09503a5d5fa 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -383,6 +383,7 @@ extern PGDLLIMPORT BackendType MyBackendType;
#define AmRegularBackendProcess() (MyBackendType == B_BACKEND)
#define AmAutoVacuumLauncherProcess() (MyBackendType == B_AUTOVAC_LAUNCHER)
+/* Parallel workers launched by autovacuum return false here. */
#define AmAutoVacuumWorkerProcess() (MyBackendType == B_AUTOVAC_WORKER)
#define AmBackgroundWorkerProcess() (MyBackendType == B_BG_WORKER)
#define AmWalSenderProcess() (MyBackendType == B_WAL_SENDER)
[parent: 9ac2cb07b44f]