From 2e49700cc2ce24399a5f260c78ba907c519dffe7 Mon Sep 17 00:00:00 2001 From: Sami Imseih Date: Tue, 31 Mar 2026 18:33:18 +0000 Subject: [PATCH v4 2/4] Add elevel parameter to relation_needs_vacanalyze Allow callers to control the log level for debug output by passing an elevel parameter. Passing 0 suppresses logging. This prepares the function for use by a future view that should not emit debug messages when queried. Discussion: https://postgr.es/m/CAA5RZ0s4xjMrB-VAnLccC7kY8d0-4806-Lsac-czJsdA1LXtAw%40mail.gmail.com --- src/backend/postmaster/autovacuum.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 2ca15aee4eb..72ad30f6ae7 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -383,7 +383,8 @@ static void relation_needs_vacanalyze(Oid relid, AutoVacOpts *relopts, PgStat_StatTabEntry *tabentry, int effective_multixact_freeze_max_age, bool *dovacuum, bool *doanalyze, bool *wraparound, - AutoVacuumPriority *priority); + AutoVacuumPriority *priority, + int elevel); static void autovacuum_do_vac_analyze(autovac_table *tab, BufferAccessStrategy bstrategy); @@ -2080,7 +2081,7 @@ do_autovacuum(void) relation_needs_vacanalyze(relid, relopts, classForm, tabentry, effective_multixact_freeze_max_age, &dovacuum, &doanalyze, &wraparound, - &priority); + &priority, DEBUG3); /* Relations that need work are added to tables_to_process */ if (dovacuum || doanalyze) @@ -2180,7 +2181,7 @@ do_autovacuum(void) relation_needs_vacanalyze(relid, relopts, classForm, tabentry, effective_multixact_freeze_max_age, &dovacuum, &doanalyze, &wraparound, - &priority); + &priority, DEBUG3); /* ignore analyze for toast tables */ if (dovacuum) @@ -2998,7 +2999,7 @@ recheck_relation_needs_vacanalyze(Oid relid, relation_needs_vacanalyze(relid, avopts, classForm, tabentry, effective_multixact_freeze_max_age, dovacuum, doanalyze, wraparound, - &priority); + &priority, DEBUG3); /* Release tabentry to avoid leakage */ if (tabentry) @@ -3087,6 +3088,8 @@ recheck_relation_needs_vacanalyze(Oid relid, * * Priority scores are always computed. dovacuum and doanalyze are only set when * autovacuum is active and enabled for the relation. + * + * elevel controls the log level for debug output. Pass 0 to suppress logging. */ static void relation_needs_vacanalyze(Oid relid, @@ -3098,7 +3101,8 @@ relation_needs_vacanalyze(Oid relid, bool *dovacuum, bool *doanalyze, bool *wraparound, - AutoVacuumPriority *priority) + AutoVacuumPriority *priority, + int elevel) { bool force_vacuum; bool av_enabled; @@ -3345,15 +3349,15 @@ relation_needs_vacanalyze(Oid relid, *doanalyze = true; } - if (vac_ins_base_thresh >= 0) - elog(DEBUG3, "%s: vac: %.0f (thresh %.0f, score %.2f), ins: %.0f (thresh %.0f, score %.2f), anl: %.0f (thresh %.0f, score %.2f), xid score: %.2f, mxid score: %.2f", + if (elevel > 0 && vac_ins_base_thresh >= 0) + elog(elevel, "%s: vac: %.0f (thresh %.0f, score %.2f), ins: %.0f (thresh %.0f, score %.2f), anl: %.0f (thresh %.0f, score %.2f), xid score: %.2f, mxid score: %.2f", NameStr(classForm->relname), vactuples, vacthresh, priority->vac, instuples, vacinsthresh, priority->vac_ins, anltuples, anlthresh, priority->anl, priority->xid, priority->mxid); - else - elog(DEBUG3, "%s: vac: %.0f (thresh %.0f, score %.2f), ins: (disabled), anl: %.0f (thresh %.0f, score %.2f), xid score: %.2f, mxid score: %.2f", + else if (elevel > 0) + elog(elevel, "%s: vac: %.0f (thresh %.0f, score %.2f), ins: (disabled), anl: %.0f (thresh %.0f, score %.2f), xid score: %.2f, mxid score: %.2f", NameStr(classForm->relname), vactuples, vacthresh, priority->vac, anltuples, anlthresh, priority->anl, -- 2.47.3