diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index cd82c04..9d4f469 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -6578,6 +6578,21 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; + + vacuum_cleanup_index_scale_factor (floating point) + + vacuum_cleanup_indexscale_factor configuration parameter + + + + + Specifies a fraction of the table pages that need to be vacuumed + prior to vacuum needed to trigger a cleaning up indexes in one table. + The default is 0.01. This parameter can be set anywhere. + + + + bytea_output (enum) diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index 5d47f16..4f29dc8 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -131,6 +131,10 @@ typedef struct LVRelStats bool lock_waiter_detected; } LVRelStats; +/* + * GUC parameter + */ +double vacuum_cleanup_index_scale; /* A few variables that don't seem worth passing around as parameters */ static int elevel = -1; @@ -478,6 +482,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, PROGRESS_VACUUM_MAX_DEAD_TUPLES }; int64 initprog_val[3]; + float4 cleanupidx_thresh; pg_rusage_init(&ru0); @@ -1313,9 +1318,20 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, pgstat_progress_update_param(PROGRESS_VACUUM_PHASE, PROGRESS_VACUUM_PHASE_INDEX_CLEANUP); - /* Do post-vacuum cleanup and statistics update for each index */ - for (i = 0; i < nindexes; i++) - lazy_cleanup_index(Irel[i], indstats[i], vacrelstats); + /* + * Do post-vacuum cleanup and statistics update for each index if + * the number of vacuumed page exceeds threshold. + */ + cleanupidx_thresh = (float4) nblocks * vacuum_cleanup_index_scale; + + elog(DEBUG3, "%s: scanned: %d (threshold %0.f)", + RelationGetRelationName(onerel), vacrelstats->scanned_pages, + cleanupidx_thresh); + if (vacrelstats->scanned_pages >= cleanupidx_thresh) + { + for (i = 0; i < nindexes; i++) + lazy_cleanup_index(Irel[i], indstats[i], vacrelstats); + } /* If no indexes, make log report that lazy_vacuum_heap would've made */ if (vacuumed_pages) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 0707f66..f8d7a5d 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2994,6 +2994,16 @@ static struct config_real ConfigureNamesReal[] = }, { + {"vacuum_cleanup_index_scale_factor", PGC_USERSET, CLIENT_CONN_STATEMENT, + gettext_noop("Number of pages containing dead tuple prior to vacuum as a fraction of relpages."), + NULL + }, + &vacuum_cleanup_index_scale, + 0.01, 0.0, 100.0, + NULL, NULL, NULL + }, + + { {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS, gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."), NULL diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 541c2fa..3e9a149 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -154,6 +154,7 @@ extern int vacuum_freeze_min_age; extern int vacuum_freeze_table_age; extern int vacuum_multixact_freeze_min_age; extern int vacuum_multixact_freeze_table_age; +extern double vacuum_cleanup_index_scale; /* in commands/vacuum.c */