mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Add log_min_autovacuum_duration per-table option
This is useful to control autovacuum log volume, for situations where monitoring only a set of tables is necessary. Author: Michael Paquier Reviewed by: A team led by Naoya Anzai (also including Akira Kurosawa, Taiki Kondo, Huong Dangminh), Fujii Masao.
This commit is contained in:
@ -85,7 +85,8 @@ static MemoryContext anl_context = NULL;
|
||||
static BufferAccessStrategy vac_strategy;
|
||||
|
||||
|
||||
static void do_analyze_rel(Relation onerel, int options, List *va_cols,
|
||||
static void do_analyze_rel(Relation onerel, int options,
|
||||
VacuumParams *params, List *va_cols,
|
||||
AcquireSampleRowsFunc acquirefunc, BlockNumber relpages,
|
||||
bool inh, bool in_outer_xact, int elevel);
|
||||
static void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
|
||||
@ -115,8 +116,9 @@ static Datum ind_fetch_func(VacAttrStatsP stats, int rownum, bool *isNull);
|
||||
* analyze_rel() -- analyze one relation
|
||||
*/
|
||||
void
|
||||
analyze_rel(Oid relid, RangeVar *relation, int options, List *va_cols,
|
||||
bool in_outer_xact, BufferAccessStrategy bstrategy)
|
||||
analyze_rel(Oid relid, RangeVar *relation, int options,
|
||||
VacuumParams *params, List *va_cols, bool in_outer_xact,
|
||||
BufferAccessStrategy bstrategy)
|
||||
{
|
||||
Relation onerel;
|
||||
int elevel;
|
||||
@ -151,7 +153,7 @@ analyze_rel(Oid relid, RangeVar *relation, int options, List *va_cols,
|
||||
else
|
||||
{
|
||||
onerel = NULL;
|
||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
|
||||
errmsg("skipping analyze of \"%s\" --- lock not available",
|
||||
@ -266,14 +268,14 @@ analyze_rel(Oid relid, RangeVar *relation, int options, List *va_cols,
|
||||
/*
|
||||
* Do the normal non-recursive ANALYZE.
|
||||
*/
|
||||
do_analyze_rel(onerel, options, va_cols, acquirefunc, relpages,
|
||||
do_analyze_rel(onerel, options, params, va_cols, acquirefunc, relpages,
|
||||
false, in_outer_xact, elevel);
|
||||
|
||||
/*
|
||||
* If there are child tables, do recursive ANALYZE.
|
||||
*/
|
||||
if (onerel->rd_rel->relhassubclass)
|
||||
do_analyze_rel(onerel, options, va_cols, acquirefunc, relpages,
|
||||
do_analyze_rel(onerel, options, params, va_cols, acquirefunc, relpages,
|
||||
true, in_outer_xact, elevel);
|
||||
|
||||
/*
|
||||
@ -301,9 +303,10 @@ analyze_rel(Oid relid, RangeVar *relation, int options, List *va_cols,
|
||||
* appropriate acquirefunc for each child table.
|
||||
*/
|
||||
static void
|
||||
do_analyze_rel(Relation onerel, int options, List *va_cols,
|
||||
AcquireSampleRowsFunc acquirefunc, BlockNumber relpages,
|
||||
bool inh, bool in_outer_xact, int elevel)
|
||||
do_analyze_rel(Relation onerel, int options, VacuumParams *params,
|
||||
List *va_cols, AcquireSampleRowsFunc acquirefunc,
|
||||
BlockNumber relpages, bool inh, bool in_outer_xact,
|
||||
int elevel)
|
||||
{
|
||||
int attr_cnt,
|
||||
tcnt,
|
||||
@ -359,10 +362,10 @@ do_analyze_rel(Relation onerel, int options, List *va_cols,
|
||||
save_nestlevel = NewGUCNestLevel();
|
||||
|
||||
/* measure elapsed time iff autovacuum logging requires it */
|
||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
|
||||
{
|
||||
pg_rusage_init(&ru0);
|
||||
if (Log_autovacuum_min_duration > 0)
|
||||
if (params->log_min_duration > 0)
|
||||
starttime = GetCurrentTimestamp();
|
||||
}
|
||||
|
||||
@ -647,11 +650,11 @@ do_analyze_rel(Relation onerel, int options, List *va_cols,
|
||||
vac_close_indexes(nindexes, Irel, NoLock);
|
||||
|
||||
/* Log the action if appropriate */
|
||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
|
||||
{
|
||||
if (Log_autovacuum_min_duration == 0 ||
|
||||
if (params->log_min_duration == 0 ||
|
||||
TimestampDifferenceExceeds(starttime, GetCurrentTimestamp(),
|
||||
Log_autovacuum_min_duration))
|
||||
params->log_min_duration))
|
||||
ereport(LOG,
|
||||
(errmsg("automatic analyze of table \"%s.%s.%s\" system usage: %s",
|
||||
get_database_name(MyDatabaseId),
|
||||
|
@ -114,6 +114,9 @@ ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
|
||||
/* user-invoked vacuum is never "for wraparound" */
|
||||
params.is_wraparound = false;
|
||||
|
||||
/* user-invoked vacuum never uses this parameter */
|
||||
params.log_min_duration = -1;
|
||||
|
||||
/* Now go through the common routine */
|
||||
vacuum(vacstmt->options, vacstmt->relation, InvalidOid, ¶ms,
|
||||
vacstmt->va_cols, NULL, isTopLevel);
|
||||
@ -304,7 +307,7 @@ vacuum(int options, RangeVar *relation, Oid relid, VacuumParams *params,
|
||||
PushActiveSnapshot(GetTransactionSnapshot());
|
||||
}
|
||||
|
||||
analyze_rel(relid, relation, options,
|
||||
analyze_rel(relid, relation, options, params,
|
||||
va_cols, in_outer_xact, vac_strategy);
|
||||
|
||||
if (use_own_xacts)
|
||||
@ -1233,7 +1236,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
|
||||
else
|
||||
{
|
||||
onerel = NULL;
|
||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
|
||||
errmsg("skipping vacuum of \"%s\" --- lock not available",
|
||||
|
@ -196,7 +196,7 @@ lazy_vacuum_rel(Relation onerel, int options, VacuumParams *params,
|
||||
Assert(params != NULL);
|
||||
|
||||
/* measure elapsed time iff autovacuum logging requires it */
|
||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
|
||||
{
|
||||
pg_rusage_init(&ru0);
|
||||
starttime = GetCurrentTimestamp();
|
||||
@ -328,13 +328,13 @@ lazy_vacuum_rel(Relation onerel, int options, VacuumParams *params,
|
||||
vacrelstats->new_dead_tuples);
|
||||
|
||||
/* and log the action if appropriate */
|
||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
|
||||
{
|
||||
TimestampTz endtime = GetCurrentTimestamp();
|
||||
|
||||
if (Log_autovacuum_min_duration == 0 ||
|
||||
if (params->log_min_duration == 0 ||
|
||||
TimestampDifferenceExceeds(starttime, endtime,
|
||||
Log_autovacuum_min_duration))
|
||||
params->log_min_duration))
|
||||
{
|
||||
StringInfoData buf;
|
||||
TimestampDifference(starttime, endtime, &secs, &usecs);
|
||||
|
Reference in New Issue
Block a user