PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
autovacuum.c File Reference
#include "postgres.h"
#include <signal.h>
#include <sys/time.h>
#include <unistd.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/reloptions.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/dependency.h"
#include "catalog/namespace.h"
#include "catalog/pg_database.h"
#include "commands/dbcommands.h"
#include "commands/vacuum.h"
#include "lib/ilist.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "postmaster/fork_process.h"
#include "postmaster/postmaster.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lmgr.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "storage/sinvaladt.h"
#include "storage/smgr.h"
#include "tcop/tcopprot.h"
#include "utils/dsa.h"
#include "utils/fmgroids.h"
#include "utils/fmgrprotos.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
#include "utils/timeout.h"
#include "utils/timestamp.h"
#include "utils/tqual.h"
Include dependency graph for autovacuum.c:

Go to the source code of this file.

Data Structures

struct  avl_dbase
 
struct  avw_dbase
 
struct  av_relation
 
struct  autovac_table
 
struct  WorkerInfoData
 
struct  AutoVacuumWorkItem
 
struct  AutoVacuumShmemStruct
 

Macros

#define STATS_READ_DELAY   1000
 
#define MIN_AUTOVAC_SLEEPTIME   100.0 /* milliseconds */
 
#define MAX_AUTOVAC_SLEEPTIME   300 /* seconds */
 
#define NUM_WORKITEMS   256
 
#define MAX_AUTOVAC_ACTIV_LEN   (NAMEDATALEN * 2 + 56)
 

Typedefs

typedef struct avl_dbase avl_dbase
 
typedef struct avw_dbase avw_dbase
 
typedef struct av_relation av_relation
 
typedef struct autovac_table autovac_table
 
typedef struct WorkerInfoData WorkerInfoData
 
typedef struct WorkerInfoDataWorkerInfo
 
typedef struct AutoVacuumWorkItem AutoVacuumWorkItem
 

Enumerations

enum  AutoVacuumSignal { AutoVacForkFailed, AutoVacRebalance, AutoVacNumSignals }
 

Functions

NON_EXEC_STATIC void AutoVacWorkerMain (int argc, char *argv[]) pg_attribute_noreturn()
 
NON_EXEC_STATIC void AutoVacLauncherMain (int argc, char *argv[]) pg_attribute_noreturn()
 
static Oid do_start_worker (void)
 
static void launcher_determine_sleep (bool canlaunch, bool recursing, struct timeval *nap)
 
static void launch_worker (TimestampTz now)
 
static Listget_database_list (void)
 
static void rebuild_database_list (Oid newdb)
 
static int db_comparator (const void *a, const void *b)
 
static void autovac_balance_cost (void)
 
static void do_autovacuum (void)
 
static void FreeWorkerInfo (int code, Datum arg)
 
static autovac_tabletable_recheck_autovac (Oid relid, HTAB *table_toast_map, TupleDesc pg_class_desc, int effective_multixact_freeze_max_age)
 
static void relation_needs_vacanalyze (Oid relid, AutoVacOpts *relopts, Form_pg_class classForm, PgStat_StatTabEntry *tabentry, int effective_multixact_freeze_max_age, bool *dovacuum, bool *doanalyze, bool *wraparound)
 
static void autovacuum_do_vac_analyze (autovac_table *tab, BufferAccessStrategy bstrategy)
 
static AutoVacOptsextract_autovac_opts (HeapTuple tup, TupleDesc pg_class_desc)
 
static PgStat_StatTabEntryget_pgstat_tabentry_relid (Oid relid, bool isshared, PgStat_StatDBEntry *shared, PgStat_StatDBEntry *dbentry)
 
static void perform_work_item (AutoVacuumWorkItem *workitem)
 
static void autovac_report_activity (autovac_table *tab)
 
static void autovac_report_workitem (AutoVacuumWorkItem *workitem, const char *nspname, const char *relname)
 
static void av_sighup_handler (SIGNAL_ARGS)
 
static void avl_sigusr2_handler (SIGNAL_ARGS)
 
static void avl_sigterm_handler (SIGNAL_ARGS)
 
static void autovac_refresh_stats (void)
 
int StartAutoVacLauncher (void)
 
void AutoVacWorkerFailed (void)
 
int StartAutoVacWorker (void)
 
void AutoVacuumUpdateDelay (void)
 
bool AutoVacuumingActive (void)
 
void AutoVacuumRequestWork (AutoVacuumWorkItemType type, Oid relationId, BlockNumber blkno)
 
void autovac_init (void)
 
bool IsAutoVacuumLauncherProcess (void)
 
bool IsAutoVacuumWorkerProcess (void)
 
Size AutoVacuumShmemSize (void)
 
void AutoVacuumShmemInit (void)
 

Variables

bool autovacuum_start_daemon = false
 
int autovacuum_max_workers
 
int autovacuum_work_mem = -1
 
int autovacuum_naptime
 
int autovacuum_vac_thresh
 
double autovacuum_vac_scale
 
int autovacuum_anl_thresh
 
double autovacuum_anl_scale
 
int autovacuum_freeze_max_age
 
int autovacuum_multixact_freeze_max_age
 
int autovacuum_vac_cost_delay
 
int autovacuum_vac_cost_limit
 
int Log_autovacuum_min_duration = -1
 
static bool am_autovacuum_launcher = false
 
static bool am_autovacuum_worker = false
 
static volatile sig_atomic_t got_SIGHUP = false
 
static volatile sig_atomic_t got_SIGUSR2 = false
 
static volatile sig_atomic_t got_SIGTERM = false
 
static TransactionId recentXid
 
static MultiXactId recentMulti
 
static int default_freeze_min_age
 
static int default_freeze_table_age
 
static int default_multixact_freeze_min_age
 
static int default_multixact_freeze_table_age
 
static MemoryContext AutovacMemCxt
 
static AutoVacuumShmemStructAutoVacuumShmem
 
static dlist_head DatabaseList = DLIST_STATIC_INIT(DatabaseList)
 
static MemoryContext DatabaseListCxt = NULL
 
static WorkerInfo MyWorkerInfo = NULL
 
int AutovacuumLauncherPid = 0
 

Macro Definition Documentation

#define MAX_AUTOVAC_ACTIV_LEN   (NAMEDATALEN * 2 + 56)
#define MAX_AUTOVAC_SLEEPTIME   300 /* seconds */

Definition at line 135 of file autovacuum.c.

Referenced by launcher_determine_sleep().

#define MIN_AUTOVAC_SLEEPTIME   100.0 /* milliseconds */

Definition at line 134 of file autovacuum.c.

Referenced by launcher_determine_sleep(), and rebuild_database_list().

#define NUM_WORKITEMS   256

Definition at line 265 of file autovacuum.c.

Referenced by AutoVacuumRequestWork(), AutoVacuumShmemInit(), and do_autovacuum().

#define STATS_READ_DELAY   1000

Definition at line 131 of file autovacuum.c.

Referenced by autovac_refresh_stats().

Typedef Documentation

Definition at line 235 of file autovacuum.c.

Enumeration Type Documentation

Enumerator
AutoVacForkFailed 
AutoVacRebalance 
AutoVacNumSignals 

Definition at line 242 of file autovacuum.c.

243 {
244  AutoVacForkFailed, /* failed trying to start a worker */
245  AutoVacRebalance, /* rebalance the cost limits */
246  AutoVacNumSignals /* must be last */
AutoVacuumSignal
Definition: autovacuum.c:242

Function Documentation

static void autovac_balance_cost ( void  )
static

Definition at line 1776 of file autovacuum.c.

References autovacuum_vac_cost_delay, autovacuum_vac_cost_limit, AutoVacuumShmemStruct::av_runningWorkers, dlist_iter::cur, DEBUG2, dlist_container, dlist_foreach, elog, Max, Min, PGPROC::pid, VacuumCostDelay, VacuumCostLimit, WorkerInfoData::wi_cost_delay, WorkerInfoData::wi_cost_limit, WorkerInfoData::wi_cost_limit_base, WorkerInfoData::wi_dboid, WorkerInfoData::wi_dobalance, WorkerInfoData::wi_proc, and WorkerInfoData::wi_tableoid.

Referenced by AutoVacLauncherMain(), and do_autovacuum().

1777 {
1778  /*
1779  * The idea here is that we ration out I/O equally. The amount of I/O
1780  * that a worker can consume is determined by cost_limit/cost_delay, so we
1781  * try to equalize those ratios rather than the raw limit settings.
1782  *
1783  * note: in cost_limit, zero also means use value from elsewhere, because
1784  * zero is not a valid value.
1785  */
1786  int vac_cost_limit = (autovacuum_vac_cost_limit > 0 ?
1788  int vac_cost_delay = (autovacuum_vac_cost_delay >= 0 ?
1790  double cost_total;
1791  double cost_avail;
1792  dlist_iter iter;
1793 
1794  /* not set? nothing to do */
1795  if (vac_cost_limit <= 0 || vac_cost_delay <= 0)
1796  return;
1797 
1798  /* calculate the total base cost limit of participating active workers */
1799  cost_total = 0.0;
1801  {
1802  WorkerInfo worker = dlist_container(WorkerInfoData, wi_links, iter.cur);
1803 
1804  if (worker->wi_proc != NULL &&
1805  worker->wi_dobalance &&
1806  worker->wi_cost_limit_base > 0 && worker->wi_cost_delay > 0)
1807  cost_total +=
1808  (double) worker->wi_cost_limit_base / worker->wi_cost_delay;
1809  }
1810 
1811  /* there are no cost limits -- nothing to do */
1812  if (cost_total <= 0)
1813  return;
1814 
1815  /*
1816  * Adjust cost limit of each active worker to balance the total of cost
1817  * limit to autovacuum_vacuum_cost_limit.
1818  */
1819  cost_avail = (double) vac_cost_limit / vac_cost_delay;
1821  {
1822  WorkerInfo worker = dlist_container(WorkerInfoData, wi_links, iter.cur);
1823 
1824  if (worker->wi_proc != NULL &&
1825  worker->wi_dobalance &&
1826  worker->wi_cost_limit_base > 0 && worker->wi_cost_delay > 0)
1827  {
1828  int limit = (int)
1829  (cost_avail * worker->wi_cost_limit_base / cost_total);
1830 
1831  /*
1832  * We put a lower bound of 1 on the cost_limit, to avoid division-
1833  * by-zero in the vacuum code. Also, in case of roundoff trouble
1834  * in these calculations, let's be sure we don't ever set
1835  * cost_limit to more than the base value.
1836  */
1837  worker->wi_cost_limit = Max(Min(limit,
1838  worker->wi_cost_limit_base),
1839  1);
1840  }
1841 
1842  if (worker->wi_proc != NULL)
1843  elog(DEBUG2, "autovac_balance_cost(pid=%u db=%u, rel=%u, dobalance=%s cost_limit=%d, cost_limit_base=%d, cost_delay=%d)",
1844  worker->wi_proc->pid, worker->wi_dboid, worker->wi_tableoid,
1845  worker->wi_dobalance ? "yes" : "no",
1846  worker->wi_cost_limit, worker->wi_cost_limit_base,
1847  worker->wi_cost_delay);
1848  }
1849 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:507
#define Min(x, y)
Definition: c.h:812
int autovacuum_vac_cost_limit
Definition: autovacuum.c:126
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
int VacuumCostLimit
Definition: globals.c:131
#define DEBUG2
Definition: elog.h:24
int autovacuum_vac_cost_delay
Definition: autovacuum.c:125
int wi_cost_limit_base
Definition: autovacuum.c:232
dlist_node * cur
Definition: ilist.h:161
int VacuumCostDelay
Definition: globals.c:132
#define Max(x, y)
Definition: c.h:806
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
PGPROC * wi_proc
Definition: autovacuum.c:226
#define elog
Definition: elog.h:219
dlist_head av_runningWorkers
Definition: autovacuum.c:288
int pid
Definition: proc.h:109
void autovac_init ( void  )

Definition at line 3236 of file autovacuum.c.

References autovacuum_start_daemon, ereport, errhint(), errmsg(), pgstat_track_counts, and WARNING.

Referenced by PostmasterMain().

3237 {
3239  ereport(WARNING,
3240  (errmsg("autovacuum not started because of misconfiguration"),
3241  errhint("Enable the \"track_counts\" option.")));
3242 }
int errhint(const char *fmt,...)
Definition: elog.c:987
bool autovacuum_start_daemon
Definition: autovacuum.c:114
bool pgstat_track_counts
Definition: pgstat.c:126
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:797
static void autovac_refresh_stats ( void  )
static

Definition at line 3334 of file autovacuum.c.

References GetCurrentTimestamp(), IsAutoVacuumLauncherProcess(), last_read, pgstat_clear_snapshot(), STATS_READ_DELAY, and TimestampDifferenceExceeds().

Referenced by do_start_worker(), rebuild_database_list(), and table_recheck_autovac().

3335 {
3337  {
3338  static TimestampTz last_read = 0;
3339  TimestampTz current_time;
3340 
3341  current_time = GetCurrentTimestamp();
3342 
3343  if (!TimestampDifferenceExceeds(last_read, current_time,
3345  return;
3346 
3347  last_read = current_time;
3348  }
3349 
3351 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1570
int64 TimestampTz
Definition: timestamp.h:39
WalTimeSample last_read[NUM_SYNC_REP_WAIT_MODE]
Definition: walsender.c:217
#define STATS_READ_DELAY
Definition: autovacuum.c:131
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1649
bool IsAutoVacuumLauncherProcess(void)
Definition: autovacuum.c:3250
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5560
static void autovac_report_activity ( autovac_table tab)
static

Definition at line 3112 of file autovacuum.c.

References autovac_table::at_nspname, autovac_table::at_params, autovac_table::at_relname, autovac_table::at_vacoptions, VacuumParams::is_wraparound, MAX_AUTOVAC_ACTIV_LEN, pgstat_report_activity(), SetCurrentStatementStartTimestamp(), snprintf(), STATE_RUNNING, VACOPT_ANALYZE, and VACOPT_VACUUM.

Referenced by autovacuum_do_vac_analyze().

3113 {
3114 #define MAX_AUTOVAC_ACTIV_LEN (NAMEDATALEN * 2 + 56)
3115  char activity[MAX_AUTOVAC_ACTIV_LEN];
3116  int len;
3117 
3118  /* Report the command and possible options */
3119  if (tab->at_vacoptions & VACOPT_VACUUM)
3120  snprintf(activity, MAX_AUTOVAC_ACTIV_LEN,
3121  "autovacuum: VACUUM%s",
3122  tab->at_vacoptions & VACOPT_ANALYZE ? " ANALYZE" : "");
3123  else
3124  snprintf(activity, MAX_AUTOVAC_ACTIV_LEN,
3125  "autovacuum: ANALYZE");
3126 
3127  /*
3128  * Report the qualified name of the relation.
3129  */
3130  len = strlen(activity);
3131 
3132  snprintf(activity + len, MAX_AUTOVAC_ACTIV_LEN - len,
3133  " %s.%s%s", tab->at_nspname, tab->at_relname,
3134  tab->at_params.is_wraparound ? " (to prevent wraparound)" : "");
3135 
3136  /* Set statement_timestamp() to current time for pg_stat_activity */
3138 
3140 }
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:2994
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * at_relname
Definition: autovacuum.c:198
bool is_wraparound
Definition: vacuum.h:144
char * at_nspname
Definition: autovacuum.c:199
#define MAX_AUTOVAC_ACTIV_LEN
VacuumParams at_params
Definition: autovacuum.c:193
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:733
static void autovac_report_workitem ( AutoVacuumWorkItem workitem,
const char *  nspname,
const char *  relname 
)
static

Definition at line 3147 of file autovacuum.c.

References AutoVacuumWorkItem::avw_blockNumber, AVW_BRINSummarizeRange, AutoVacuumWorkItem::avw_type, BlockNumberIsValid, MAX_AUTOVAC_ACTIV_LEN, pgstat_report_activity(), SetCurrentStatementStartTimestamp(), snprintf(), and STATE_RUNNING.

Referenced by perform_work_item().

3149 {
3150  char activity[MAX_AUTOVAC_ACTIV_LEN + 12 + 2];
3151  char blk[12 + 2];
3152  int len;
3153 
3154  switch (workitem->avw_type)
3155  {
3157  snprintf(activity, MAX_AUTOVAC_ACTIV_LEN,
3158  "autovacuum: BRIN summarize");
3159  break;
3160  }
3161 
3162  /*
3163  * Report the qualified name of the relation, and the block number if any
3164  */
3165  len = strlen(activity);
3166 
3167  if (BlockNumberIsValid(workitem->avw_blockNumber))
3168  snprintf(blk, sizeof(blk), " %u", workitem->avw_blockNumber);
3169  else
3170  blk[0] = '\0';
3171 
3172  snprintf(activity + len, MAX_AUTOVAC_ACTIV_LEN - len,
3173  " %s.%s%s", nspname, relname, blk);
3174 
3175  /* Set statement_timestamp() to current time for pg_stat_activity */
3177 
3179 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:257
void pgstat_report_activity(BackendState state, const char *cmd_str)
Definition: pgstat.c:2994
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define MAX_AUTOVAC_ACTIV_LEN
BlockNumber avw_blockNumber
Definition: autovacuum.c:262
#define BlockNumberIsValid(blockNumber)
Definition: block.h:70
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:733
NON_EXEC_STATIC void AutoVacLauncherMain ( int  argc,
char *  argv[] 
)

Definition at line 433 of file autovacuum.c.

References AbortBufferIO(), AbortCurrentTransaction(), avl_dbase::adl_next_worker, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), am_autovacuum_launcher, AtEOXact_Buffers(), AtEOXact_Files(), AtEOXact_HashTables(), AtEOXact_SMgr(), autovac_balance_cost(), AutoVacForkFailed, AutoVacRebalance, autovacuum_naptime, AutoVacuumingActive(), AutoVacuumShmemStruct::av_freeWorkers, AutoVacuumShmemStruct::av_launcherpid, av_sighup_handler(), AutoVacuumShmemStruct::av_signal, AutoVacuumShmemStruct::av_startingWorker, avl_sigterm_handler(), avl_sigusr2_handler(), B_AUTOVAC_LAUNCHER, BaseInit(), CurrentResourceOwner, DEBUG1, disable_all_timeouts(), dlist_init(), dlist_is_empty(), dlist_push_head(), dlist_tail_element, do_start_worker(), elog, EmitErrorReport(), ereport, errmsg(), error_context_stack, FloatExceptionHandler(), FlushErrorState(), GetCurrentTimestamp(), got_SIGHUP, got_SIGTERM, got_SIGUSR2, HOLD_INTERRUPTS, init_ps_display(), InitializeTimeouts(), InitPostgres(), InitProcess(), InitProcessing, InvalidOid, launch_worker(), launcher_determine_sleep(), LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), LWLockReleaseAll(), MemoryContextResetAndDeleteChildren, MemoryContextSwitchTo(), Min, MyLatch, MyProcPid, NormalProcessing, PG_exception_stack, PG_SETMASK, pg_usleep(), PGC_S_OVERRIDE, PGC_SIGHUP, PGC_SUSET, pgstat_clear_snapshot(), pgstat_get_backend_desc(), pgstat_report_wait_end(), PMSIGNAL_START_AUTOVAC_WORKER, PostAuthDelay, pqsignal(), proc_exit(), ProcessCatchupInterrupt(), ProcessConfigFile(), procsignal_sigusr1_handler(), QueryCancelPending, quickdie(), rebuild_database_list(), ResetLatch(), RESOURCE_RELEASE_BEFORE_LOCKS, ResourceOwnerRelease(), RESUME_INTERRUPTS, SendPostmasterSignal(), SetConfigOption(), SetProcessingMode, SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, StatementCancelHandler(), TimestampDifferenceExceeds(), TopMemoryContext, UnBlockSig, UnlockBuffers(), WAIT_EVENT_AUTOVACUUM_MAIN, WaitLatch(), waittime, WARNING, WorkerInfoData::wi_dboid, WorkerInfoData::wi_launchtime, WorkerInfoData::wi_links, WorkerInfoData::wi_proc, WorkerInfoData::wi_sharedrel, WorkerInfoData::wi_tableoid, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.

Referenced by StartAutoVacLauncher().

434 {
435  sigjmp_buf local_sigjmp_buf;
436 
437  am_autovacuum_launcher = true;
438 
439  /* Identify myself via ps */
441 
442  ereport(DEBUG1,
443  (errmsg("autovacuum launcher started")));
444 
445  if (PostAuthDelay)
446  pg_usleep(PostAuthDelay * 1000000L);
447 
449 
450  /*
451  * Set up signal handlers. We operate on databases much like a regular
452  * backend, so we use the same signal handling. See equivalent code in
453  * tcop/postgres.c.
454  */
457  pqsignal(SIGTERM, avl_sigterm_handler);
458 
460  InitializeTimeouts(); /* establishes SIGALRM handler */
461 
467 
468  /* Early initialization */
469  BaseInit();
470 
471  /*
472  * Create a per-backend PGPROC struct in shared memory, except in the
473  * EXEC_BACKEND case where this was done in SubPostmasterMain. We must do
474  * this before we can use LWLocks (and in the EXEC_BACKEND case we already
475  * had to do some stuff with LWLocks).
476  */
477 #ifndef EXEC_BACKEND
478  InitProcess();
479 #endif
480 
481  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL);
482 
484 
485  /*
486  * Create a memory context that we will do all our work in. We do this so
487  * that we can reset the context during error recovery and thereby avoid
488  * possible memory leaks.
489  */
491  "Autovacuum Launcher",
494 
495  /*
496  * If an exception is encountered, processing resumes here.
497  *
498  * This code is a stripped down version of PostgresMain error recovery.
499  */
500  if (sigsetjmp(local_sigjmp_buf, 1) != 0)
501  {
502  /* since not using PG_TRY, must reset error stack by hand */
503  error_context_stack = NULL;
504 
505  /* Prevents interrupts while cleaning up */
506  HOLD_INTERRUPTS();
507 
508  /* Forget any pending QueryCancel or timeout request */
509  disable_all_timeouts(false);
510  QueryCancelPending = false; /* second to avoid race condition */
511 
512  /* Report the error to the server log */
513  EmitErrorReport();
514 
515  /* Abort the current transaction in order to recover */
517 
518  /*
519  * Release any other resources, for the case where we were not in a
520  * transaction.
521  */
524  AbortBufferIO();
525  UnlockBuffers();
527  {
530  false, true);
531  /* we needn't bother with the other ResourceOwnerRelease phases */
532  }
533  AtEOXact_Buffers(false);
534  AtEOXact_SMgr();
535  AtEOXact_Files();
536  AtEOXact_HashTables(false);
537 
538  /*
539  * Now return to normal top-level context and clear ErrorContext for
540  * next time.
541  */
543  FlushErrorState();
544 
545  /* Flush any leaked data in the top-level context */
547 
548  /* don't leave dangling pointers to freed memory */
549  DatabaseListCxt = NULL;
551 
552  /*
553  * Make sure pgstat also considers our stat data as gone. Note: we
554  * mustn't use autovac_refresh_stats here.
555  */
557 
558  /* Now we can allow interrupts again */
560 
561  /* if in shutdown mode, no need for anything further; just go away */
562  if (got_SIGTERM)
563  goto shutdown;
564 
565  /*
566  * Sleep at least 1 second after any error. We don't want to be
567  * filling the error logs as fast as we can.
568  */
569  pg_usleep(1000000L);
570  }
571 
572  /* We can now handle ereport(ERROR) */
573  PG_exception_stack = &local_sigjmp_buf;
574 
575  /* must unblock signals before calling rebuild_database_list */
577 
578  /*
579  * Force zero_damaged_pages OFF in the autovac process, even if it is set
580  * in postgresql.conf. We don't really want such a dangerous option being
581  * applied non-interactively.
582  */
583  SetConfigOption("zero_damaged_pages", "false", PGC_SUSET, PGC_S_OVERRIDE);
584 
585  /*
586  * Force settable timeouts off to avoid letting these settings prevent
587  * regular maintenance from being executed.
588  */
589  SetConfigOption("statement_timeout", "0", PGC_SUSET, PGC_S_OVERRIDE);
590  SetConfigOption("lock_timeout", "0", PGC_SUSET, PGC_S_OVERRIDE);
591  SetConfigOption("idle_in_transaction_session_timeout", "0",
593 
594  /*
595  * Force default_transaction_isolation to READ COMMITTED. We don't want
596  * to pay the overhead of serializable mode, nor add any risk of causing
597  * deadlocks or delaying other transactions.
598  */
599  SetConfigOption("default_transaction_isolation", "read committed",
601 
602  /*
603  * In emergency mode, just start a worker (unless shutdown was requested)
604  * and go away.
605  */
606  if (!AutoVacuumingActive())
607  {
608  if (!got_SIGTERM)
609  do_start_worker();
610  proc_exit(0); /* done */
611  }
612 
614 
615  /*
616  * Create the initial database list. The invariant we want this list to
617  * keep is that it's ordered by decreasing next_time. As soon as an entry
618  * is updated to a higher time, it will be moved to the front (which is
619  * correct because the only operation is to add autovacuum_naptime to the
620  * entry, and time always increases).
621  */
623 
624  /* loop until shutdown request */
625  while (!got_SIGTERM)
626  {
627  struct timeval nap;
628  TimestampTz current_time = 0;
629  bool can_launch;
630  int rc;
631 
632  /*
633  * This loop is a bit different from the normal use of WaitLatch,
634  * because we'd like to sleep before the first launch of a child
635  * process. So it's WaitLatch, then ResetLatch, then check for
636  * wakening conditions.
637  */
638 
640  false, &nap);
641 
642  /*
643  * Wait until naptime expires or we get some type of signal (all the
644  * signal handlers will wake us by calling SetLatch).
645  */
646  rc = WaitLatch(MyLatch,
648  (nap.tv_sec * 1000L) + (nap.tv_usec / 1000L),
650 
652 
653  /* Process sinval catchup interrupts that happened while sleeping */
655 
656  /*
657  * Emergency bailout if postmaster has died. This is to avoid the
658  * necessity for manual cleanup of all postmaster children.
659  */
660  if (rc & WL_POSTMASTER_DEATH)
661  proc_exit(1);
662 
663  /* the normal shutdown case */
664  if (got_SIGTERM)
665  break;
666 
667  if (got_SIGHUP)
668  {
669  got_SIGHUP = false;
671 
672  /* shutdown requested in config file? */
673  if (!AutoVacuumingActive())
674  break;
675 
676  /* rebalance in case the default cost parameters changed */
677  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
679  LWLockRelease(AutovacuumLock);
680 
681  /* rebuild the list in case the naptime changed */
683  }
684 
685  /*
686  * a worker finished, or postmaster signalled failure to start a
687  * worker
688  */
689  if (got_SIGUSR2)
690  {
691  got_SIGUSR2 = false;
692 
693  /* rebalance cost limits, if needed */
695  {
696  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
699  LWLockRelease(AutovacuumLock);
700  }
701 
703  {
704  /*
705  * If the postmaster failed to start a new worker, we sleep
706  * for a little while and resend the signal. The new worker's
707  * state is still in memory, so this is sufficient. After
708  * that, we restart the main loop.
709  *
710  * XXX should we put a limit to the number of times we retry?
711  * I don't think it makes much sense, because a future start
712  * of a worker will continue to fail in the same way.
713  */
715  pg_usleep(1000000L); /* 1s */
717  continue;
718  }
719  }
720 
721  /*
722  * There are some conditions that we need to check before trying to
723  * start a worker. First, we need to make sure that there is a worker
724  * slot available. Second, we need to make sure that no other worker
725  * failed while starting up.
726  */
727 
728  current_time = GetCurrentTimestamp();
729  LWLockAcquire(AutovacuumLock, LW_SHARED);
730 
732 
733  if (AutoVacuumShmem->av_startingWorker != NULL)
734  {
735  int waittime;
737 
738  /*
739  * We can't launch another worker when another one is still
740  * starting up (or failed while doing so), so just sleep for a bit
741  * more; that worker will wake us up again as soon as it's ready.
742  * We will only wait autovacuum_naptime seconds (up to a maximum
743  * of 60 seconds) for this to happen however. Note that failure
744  * to connect to a particular database is not a problem here,
745  * because the worker removes itself from the startingWorker
746  * pointer before trying to connect. Problems detected by the
747  * postmaster (like fork() failure) are also reported and handled
748  * differently. The only problems that may cause this code to
749  * fire are errors in the earlier sections of AutoVacWorkerMain,
750  * before the worker removes the WorkerInfo from the
751  * startingWorker pointer.
752  */
753  waittime = Min(autovacuum_naptime, 60) * 1000;
754  if (TimestampDifferenceExceeds(worker->wi_launchtime, current_time,
755  waittime))
756  {
757  LWLockRelease(AutovacuumLock);
758  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
759 
760  /*
761  * No other process can put a worker in starting mode, so if
762  * startingWorker is still INVALID after exchanging our lock,
763  * we assume it's the same one we saw above (so we don't
764  * recheck the launch time).
765  */
766  if (AutoVacuumShmem->av_startingWorker != NULL)
767  {
769  worker->wi_dboid = InvalidOid;
770  worker->wi_tableoid = InvalidOid;
771  worker->wi_sharedrel = false;
772  worker->wi_proc = NULL;
773  worker->wi_launchtime = 0;
775  &worker->wi_links);
777  elog(WARNING, "worker took too long to start; canceled");
778  }
779  }
780  else
781  can_launch = false;
782  }
783  LWLockRelease(AutovacuumLock); /* either shared or exclusive */
784 
785  /* if we can't do anything, just go back to sleep */
786  if (!can_launch)
787  continue;
788 
789  /* We're OK to start a new worker */
790 
792  {
793  /*
794  * Special case when the list is empty: start a worker right away.
795  * This covers the initial case, when no database is in pgstats
796  * (thus the list is empty). Note that the constraints in
797  * launcher_determine_sleep keep us from starting workers too
798  * quickly (at most once every autovacuum_naptime when the list is
799  * empty).
800  */
801  launch_worker(current_time);
802  }
803  else
804  {
805  /*
806  * because rebuild_database_list constructs a list with most
807  * distant adl_next_worker first, we obtain our database from the
808  * tail of the list.
809  */
810  avl_dbase *avdb;
811 
812  avdb = dlist_tail_element(avl_dbase, adl_node, &DatabaseList);
813 
814  /*
815  * launch a worker if next_worker is right now or it is in the
816  * past
817  */
819  current_time, 0))
820  launch_worker(current_time);
821  }
822  }
823 
824  /* Normal exit from the autovac launcher is here */
825 shutdown:
826  ereport(DEBUG1,
827  (errmsg("autovacuum launcher shutting down")));
829 
830  proc_exit(0); /* done */
831 }
void ProcessCatchupInterrupt(void)
Definition: sinval.c:177
void InitializeTimeouts(void)
Definition: timeout.c:340
int autovacuum_naptime
Definition: autovacuum.c:117
void AbortCurrentTransaction(void)
Definition: xact.c:2984
#define SIGUSR1
Definition: win32.h:202
TimestampTz adl_next_worker
Definition: autovacuum.c:163
#define DEBUG1
Definition: elog.h:25
int MyProcPid
Definition: globals.c:39
WorkerInfo av_startingWorker
Definition: autovacuum.c:289
static void autovac_balance_cost(void)
Definition: autovacuum.c:1776
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:285
static bool am_autovacuum_launcher
Definition: autovacuum.c:138
#define WL_TIMEOUT
Definition: latch.h:127
void ProcessConfigFile(GucContext context)
dlist_head av_freeWorkers
Definition: autovacuum.c:287
int waittime
Definition: pg_standby.c:43
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1570
int64 TimestampTz
Definition: timestamp.h:39
void AtEOXact_Buffers(bool isCommit)
Definition: bufmgr.c:2415
ResourceOwner CurrentResourceOwner
Definition: resowner.c:138
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4044
TimestampTz wi_launchtime
Definition: autovacuum.c:227
static MemoryContext AutovacMemCxt
Definition: autovacuum.c:157
#define Min(x, y)
Definition: c.h:812
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void proc_exit(int code)
Definition: ipc.c:99
static volatile sig_atomic_t got_SIGHUP
Definition: autovacuum.c:142
#define SetProcessingMode(mode)
Definition: miscadmin.h:373
void BaseInit(void)
Definition: postinit.c:518
dlist_node wi_links
Definition: autovacuum.c:223
void ResetLatch(volatile Latch *latch)
Definition: latch.c:497
volatile bool QueryCancelPending
Definition: globals.c:30
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1649
#define SIGQUIT
Definition: win32.h:189
void FlushErrorState(void)
Definition: elog.c:1587
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
void StatementCancelHandler(SIGNAL_ARGS)
Definition: postgres.c:2683
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:117
ErrorContextCallback * error_context_stack
Definition: elog.c:88
void pg_usleep(long microsec)
Definition: signal.c:53
void AtEOXact_SMgr(void)
Definition: smgr.c:798
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:336
#define SIG_IGN
Definition: win32.h:185
#define dlist_tail_element(type, membername, lhead)
Definition: ilist.h:496
void disable_all_timeouts(bool keep_indicators)
Definition: timeout.c:596
bool AutoVacuumingActive(void)
Definition: autovacuum.c:3187
void AtEOXact_Files(void)
Definition: fd.c:2649
Definition: guc.h:75
static volatile sig_atomic_t got_SIGTERM
Definition: autovacuum.c:144
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
void InitProcess(void)
Definition: proc.c:288
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6681
sigset_t UnBlockSig
Definition: pqsignal.c:22
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1244
static dlist_head DatabaseList
Definition: autovacuum.c:299
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:43
Definition: guc.h:72
static void avl_sigusr2_handler(SIGNAL_ARGS)
Definition: autovacuum.c:1412
static void launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval *nap)
Definition: autovacuum.c:841
#define WARNING
Definition: elog.h:40
void UnlockBuffers(void)
Definition: bufmgr.c:3518
#define MemoryContextResetAndDeleteChildren(ctx)
Definition: memutils.h:67
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
int PostAuthDelay
Definition: postgres.c:99
void EmitErrorReport(void)
Definition: elog.c:1446
#define SIGPIPE
Definition: win32.h:193
#define SIGHUP
Definition: win32.h:188
#define InvalidOid
Definition: postgres_ext.h:36
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define SIG_DFL
Definition: win32.h:183
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
static volatile sig_atomic_t got_SIGUSR2
Definition: autovacuum.c:143
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:471
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
void pgstat_clear_snapshot(void)
Definition: pgstat.c:5560
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
void AbortBufferIO(void)
Definition: bufmgr.c:3974
static void av_sighup_handler(SIGNAL_ARGS)
Definition: autovacuum.c:1400
sigjmp_buf * PG_exception_stack
Definition: elog.c:90
static void rebuild_database_list(Oid newdb)
Definition: autovacuum.c:925
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname)
Definition: postinit.c:559
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:115
static MemoryContext DatabaseListCxt
Definition: autovacuum.c:300
void FloatExceptionHandler(SIGNAL_ARGS)
Definition: postgres.c:2704
struct Latch * MyLatch
Definition: globals.c:52
PGPROC * wi_proc
Definition: autovacuum.c:226
static void launch_worker(TimestampTz now)
Definition: autovacuum.c:1341
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:113
#define elog
Definition: elog.h:219
void LWLockReleaseAll(void)
Definition: lwlock.c:1820
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:261
void AtEOXact_HashTables(bool isCommit)
Definition: dynahash.c:1830
#define SIGCHLD
Definition: win32.h:198
#define WL_LATCH_SET
Definition: latch.h:124
void quickdie(SIGNAL_ARGS)
Definition: postgres.c:2591
static Oid do_start_worker(void)
Definition: autovacuum.c:1126
#define SIGUSR2
Definition: win32.h:203
static void avl_sigterm_handler(SIGNAL_ARGS)
Definition: autovacuum.c:1424
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:244
static void autovacuum_do_vac_analyze ( autovac_table tab,
BufferAccessStrategy  bstrategy 
)
static

Definition at line 3083 of file autovacuum.c.

References autovac_table::at_nspname, autovac_table::at_params, autovac_table::at_relid, autovac_table::at_relname, autovac_table::at_vacoptions, autovac_report_activity(), list_make1, makeRangeVar(), makeVacuumRelation(), NIL, and vacuum().

Referenced by do_autovacuum().

3084 {
3085  RangeVar *rangevar;
3086  VacuumRelation *rel;
3087  List *rel_list;
3088 
3089  /* Let pgstat know what we're doing */
3091 
3092  /* Set up one VacuumRelation target, identified by OID, for vacuum() */
3093  rangevar = makeRangeVar(tab->at_nspname, tab->at_relname, -1);
3094  rel = makeVacuumRelation(rangevar, tab->at_relid, NIL);
3095  rel_list = list_make1(rel);
3096 
3097  vacuum(tab->at_vacoptions, rel_list, &tab->at_params, bstrategy, true);
3098 }
#define NIL
Definition: pg_list.h:69
VacuumRelation * makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
Definition: makefuncs.c:620
void vacuum(int options, List *relations, VacuumParams *params, BufferAccessStrategy bstrategy, bool isTopLevel)
Definition: vacuum.c:166
#define list_make1(x1)
Definition: pg_list.h:139
char * at_relname
Definition: autovacuum.c:198
static void autovac_report_activity(autovac_table *tab)
Definition: autovacuum.c:3112
char * at_nspname
Definition: autovacuum.c:199
VacuumParams at_params
Definition: autovacuum.c:193
Definition: pg_list.h:45
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:419
bool AutoVacuumingActive ( void  )

Definition at line 3187 of file autovacuum.c.

References autovacuum_start_daemon, and pgstat_track_counts.

Referenced by AutoVacLauncherMain(), reaper(), relation_needs_vacanalyze(), and ServerLoop().

3188 {
3190  return false;
3191  return true;
3192 }
bool autovacuum_start_daemon
Definition: autovacuum.c:114
bool pgstat_track_counts
Definition: pgstat.c:126
void AutoVacuumRequestWork ( AutoVacuumWorkItemType  type,
Oid  relationId,
BlockNumber  blkno 
)

Definition at line 3198 of file autovacuum.c.

References AutoVacuumShmemStruct::av_workItems, AutoVacuumWorkItem::avw_active, AutoVacuumWorkItem::avw_blockNumber, AutoVacuumWorkItem::avw_database, AutoVacuumWorkItem::avw_relation, AutoVacuumWorkItem::avw_type, AutoVacuumWorkItem::avw_used, i, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyDatabaseId, and NUM_WORKITEMS.

Referenced by brininsert().

3200 {
3201  int i;
3202 
3203  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3204 
3205  /*
3206  * Locate an unused work item and fill it with the given data.
3207  */
3208  for (i = 0; i < NUM_WORKITEMS; i++)
3209  {
3211 
3212  if (workitem->avw_used)
3213  continue;
3214 
3215  workitem->avw_used = true;
3216  workitem->avw_active = false;
3217  workitem->avw_type = type;
3218  workitem->avw_database = MyDatabaseId;
3219  workitem->avw_relation = relationId;
3220  workitem->avw_blockNumber = blkno;
3221 
3222  /* done */
3223  break;
3224  }
3225 
3226  LWLockRelease(AutovacuumLock);
3227 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:257
#define NUM_WORKITEMS
Definition: autovacuum.c:265
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:290
Oid MyDatabaseId
Definition: globals.c:77
BlockNumber avw_blockNumber
Definition: autovacuum.c:262
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
int i
void AutoVacuumShmemInit ( void  )

Definition at line 3286 of file autovacuum.c.

References Assert, autovacuum_max_workers, AutoVacuumShmemSize(), AutoVacuumShmemStruct::av_freeWorkers, AutoVacuumShmemStruct::av_launcherpid, AutoVacuumShmemStruct::av_runningWorkers, AutoVacuumShmemStruct::av_startingWorker, AutoVacuumShmemStruct::av_workItems, dlist_init(), dlist_push_head(), i, IsUnderPostmaster, MAXALIGN, NUM_WORKITEMS, ShmemInitStruct(), and WorkerInfoData::wi_links.

Referenced by CreateSharedMemoryAndSemaphores().

3287 {
3288  bool found;
3289 
3291  ShmemInitStruct("AutoVacuum Data",
3293  &found);
3294 
3295  if (!IsUnderPostmaster)
3296  {
3297  WorkerInfo worker;
3298  int i;
3299 
3300  Assert(!found);
3301 
3306  memset(AutoVacuumShmem->av_workItems, 0,
3307  sizeof(AutoVacuumWorkItem) * NUM_WORKITEMS);
3308 
3309  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3310  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3311 
3312  /* initialize the WorkerInfo free list */
3313  for (i = 0; i < autovacuum_max_workers; i++)
3315  &worker[i].wi_links);
3316  }
3317  else
3318  Assert(found);
3319 }
#define NUM_WORKITEMS
Definition: autovacuum.c:265
WorkerInfo av_startingWorker
Definition: autovacuum.c:289
dlist_head av_freeWorkers
Definition: autovacuum.c:287
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
struct WorkerInfoData * WorkerInfo
Definition: autovacuum.c:235
dlist_node wi_links
Definition: autovacuum.c:223
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:290
bool IsUnderPostmaster
Definition: globals.c:101
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3267
int autovacuum_max_workers
Definition: autovacuum.c:115
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define Assert(condition)
Definition: c.h:681
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
#define MAXALIGN(LEN)
Definition: c.h:576
int i
dlist_head av_runningWorkers
Definition: autovacuum.c:288
Size AutoVacuumShmemSize ( void  )

Definition at line 3267 of file autovacuum.c.

References add_size(), autovacuum_max_workers, MAXALIGN, and mul_size().

Referenced by AutoVacuumShmemInit(), and CreateSharedMemoryAndSemaphores().

3268 {
3269  Size size;
3270 
3271  /*
3272  * Need the fixed struct and the array of WorkerInfoData.
3273  */
3274  size = sizeof(AutoVacuumShmemStruct);
3275  size = MAXALIGN(size);
3277  sizeof(WorkerInfoData)));
3278  return size;
3279 }
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
int autovacuum_max_workers
Definition: autovacuum.c:115
size_t Size
Definition: c.h:350
#define MAXALIGN(LEN)
Definition: c.h:576
void AutoVacuumUpdateDelay ( void  )

Definition at line 1760 of file autovacuum.c.

References VacuumCostDelay, VacuumCostLimit, WorkerInfoData::wi_cost_delay, and WorkerInfoData::wi_cost_limit.

Referenced by do_autovacuum(), and vacuum_delay_point().

1761 {
1762  if (MyWorkerInfo)
1763  {
1766  }
1767 }
int VacuumCostLimit
Definition: globals.c:131
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:303
int VacuumCostDelay
Definition: globals.c:132
void AutoVacWorkerFailed ( void  )

Definition at line 1393 of file autovacuum.c.

References AutoVacForkFailed, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

1394 {
1396 }
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:285
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
NON_EXEC_STATIC void AutoVacWorkerMain ( int  argc,
char *  argv[] 
)

Definition at line 1515 of file autovacuum.c.

References am_autovacuum_worker, AutoVacuumShmemStruct::av_launcherpid, AutoVacuumShmemStruct::av_runningWorkers, av_sighup_handler(), AutoVacuumShmemStruct::av_startingWorker, B_AUTOVAC_WORKER, BaseInit(), dbname, DEBUG1, die(), dlist_push_head(), do_autovacuum(), elog, EmitErrorReport(), ereport, errmsg(), FloatExceptionHandler(), FreeWorkerInfo(), HOLD_INTERRUPTS, init_ps_display(), InitializeTimeouts(), InitPostgres(), InitProcess(), InitProcessing, InvalidOid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProc, NAMEDATALEN, NormalProcessing, OidIsValid, on_shmem_exit(), PG_exception_stack, PG_SETMASK, pg_usleep(), PGC_S_OVERRIDE, PGC_SUSET, pgstat_get_backend_desc(), pgstat_report_autovac(), PostAuthDelay, pqsignal(), proc_exit(), procsignal_sigusr1_handler(), quickdie(), ReadNewTransactionId(), ReadNextMultiXactId(), recentMulti, recentXid, set_ps_display(), SetConfigOption(), SetProcessingMode, SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, StatementCancelHandler(), synchronous_commit, SYNCHRONOUS_COMMIT_LOCAL_FLUSH, UnBlockSig, WARNING, WorkerInfoData::wi_dboid, WorkerInfoData::wi_links, and WorkerInfoData::wi_proc.

Referenced by StartAutoVacWorker().

1516 {
1517  sigjmp_buf local_sigjmp_buf;
1518  Oid dbid;
1519 
1520  am_autovacuum_worker = true;
1521 
1522  /* Identify myself via ps */
1524 
1526 
1527  /*
1528  * Set up signal handlers. We operate on databases much like a regular
1529  * backend, so we use the same signal handling. See equivalent code in
1530  * tcop/postgres.c.
1531  */
1533 
1534  /*
1535  * SIGINT is used to signal canceling the current table's vacuum; SIGTERM
1536  * means abort and exit cleanly, and SIGQUIT means abandon ship.
1537  */
1539  pqsignal(SIGTERM, die);
1541  InitializeTimeouts(); /* establishes SIGALRM handler */
1542 
1548 
1549  /* Early initialization */
1550  BaseInit();
1551 
1552  /*
1553  * Create a per-backend PGPROC struct in shared memory, except in the
1554  * EXEC_BACKEND case where this was done in SubPostmasterMain. We must do
1555  * this before we can use LWLocks (and in the EXEC_BACKEND case we already
1556  * had to do some stuff with LWLocks).
1557  */
1558 #ifndef EXEC_BACKEND
1559  InitProcess();
1560 #endif
1561 
1562  /*
1563  * If an exception is encountered, processing resumes here.
1564  *
1565  * See notes in postgres.c about the design of this coding.
1566  */
1567  if (sigsetjmp(local_sigjmp_buf, 1) != 0)
1568  {
1569  /* Prevents interrupts while cleaning up */
1570  HOLD_INTERRUPTS();
1571 
1572  /* Report the error to the server log */
1573  EmitErrorReport();
1574 
1575  /*
1576  * We can now go away. Note that because we called InitProcess, a
1577  * callback was registered to do ProcKill, which will clean up
1578  * necessary state.
1579  */
1580  proc_exit(0);
1581  }
1582 
1583  /* We can now handle ereport(ERROR) */
1584  PG_exception_stack = &local_sigjmp_buf;
1585 
1587 
1588  /*
1589  * Force zero_damaged_pages OFF in the autovac process, even if it is set
1590  * in postgresql.conf. We don't really want such a dangerous option being
1591  * applied non-interactively.
1592  */
1593  SetConfigOption("zero_damaged_pages", "false", PGC_SUSET, PGC_S_OVERRIDE);
1594 
1595  /*
1596  * Force settable timeouts off to avoid letting these settings prevent
1597  * regular maintenance from being executed.
1598  */
1599  SetConfigOption("statement_timeout", "0", PGC_SUSET, PGC_S_OVERRIDE);
1600  SetConfigOption("lock_timeout", "0", PGC_SUSET, PGC_S_OVERRIDE);
1601  SetConfigOption("idle_in_transaction_session_timeout", "0",
1603 
1604  /*
1605  * Force default_transaction_isolation to READ COMMITTED. We don't want
1606  * to pay the overhead of serializable mode, nor add any risk of causing
1607  * deadlocks or delaying other transactions.
1608  */
1609  SetConfigOption("default_transaction_isolation", "read committed",
1611 
1612  /*
1613  * Force synchronous replication off to allow regular maintenance even if
1614  * we are waiting for standbys to connect. This is important to ensure we
1615  * aren't blocked from performing anti-wraparound tasks.
1616  */
1618  SetConfigOption("synchronous_commit", "local",
1620 
1621  /*
1622  * Get the info about the database we're going to work on.
1623  */
1624  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
1625 
1626  /*
1627  * beware of startingWorker being INVALID; this should normally not
1628  * happen, but if a worker fails after forking and before this, the
1629  * launcher might have decided to remove it from the queue and start
1630  * again.
1631  */
1632  if (AutoVacuumShmem->av_startingWorker != NULL)
1633  {
1635  dbid = MyWorkerInfo->wi_dboid;
1637 
1638  /* insert into the running list */
1641 
1642  /*
1643  * remove from the "starting" pointer, so that the launcher can start
1644  * a new worker if required
1645  */
1647  LWLockRelease(AutovacuumLock);
1648 
1650 
1651  /* wake up the launcher */
1652  if (AutoVacuumShmem->av_launcherpid != 0)
1654  }
1655  else
1656  {
1657  /* no worker entry for me, go away */
1658  elog(WARNING, "autovacuum worker started without a worker entry");
1659  dbid = InvalidOid;
1660  LWLockRelease(AutovacuumLock);
1661  }
1662 
1663  if (OidIsValid(dbid))
1664  {
1665  char dbname[NAMEDATALEN];
1666 
1667  /*
1668  * Report autovac startup to the stats collector. We deliberately do
1669  * this before InitPostgres, so that the last_autovac_time will get
1670  * updated even if the connection attempt fails. This is to prevent
1671  * autovac from getting "stuck" repeatedly selecting an unopenable
1672  * database, rather than making any progress on stuff it can connect
1673  * to.
1674  */
1675  pgstat_report_autovac(dbid);
1676 
1677  /*
1678  * Connect to the selected database
1679  *
1680  * Note: if we have selected a just-deleted database (due to using
1681  * stale stats info), we'll fail and exit here.
1682  */
1683  InitPostgres(NULL, dbid, NULL, InvalidOid, dbname);
1685  set_ps_display(dbname, false);
1686  ereport(DEBUG1,
1687  (errmsg("autovacuum: processing database \"%s\"", dbname)));
1688 
1689  if (PostAuthDelay)
1690  pg_usleep(PostAuthDelay * 1000000L);
1691 
1692  /* And do an appropriate amount of work */
1695  do_autovacuum();
1696  }
1697 
1698  /*
1699  * The launcher will be notified of my death in ProcKill, *if* we managed
1700  * to get a worker slot at all
1701  */
1702 
1703  /* All done, go away */
1704  proc_exit(0);
1705 }
static bool am_autovacuum_worker
Definition: autovacuum.c:139
void InitializeTimeouts(void)
Definition: timeout.c:340
#define SIGUSR1
Definition: win32.h:202
#define DEBUG1
Definition: elog.h:25
WorkerInfo av_startingWorker
Definition: autovacuum.c:289
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
static void do_autovacuum(void)
Definition: autovacuum.c:1930
PGPROC * MyProc
Definition: proc.c:67
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4044
static MultiXactId recentMulti
Definition: autovacuum.c:148
void set_ps_display(const char *activity, bool force)
Definition: ps_status.c:326
void proc_exit(int code)
Definition: ipc.c:99
#define SetProcessingMode(mode)
Definition: miscadmin.h:373
void BaseInit(void)
Definition: postinit.c:518
dlist_node wi_links
Definition: autovacuum.c:223
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define SIGQUIT
Definition: win32.h:189
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
void StatementCancelHandler(SIGNAL_ARGS)
Definition: postgres.c:2683
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
#define NAMEDATALEN
void pg_usleep(long microsec)
Definition: signal.c:53
#define SIG_IGN
Definition: win32.h:185
Definition: guc.h:75
void InitProcess(void)
Definition: proc.c:288
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:348
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6681
TransactionId ReadNewTransactionId(void)
Definition: varsup.c:250
sigset_t UnBlockSig
Definition: pqsignal.c:22
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:303
int synchronous_commit
Definition: xact.c:82
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
int PostAuthDelay
Definition: postgres.c:99
static TransactionId recentXid
Definition: autovacuum.c:147
void EmitErrorReport(void)
Definition: elog.c:1446
#define SIGPIPE
Definition: win32.h:193
#define SIGHUP
Definition: win32.h:188
#define InvalidOid
Definition: postgres_ext.h:36
#define SIG_DFL
Definition: win32.h:183
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
char * dbname
Definition: streamutil.c:42
static void FreeWorkerInfo(int code, Datum arg)
Definition: autovacuum.c:1711
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
static void av_sighup_handler(SIGNAL_ARGS)
Definition: autovacuum.c:1400
sigjmp_buf * PG_exception_stack
Definition: elog.c:90
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname)
Definition: postinit.c:559
int errmsg(const char *fmt,...)
Definition: elog.c:797
void die(SIGNAL_ARGS)
Definition: postgres.c:2652
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:115
void FloatExceptionHandler(SIGNAL_ARGS)
Definition: postgres.c:2704
PGPROC * wi_proc
Definition: autovacuum.c:226
#define elog
Definition: elog.h:219
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:261
dlist_head av_runningWorkers
Definition: autovacuum.c:288
#define SIGCHLD
Definition: win32.h:198
void pgstat_report_autovac(Oid dboid)
Definition: pgstat.c:1383
void quickdie(SIGNAL_ARGS)
Definition: postgres.c:2591
#define SIGUSR2
Definition: win32.h:203
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:244
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:721
static void av_sighup_handler ( SIGNAL_ARGS  )
static

Definition at line 1400 of file autovacuum.c.

References got_SIGHUP, MyLatch, and SetLatch().

Referenced by AutoVacLauncherMain(), and AutoVacWorkerMain().

1401 {
1402  int save_errno = errno;
1403 
1404  got_SIGHUP = true;
1405  SetLatch(MyLatch);
1406 
1407  errno = save_errno;
1408 }
static volatile sig_atomic_t got_SIGHUP
Definition: autovacuum.c:142
void SetLatch(volatile Latch *latch)
Definition: latch.c:414
struct Latch * MyLatch
Definition: globals.c:52
static void avl_sigterm_handler ( SIGNAL_ARGS  )
static

Definition at line 1424 of file autovacuum.c.

References got_SIGTERM, MyLatch, and SetLatch().

Referenced by AutoVacLauncherMain().

1425 {
1426  int save_errno = errno;
1427 
1428  got_SIGTERM = true;
1429  SetLatch(MyLatch);
1430 
1431  errno = save_errno;
1432 }
static volatile sig_atomic_t got_SIGTERM
Definition: autovacuum.c:144
void SetLatch(volatile Latch *latch)
Definition: latch.c:414
struct Latch * MyLatch
Definition: globals.c:52
static void avl_sigusr2_handler ( SIGNAL_ARGS  )
static

Definition at line 1412 of file autovacuum.c.

References got_SIGUSR2, MyLatch, and SetLatch().

Referenced by AutoVacLauncherMain().

1413 {
1414  int save_errno = errno;
1415 
1416  got_SIGUSR2 = true;
1417  SetLatch(MyLatch);
1418 
1419  errno = save_errno;
1420 }
static volatile sig_atomic_t got_SIGUSR2
Definition: autovacuum.c:143
void SetLatch(volatile Latch *latch)
Definition: latch.c:414
struct Latch * MyLatch
Definition: globals.c:52
static int db_comparator ( const void *  a,
const void *  b 
)
static

Definition at line 1106 of file autovacuum.c.

Referenced by rebuild_database_list().

1107 {
1108  if (((const avl_dbase *) a)->adl_score == ((const avl_dbase *) b)->adl_score)
1109  return 0;
1110  else
1111  return (((const avl_dbase *) a)->adl_score < ((const avl_dbase *) b)->adl_score) ? 1 : -1;
1112 }
static void do_autovacuum ( void  )
static

Definition at line 1930 of file autovacuum.c.

References AbortOutOfAnyTransaction(), AccessExclusiveLock, AccessShareLock, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), Anum_pg_class_relkind, av_relation::ar_hasrelopts, av_relation::ar_relid, av_relation::ar_reloptions, autovac_table::at_datname, autovac_table::at_dobalance, autovac_table::at_nspname, autovac_table::at_relid, autovac_table::at_relname, autovac_table::at_sharedrel, autovac_table::at_vacoptions, autovac_table::at_vacuum_cost_delay, autovac_table::at_vacuum_cost_limit, autovac_balance_cost(), autovacuum_do_vac_analyze(), AutoVacuumUpdateDelay(), AutoVacuumShmemStruct::av_runningWorkers, AutoVacuumShmemStruct::av_workItems, AutoVacuumWorkItem::avw_active, AutoVacuumWorkItem::avw_used, BackendIdGetProc(), BAS_VACUUM, BTEqualStrategyNumber, CharGetDatum, CHECK_FOR_INTERRUPTS, CommitTransactionCommand(), ConditionalLockRelationOid(), CreateTupleDescCopy(), dlist_iter::cur, DATABASEOID, default_freeze_min_age, default_freeze_table_age, default_multixact_freeze_min_age, default_multixact_freeze_table_age, dlist_container, dlist_foreach, DROP_CASCADE, elog, EmitErrorReport(), HASHCTL::entrysize, ereport, errcontext, errmsg(), ERROR, extract_autovac_opts(), FlushErrorState(), ForwardScanDirection, get_database_name(), get_namespace_name(), get_pgstat_tabentry_relid(), get_rel_name(), get_rel_namespace(), GetAccessStrategy(), GETSTRUCT, GetTempNamespaceBackendId(), got_SIGHUP, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, HASH_FIND, hash_search(), heap_beginscan_catalog(), heap_close, heap_endscan(), heap_getnext(), heap_open(), HeapTupleGetOid, HeapTupleIsValid, HOLD_INTERRUPTS, i, InvalidBackendId, InvalidOid, HASHCTL::keysize, lappend_oid(), lfirst_oid, LOG, LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), MemoryContextResetAndDeleteChildren, MemoryContextSwitchTo(), MemSet, MultiXactMemberFreezeThreshold(), MyBackendId, MyDatabaseId, NameStr, NIL, NUM_WORKITEMS, ObjectIdGetDatum, OidIsValid, PERFORM_DELETION_INTERNAL, PERFORM_DELETION_QUIETLY, PERFORM_DELETION_SKIP_EXTENSIONS, perform_work_item(), performDeletion(), pfree(), PG_CATCH, PG_END_TRY, PG_TRY, PGC_SIGHUP, pgstat_fetch_stat_dbentry(), pgstat_vacuum_stat(), PortalContext, ProcessConfigFile(), QueryCancelPending, relation_needs_vacanalyze(), RelationGetDescr, RelationRelationId, ReleaseSysCache(), RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_TOASTVALUE, RELOID, RELPERSISTENCE_TEMP, RESUME_INTERRUPTS, ScanKeyInit(), SearchSysCache1(), SearchSysCacheCopy1, StartTransactionCommand(), table_recheck_autovac(), TopMemoryContext, UnlockRelationOid(), vac_update_datfrozenxid(), VACOPT_VACUUM, vacuum_freeze_min_age, vacuum_freeze_table_age, vacuum_multixact_freeze_min_age, vacuum_multixact_freeze_table_age, VacuumCostDelay, VacuumCostLimit, WorkerInfoData::wi_cost_delay, WorkerInfoData::wi_cost_limit, WorkerInfoData::wi_cost_limit_base, WorkerInfoData::wi_dboid, WorkerInfoData::wi_dobalance, WorkerInfoData::wi_sharedrel, and WorkerInfoData::wi_tableoid.

Referenced by AutoVacWorkerMain().

1931 {
1932  Relation classRel;
1933  HeapTuple tuple;
1934  HeapScanDesc relScan;
1935  Form_pg_database dbForm;
1936  List *table_oids = NIL;
1937  List *orphan_oids = NIL;
1938  HASHCTL ctl;
1939  HTAB *table_toast_map;
1940  ListCell *volatile cell;
1941  PgStat_StatDBEntry *shared;
1942  PgStat_StatDBEntry *dbentry;
1943  BufferAccessStrategy bstrategy;
1944  ScanKeyData key;
1945  TupleDesc pg_class_desc;
1946  int effective_multixact_freeze_max_age;
1947  bool did_vacuum = false;
1948  bool found_concurrent_worker = false;
1949  int i;
1950 
1951  /*
1952  * StartTransactionCommand and CommitTransactionCommand will automatically
1953  * switch to other contexts. We need this one to keep the list of
1954  * relations to vacuum/analyze across transactions.
1955  */
1957  "AV worker",
1960 
1961  /*
1962  * may be NULL if we couldn't find an entry (only happens if we are
1963  * forcing a vacuum for anti-wrap purposes).
1964  */
1966 
1967  /* Start a transaction so our commands have one to play into. */
1969 
1970  /*
1971  * Clean up any dead statistics collector entries for this DB. We always
1972  * want to do this exactly once per DB-processing cycle, even if we find
1973  * nothing worth vacuuming in the database.
1974  */
1976 
1977  /*
1978  * Compute the multixact age for which freezing is urgent. This is
1979  * normally autovacuum_multixact_freeze_max_age, but may be less if we are
1980  * short of multixact member space.
1981  */
1982  effective_multixact_freeze_max_age = MultiXactMemberFreezeThreshold();
1983 
1984  /*
1985  * Find the pg_database entry and select the default freeze ages. We use
1986  * zero in template and nonconnectable databases, else the system-wide
1987  * default.
1988  */
1990  if (!HeapTupleIsValid(tuple))
1991  elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
1992  dbForm = (Form_pg_database) GETSTRUCT(tuple);
1993 
1994  if (dbForm->datistemplate || !dbForm->datallowconn)
1995  {
2000  }
2001  else
2002  {
2007  }
2008 
2009  ReleaseSysCache(tuple);
2010 
2011  /* StartTransactionCommand changed elsewhere */
2013 
2014  /* The database hash where pgstat keeps shared relations */
2016 
2018 
2019  /* create a copy so we can use it after closing pg_class */
2020  pg_class_desc = CreateTupleDescCopy(RelationGetDescr(classRel));
2021 
2022  /* create hash table for toast <-> main relid mapping */
2023  MemSet(&ctl, 0, sizeof(ctl));
2024  ctl.keysize = sizeof(Oid);
2025  ctl.entrysize = sizeof(av_relation);
2026 
2027  table_toast_map = hash_create("TOAST to main relid map",
2028  100,
2029  &ctl,
2030  HASH_ELEM | HASH_BLOBS);
2031 
2032  /*
2033  * Scan pg_class to determine which tables to vacuum.
2034  *
2035  * We do this in two passes: on the first one we collect the list of plain
2036  * relations and materialized views, and on the second one we collect
2037  * TOAST tables. The reason for doing the second pass is that during it we
2038  * want to use the main relation's pg_class.reloptions entry if the TOAST
2039  * table does not have any, and we cannot obtain it unless we know
2040  * beforehand what's the main table OID.
2041  *
2042  * We need to check TOAST tables separately because in cases with short,
2043  * wide tables there might be proportionally much more activity in the
2044  * TOAST table than in its parent.
2045  */
2046  relScan = heap_beginscan_catalog(classRel, 0, NULL);
2047 
2048  /*
2049  * On the first pass, we collect main tables to vacuum, and also the main
2050  * table relid to TOAST relid mapping.
2051  */
2052  while ((tuple = heap_getnext(relScan, ForwardScanDirection)) != NULL)
2053  {
2054  Form_pg_class classForm = (Form_pg_class) GETSTRUCT(tuple);
2055  PgStat_StatTabEntry *tabentry;
2056  AutoVacOpts *relopts;
2057  Oid relid;
2058  bool dovacuum;
2059  bool doanalyze;
2060  bool wraparound;
2061 
2062  if (classForm->relkind != RELKIND_RELATION &&
2063  classForm->relkind != RELKIND_MATVIEW)
2064  continue;
2065 
2066  relid = HeapTupleGetOid(tuple);
2067 
2068  /*
2069  * Check if it is a temp table (presumably, of some other backend's).
2070  * We cannot safely process other backends' temp tables.
2071  */
2072  if (classForm->relpersistence == RELPERSISTENCE_TEMP)
2073  {
2074  int backendID;
2075 
2076  backendID = GetTempNamespaceBackendId(classForm->relnamespace);
2077 
2078  /* We just ignore it if the owning backend is still active */
2079  if (backendID != InvalidBackendId &&
2080  (backendID == MyBackendId ||
2081  BackendIdGetProc(backendID) == NULL))
2082  {
2083  /*
2084  * The table seems to be orphaned -- although it might be that
2085  * the owning backend has already deleted it and exited; our
2086  * pg_class scan snapshot is not necessarily up-to-date
2087  * anymore, so we could be looking at a committed-dead entry.
2088  * Remember it so we can try to delete it later.
2089  */
2090  orphan_oids = lappend_oid(orphan_oids, relid);
2091  }
2092  continue;
2093  }
2094 
2095  /* Fetch reloptions and the pgstat entry for this table */
2096  relopts = extract_autovac_opts(tuple, pg_class_desc);
2097  tabentry = get_pgstat_tabentry_relid(relid, classForm->relisshared,
2098  shared, dbentry);
2099 
2100  /* Check if it needs vacuum or analyze */
2101  relation_needs_vacanalyze(relid, relopts, classForm, tabentry,
2102  effective_multixact_freeze_max_age,
2103  &dovacuum, &doanalyze, &wraparound);
2104 
2105  /* Relations that need work are added to table_oids */
2106  if (dovacuum || doanalyze)
2107  table_oids = lappend_oid(table_oids, relid);
2108 
2109  /*
2110  * Remember TOAST associations for the second pass. Note: we must do
2111  * this whether or not the table is going to be vacuumed, because we
2112  * don't automatically vacuum toast tables along the parent table.
2113  */
2114  if (OidIsValid(classForm->reltoastrelid))
2115  {
2116  av_relation *hentry;
2117  bool found;
2118 
2119  hentry = hash_search(table_toast_map,
2120  &classForm->reltoastrelid,
2121  HASH_ENTER, &found);
2122 
2123  if (!found)
2124  {
2125  /* hash_search already filled in the key */
2126  hentry->ar_relid = relid;
2127  hentry->ar_hasrelopts = false;
2128  if (relopts != NULL)
2129  {
2130  hentry->ar_hasrelopts = true;
2131  memcpy(&hentry->ar_reloptions, relopts,
2132  sizeof(AutoVacOpts));
2133  }
2134  }
2135  }
2136  }
2137 
2138  heap_endscan(relScan);
2139 
2140  /* second pass: check TOAST tables */
2141  ScanKeyInit(&key,
2143  BTEqualStrategyNumber, F_CHAREQ,
2145 
2146  relScan = heap_beginscan_catalog(classRel, 1, &key);
2147  while ((tuple = heap_getnext(relScan, ForwardScanDirection)) != NULL)
2148  {
2149  Form_pg_class classForm = (Form_pg_class) GETSTRUCT(tuple);
2150  PgStat_StatTabEntry *tabentry;
2151  Oid relid;
2152  AutoVacOpts *relopts = NULL;
2153  bool dovacuum;
2154  bool doanalyze;
2155  bool wraparound;
2156 
2157  /*
2158  * We cannot safely process other backends' temp tables, so skip 'em.
2159  */
2160  if (classForm->relpersistence == RELPERSISTENCE_TEMP)
2161  continue;
2162 
2163  relid = HeapTupleGetOid(tuple);
2164 
2165  /*
2166  * fetch reloptions -- if this toast table does not have them, try the
2167  * main rel
2168  */
2169  relopts = extract_autovac_opts(tuple, pg_class_desc);
2170  if (relopts == NULL)
2171  {
2172  av_relation *hentry;
2173  bool found;
2174 
2175  hentry = hash_search(table_toast_map, &relid, HASH_FIND, &found);
2176  if (found && hentry->ar_hasrelopts)
2177  relopts = &hentry->ar_reloptions;
2178  }
2179 
2180  /* Fetch the pgstat entry for this table */
2181  tabentry = get_pgstat_tabentry_relid(relid, classForm->relisshared,
2182  shared, dbentry);
2183 
2184  relation_needs_vacanalyze(relid, relopts, classForm, tabentry,
2185  effective_multixact_freeze_max_age,
2186  &dovacuum, &doanalyze, &wraparound);
2187 
2188  /* ignore analyze for toast tables */
2189  if (dovacuum)
2190  table_oids = lappend_oid(table_oids, relid);
2191  }
2192 
2193  heap_endscan(relScan);
2194  heap_close(classRel, AccessShareLock);
2195 
2196  /*
2197  * Recheck orphan temporary tables, and if they still seem orphaned, drop
2198  * them. We'll eat a transaction per dropped table, which might seem
2199  * excessive, but we should only need to do anything as a result of a
2200  * previous backend crash, so this should not happen often enough to
2201  * justify "optimizing". Using separate transactions ensures that we
2202  * don't bloat the lock table if there are many temp tables to be dropped,
2203  * and it ensures that we don't lose work if a deletion attempt fails.
2204  */
2205  foreach(cell, orphan_oids)
2206  {
2207  Oid relid = lfirst_oid(cell);
2208  Form_pg_class classForm;
2209  int backendID;
2210  ObjectAddress object;
2211 
2212  /*
2213  * Check for user-requested abort.
2214  */
2216 
2217  /*
2218  * Try to lock the table. If we can't get the lock immediately,
2219  * somebody else is using (or dropping) the table, so it's not our
2220  * concern anymore. Having the lock prevents race conditions below.
2221  */
2223  continue;
2224 
2225  /*
2226  * Re-fetch the pg_class tuple and re-check whether it still seems to
2227  * be an orphaned temp table. If it's not there or no longer the same
2228  * relation, ignore it.
2229  */
2230  tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relid));
2231  if (!HeapTupleIsValid(tuple))
2232  {
2233  /* be sure to drop useless lock so we don't bloat lock table */
2235  continue;
2236  }
2237  classForm = (Form_pg_class) GETSTRUCT(tuple);
2238 
2239  /*
2240  * Make all the same tests made in the loop above. In event of OID
2241  * counter wraparound, the pg_class entry we have now might be
2242  * completely unrelated to the one we saw before.
2243  */
2244  if (!((classForm->relkind == RELKIND_RELATION ||
2245  classForm->relkind == RELKIND_MATVIEW) &&
2246  classForm->relpersistence == RELPERSISTENCE_TEMP))
2247  {
2249  continue;
2250  }
2251  backendID = GetTempNamespaceBackendId(classForm->relnamespace);
2252  if (!(backendID != InvalidBackendId &&
2253  (backendID == MyBackendId ||
2254  BackendIdGetProc(backendID) == NULL)))
2255  {
2257  continue;
2258  }
2259 
2260  /* OK, let's delete it */
2261  ereport(LOG,
2262  (errmsg("autovacuum: dropping orphan temp table \"%s.%s.%s\"",
2264  get_namespace_name(classForm->relnamespace),
2265  NameStr(classForm->relname))));
2266 
2267  object.classId = RelationRelationId;
2268  object.objectId = relid;
2269  object.objectSubId = 0;
2270  performDeletion(&object, DROP_CASCADE,
2274 
2275  /*
2276  * To commit the deletion, end current transaction and start a new
2277  * one. Note this also releases the lock we took.
2278  */
2281 
2282  /* StartTransactionCommand changed current memory context */
2284  }
2285 
2286  /*
2287  * Create a buffer access strategy object for VACUUM to use. We want to
2288  * use the same one across all the vacuum operations we perform, since the
2289  * point is for VACUUM not to blow out the shared cache.
2290  */
2291  bstrategy = GetAccessStrategy(BAS_VACUUM);
2292 
2293  /*
2294  * create a memory context to act as fake PortalContext, so that the
2295  * contexts created in the vacuum code are cleaned up for each table.
2296  */
2298  "Autovacuum Portal",
2300 
2301  /*
2302  * Perform operations on collected tables.
2303  */
2304  foreach(cell, table_oids)
2305  {
2306  Oid relid = lfirst_oid(cell);
2307  autovac_table *tab;
2308  bool skipit;
2309  int stdVacuumCostDelay;
2310  int stdVacuumCostLimit;
2311  dlist_iter iter;
2312 
2314 
2315  /*
2316  * Check for config changes before processing each collected table.
2317  */
2318  if (got_SIGHUP)
2319  {
2320  got_SIGHUP = false;
2322 
2323  /*
2324  * You might be tempted to bail out if we see autovacuum is now
2325  * disabled. Must resist that temptation -- this might be a
2326  * for-wraparound emergency worker, in which case that would be
2327  * entirely inappropriate.
2328  */
2329  }
2330 
2331  /*
2332  * hold schedule lock from here until we're sure that this table still
2333  * needs vacuuming. We also need the AutovacuumLock to walk the
2334  * worker array, but we'll let go of that one quickly.
2335  */
2336  LWLockAcquire(AutovacuumScheduleLock, LW_EXCLUSIVE);
2337  LWLockAcquire(AutovacuumLock, LW_SHARED);
2338 
2339  /*
2340  * Check whether the table is being vacuumed concurrently by another
2341  * worker.
2342  */
2343  skipit = false;
2345  {
2346  WorkerInfo worker = dlist_container(WorkerInfoData, wi_links, iter.cur);
2347 
2348  /* ignore myself */
2349  if (worker == MyWorkerInfo)
2350  continue;
2351 
2352  /* ignore workers in other databases (unless table is shared) */
2353  if (!worker->wi_sharedrel && worker->wi_dboid != MyDatabaseId)
2354  continue;
2355 
2356  if (worker->wi_tableoid == relid)
2357  {
2358  skipit = true;
2359  found_concurrent_worker = true;
2360  break;
2361  }
2362  }
2363  LWLockRelease(AutovacuumLock);
2364  if (skipit)
2365  {
2366  LWLockRelease(AutovacuumScheduleLock);
2367  continue;
2368  }
2369 
2370  /*
2371  * Check whether pgstat data still says we need to vacuum this table.
2372  * It could have changed if something else processed the table while
2373  * we weren't looking.
2374  *
2375  * Note: we have a special case in pgstat code to ensure that the
2376  * stats we read are as up-to-date as possible, to avoid the problem
2377  * that somebody just finished vacuuming this table. The window to
2378  * the race condition is not closed but it is very small.
2379  */
2381  tab = table_recheck_autovac(relid, table_toast_map, pg_class_desc,
2382  effective_multixact_freeze_max_age);
2383  if (tab == NULL)
2384  {
2385  /* someone else vacuumed the table, or it went away */
2386  LWLockRelease(AutovacuumScheduleLock);
2387  continue;
2388  }
2389 
2390  /*
2391  * Ok, good to go. Store the table in shared memory before releasing
2392  * the lock so that other workers don't vacuum it concurrently.
2393  */
2394  MyWorkerInfo->wi_tableoid = relid;
2396  LWLockRelease(AutovacuumScheduleLock);
2397 
2398  /*
2399  * Remember the prevailing values of the vacuum cost GUCs. We have to
2400  * restore these at the bottom of the loop, else we'll compute wrong
2401  * values in the next iteration of autovac_balance_cost().
2402  */
2403  stdVacuumCostDelay = VacuumCostDelay;
2404  stdVacuumCostLimit = VacuumCostLimit;
2405 
2406  /* Must hold AutovacuumLock while mucking with cost balance info */
2407  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
2408 
2409  /* advertise my cost delay parameters for the balancing algorithm */
2414 
2415  /* do a balance */
2417 
2418  /* set the active cost parameters from the result of that */
2420 
2421  /* done */
2422  LWLockRelease(AutovacuumLock);
2423 
2424  /* clean up memory before each iteration */
2426 
2427  /*
2428  * Save the relation name for a possible error message, to avoid a
2429  * catalog lookup in case of an error. If any of these return NULL,
2430  * then the relation has been dropped since last we checked; skip it.
2431  * Note: they must live in a long-lived memory context because we call
2432  * vacuum and analyze in different transactions.
2433  */
2434 
2435  tab->at_relname = get_rel_name(tab->at_relid);
2438  if (!tab->at_relname || !tab->at_nspname || !tab->at_datname)
2439  goto deleted;
2440 
2441  /*
2442  * We will abort vacuuming the current table if something errors out,
2443  * and continue with the next one in schedule; in particular, this
2444  * happens if we are interrupted with SIGINT.
2445  */
2446  PG_TRY();
2447  {
2448  /* Use PortalContext for any per-table allocations */
2450 
2451  /* have at it */
2452  autovacuum_do_vac_analyze(tab, bstrategy);
2453 
2454  /*
2455  * Clear a possible query-cancel signal, to avoid a late reaction
2456  * to an automatically-sent signal because of vacuuming the
2457  * current table (we're done with it, so it would make no sense to
2458  * cancel at this point.)
2459  */
2460  QueryCancelPending = false;
2461  }
2462  PG_CATCH();
2463  {
2464  /*
2465  * Abort the transaction, start a new one, and proceed with the
2466  * next table in our list.
2467  */
2468  HOLD_INTERRUPTS();
2469  if (tab->at_vacoptions & VACOPT_VACUUM)
2470  errcontext("automatic vacuum of table \"%s.%s.%s\"",
2471  tab->at_datname, tab->at_nspname, tab->at_relname);
2472  else
2473  errcontext("automatic analyze of table \"%s.%s.%s\"",
2474  tab->at_datname, tab->at_nspname, tab->at_relname);
2475  EmitErrorReport();
2476 
2477  /* this resets the PGXACT flags too */
2479  FlushErrorState();
2481 
2482  /* restart our transaction for the following operations */
2485  }
2486  PG_END_TRY();
2487 
2488  /* Make sure we're back in AutovacMemCxt */
2490 
2491  did_vacuum = true;
2492 
2493  /* the PGXACT flags are reset at the next end of transaction */
2494 
2495  /* be tidy */
2496 deleted:
2497  if (tab->at_datname != NULL)
2498  pfree(tab->at_datname);
2499  if (tab->at_nspname != NULL)
2500  pfree(tab->at_nspname);
2501  if (tab->at_relname != NULL)
2502  pfree(tab->at_relname);
2503  pfree(tab);
2504 
2505  /*
2506  * Remove my info from shared memory. We could, but intentionally
2507  * don't, clear wi_cost_limit and friends --- this is on the
2508  * assumption that we probably have more to do with similar cost
2509  * settings, so we don't want to give up our share of I/O for a very
2510  * short interval and thereby thrash the global balance.
2511  */
2512  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
2514  MyWorkerInfo->wi_sharedrel = false;
2515  LWLockRelease(AutovacuumLock);
2516 
2517  /* restore vacuum cost GUCs for the next iteration */
2518  VacuumCostDelay = stdVacuumCostDelay;
2519  VacuumCostLimit = stdVacuumCostLimit;
2520  }
2521 
2522  /*
2523  * Perform additional work items, as requested by backends.
2524  */
2525  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
2526  for (i = 0; i < NUM_WORKITEMS; i++)
2527  {
2529 
2530  if (!workitem->avw_used)
2531  continue;
2532  if (workitem->avw_active)
2533  continue;
2534 
2535  /* claim this one, and release lock while performing it */
2536  workitem->avw_active = true;
2537  LWLockRelease(AutovacuumLock);
2538 
2539  perform_work_item(workitem);
2540 
2541  /*
2542  * Check for config changes before acquiring lock for further jobs.
2543  */
2545  if (got_SIGHUP)
2546  {
2547  got_SIGHUP = false;
2549  }
2550 
2551  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
2552 
2553  /* and mark it done */
2554  workitem->avw_active = false;
2555  workitem->avw_used = false;
2556  }
2557  LWLockRelease(AutovacuumLock);
2558 
2559  /*
2560  * We leak table_toast_map here (among other things), but since we're
2561  * going away soon, it's not a problem.
2562  */
2563 
2564  /*
2565  * Update pg_database.datfrozenxid, and truncate pg_xact if possible. We
2566  * only need to do this once, not after each table.
2567  *
2568  * Even if we didn't vacuum anything, it may still be important to do
2569  * this, because one indirect effect of vac_update_datfrozenxid() is to
2570  * update ShmemVariableCache->xidVacLimit. That might need to be done
2571  * even if we haven't vacuumed anything, because relations with older
2572  * relfrozenxid values or other databases with older datfrozenxid values
2573  * might have been dropped, allowing xidVacLimit to advance.
2574  *
2575  * However, it's also important not to do this blindly in all cases,
2576  * because when autovacuum=off this will restart the autovacuum launcher.
2577  * If we're not careful, an infinite loop can result, where workers find
2578  * no work to do and restart the launcher, which starts another worker in
2579  * the same database that finds no work to do. To prevent that, we skip
2580  * this if (1) we found no work to do and (2) we skipped at least one
2581  * table due to concurrent autovacuum activity. In that case, the other
2582  * worker has already done it, or will do so when it finishes.
2583  */
2584  if (did_vacuum || !found_concurrent_worker)
2586 
2587  /* Finally close out the last transaction. */
2589 }
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:542
#define NIL
Definition: pg_list.h:69
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:138
static int default_freeze_table_age
Definition: autovacuum.c:152
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:102
BackendId MyBackendId
Definition: globals.c:73
#define NUM_WORKITEMS
Definition: autovacuum.c:265
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
static void autovac_balance_cost(void)
Definition: autovacuum.c:1776
int vacuum_multixact_freeze_table_age
Definition: vacuum.c:62
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
int at_vacuum_cost_delay
Definition: autovacuum.c:194
#define HASH_ELEM
Definition: hsearch.h:87
void ProcessConfigFile(GucContext context)
void vac_update_datfrozenxid(void)
Definition: vacuum.c:1014
static int default_multixact_freeze_min_age
Definition: autovacuum.c:153
#define RelationGetDescr(relation)
Definition: rel.h:428
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:182
FormData_pg_database * Form_pg_database
Definition: pg_database.h:57
#define dlist_foreach(iter, lhead)
Definition: ilist.h:507
void CommitTransactionCommand(void)
Definition: xact.c:2744
#define RelationRelationId
Definition: pg_class.h:29
static MemoryContext AutovacMemCxt
Definition: autovacuum.c:157
Oid get_rel_namespace(Oid relid)
Definition: lsyscache.c:1750
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AccessShareLock
Definition: lockdefs.h:36
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:863
static volatile sig_atomic_t got_SIGHUP
Definition: autovacuum.c:142
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
int GetTempNamespaceBackendId(Oid namespaceId)
Definition: namespace.c:3195
#define heap_close(r, l)
Definition: heapam.h:97
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
char * at_datname
Definition: autovacuum.c:200
#define LOG
Definition: elog.h:26
unsigned int Oid
Definition: postgres_ext.h:31
volatile bool QueryCancelPending
Definition: globals.c:30
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
#define OidIsValid(objectId)
Definition: c.h:532
void AbortOutOfAnyTransaction(void)
Definition: xact.c:4343
void FlushErrorState(void)
Definition: elog.c:1587
MemoryContext PortalContext
Definition: mcxt.c:52
bool at_sharedrel
Definition: autovacuum.c:197
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:117
#define Anum_pg_class_relkind
Definition: pg_class.h:118
int at_vacuum_cost_limit
Definition: autovacuum.c:195
Definition: dynahash.c:208
char * at_relname
Definition: autovacuum.c:198
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
void pfree(void *pointer)
Definition: mcxt.c:949
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
int VacuumCostLimit
Definition: globals.c:131
int vacuum_multixact_freeze_min_age
Definition: vacuum.c:61
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2056
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:290
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
static AutoVacOpts * extract_autovac_opts(HeapTuple tup, TupleDesc pg_class_desc)
Definition: autovacuum.c:2703
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:303
static PgStat_StatTabEntry * get_pgstat_tabentry_relid(Oid relid, bool isshared, PgStat_StatDBEntry *shared, PgStat_StatDBEntry *dbentry)
Definition: autovacuum.c:2729
static void perform_work_item(AutoVacuumWorkItem *workitem)
Definition: autovacuum.c:2595
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:303
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1405
static void relation_needs_vacanalyze(Oid relid, AutoVacOpts *relopts, Form_pg_class classForm, PgStat_StatTabEntry *tabentry, int effective_multixact_freeze_max_age, bool *dovacuum, bool *doanalyze, bool *wraparound)
Definition: autovacuum.c:2938
#define ereport(elevel, rest)
Definition: elog.h:122
void pgstat_vacuum_stat(void)
Definition: pgstat.c:1022
int MultiXactMemberFreezeThreshold(void)
Definition: multixact.c:2817
int wi_cost_limit_base
Definition: autovacuum.c:232
MemoryContext TopMemoryContext
Definition: mcxt.c:43
Definition: guc.h:72
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define MemoryContextResetAndDeleteChildren(ctx)
Definition: memutils.h:67
#define HASH_BLOBS
Definition: hsearch.h:88
char * at_nspname
Definition: autovacuum.c:199
#define InvalidBackendId
Definition: backendid.h:23
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Oid MyDatabaseId
Definition: globals.c:77
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1808
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
Size keysize
Definition: hsearch.h:72
dlist_node * cur
Definition: ilist.h:161
void EmitErrorReport(void)
Definition: elog.c:1446
#define InvalidOid
Definition: postgres_ext.h:36
int VacuumCostDelay
Definition: globals.c:132
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define PERFORM_DELETION_QUIETLY
Definition: dependency.h:176
void StartTransactionCommand(void)
Definition: xact.c:2673
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
int vacuum_freeze_min_age
Definition: vacuum.c:59
int vacuum_freeze_table_age
Definition: vacuum.c:60
#define CharGetDatum(X)
Definition: postgres.h:422
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:173
AutoVacOpts ar_reloptions
Definition: autovacuum.c:184
#define AccessExclusiveLock
Definition: lockdefs.h:45
static void autovacuum_do_vac_analyze(autovac_table *tab, BufferAccessStrategy bstrategy)
Definition: autovacuum.c:3083
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:115
int i
#define errcontext
Definition: elog.h:164
#define NameStr(name)
Definition: c.h:493
struct av_relation av_relation
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
void AutoVacuumUpdateDelay(void)
Definition: autovacuum.c:1760
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
#define RELPERSISTENCE_TEMP
Definition: pg_class.h:172
dlist_head av_runningWorkers
Definition: autovacuum.c:288
#define PG_TRY()
Definition: elog.h:284
#define PERFORM_DELETION_SKIP_EXTENSIONS
Definition: dependency.h:178
#define RELKIND_RELATION
Definition: pg_class.h:160
bool ar_hasrelopts
Definition: autovacuum.c:183
Definition: pg_list.h:45
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1726
static int default_multixact_freeze_table_age
Definition: autovacuum.c:154
static int default_freeze_min_age
Definition: autovacuum.c:151
#define PG_END_TRY()
Definition: elog.h:300
#define BTEqualStrategyNumber
Definition: stratnum.h:31
bool at_dobalance
Definition: autovacuum.c:196
#define lfirst_oid(lc)
Definition: pg_list.h:108
static autovac_table * table_recheck_autovac(Oid relid, HTAB *table_toast_map, TupleDesc pg_class_desc, int effective_multixact_freeze_max_age)
Definition: autovacuum.c:2756
#define PERFORM_DELETION_INTERNAL
Definition: dependency.h:174
PGPROC * BackendIdGetProc(int backendID)
Definition: sinvaladt.c:377
static Oid do_start_worker ( void  )
static

Definition at line 1126 of file autovacuum.c.

References avl_dbase::adl_datid, avl_dbase::adl_next_worker, avw_dbase::adw_datid, avw_dbase::adw_entry, avw_dbase::adw_frozenxid, avw_dbase::adw_minmulti, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), autovac_refresh_stats(), autovacuum_freeze_max_age, autovacuum_naptime, AutoVacuumShmemStruct::av_freeWorkers, AutoVacuumShmemStruct::av_startingWorker, dlist_iter::cur, CurrentMemoryContext, dblist, dlist_container, dlist_is_empty(), dlist_pop_head_node(), dlist_reverse_foreach, FirstMultiXactId, FirstNormalTransactionId, get_database_list(), GetCurrentTimestamp(), InvalidOid, PgStat_StatDBEntry::last_autovac_time, lfirst, LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), MemoryContextDelete(), MemoryContextSwitchTo(), MultiXactIdPrecedes(), MultiXactMemberFreezeThreshold(), pgstat_fetch_stat_dbentry(), PMSIGNAL_START_AUTOVAC_WORKER, ReadNewTransactionId(), ReadNextMultiXactId(), rebuild_database_list(), recentMulti, recentXid, SendPostmasterSignal(), TimestampDifferenceExceeds(), TransactionIdPrecedes(), WorkerInfoData::wi_dboid, WorkerInfoData::wi_launchtime, and WorkerInfoData::wi_proc.

Referenced by AutoVacLauncherMain(), and launch_worker().

1127 {
1128  List *dblist;
1129  ListCell *cell;
1130  TransactionId xidForceLimit;
1131  MultiXactId multiForceLimit;
1132  bool for_xid_wrap;
1133  bool for_multi_wrap;
1134  avw_dbase *avdb;
1135  TimestampTz current_time;
1136  bool skipit = false;
1137  Oid retval = InvalidOid;
1138  MemoryContext tmpcxt,
1139  oldcxt;
1140 
1141  /* return quickly when there are no free workers */
1142  LWLockAcquire(AutovacuumLock, LW_SHARED);
1144  {
1145  LWLockRelease(AutovacuumLock);
1146  return InvalidOid;
1147  }
1148  LWLockRelease(AutovacuumLock);
1149 
1150  /*
1151  * Create and switch to a temporary context to avoid leaking the memory
1152  * allocated for the database list.
1153  */
1155  "Start worker tmp cxt",
1157  oldcxt = MemoryContextSwitchTo(tmpcxt);
1158 
1159  /* use fresh stats */
1161 
1162  /* Get a list of databases */
1163  dblist = get_database_list();
1164 
1165  /*
1166  * Determine the oldest datfrozenxid/relfrozenxid that we will allow to
1167  * pass without forcing a vacuum. (This limit can be tightened for
1168  * particular tables, but not loosened.)
1169  */
1171  xidForceLimit = recentXid - autovacuum_freeze_max_age;
1172  /* ensure it's a "normal" XID, else TransactionIdPrecedes misbehaves */
1173  /* this can cause the limit to go backwards by 3, but that's OK */
1174  if (xidForceLimit < FirstNormalTransactionId)
1175  xidForceLimit -= FirstNormalTransactionId;
1176 
1177  /* Also determine the oldest datminmxid we will consider. */
1179  multiForceLimit = recentMulti - MultiXactMemberFreezeThreshold();
1180  if (multiForceLimit < FirstMultiXactId)
1181  multiForceLimit -= FirstMultiXactId;
1182 
1183  /*
1184  * Choose a database to connect to. We pick the database that was least
1185  * recently auto-vacuumed, or one that needs vacuuming to prevent Xid
1186  * wraparound-related data loss. If any db at risk of Xid wraparound is
1187  * found, we pick the one with oldest datfrozenxid, independently of
1188  * autovacuum times; similarly we pick the one with the oldest datminmxid
1189  * if any is in MultiXactId wraparound. Note that those in Xid wraparound
1190  * danger are given more priority than those in multi wraparound danger.
1191  *
1192  * Note that a database with no stats entry is not considered, except for
1193  * Xid wraparound purposes. The theory is that if no one has ever
1194  * connected to it since the stats were last initialized, it doesn't need
1195  * vacuuming.
1196  *
1197  * XXX This could be improved if we had more info about whether it needs
1198  * vacuuming before connecting to it. Perhaps look through the pgstats
1199  * data for the database's tables? One idea is to keep track of the
1200  * number of new and dead tuples per database in pgstats. However it
1201  * isn't clear how to construct a metric that measures that and not cause
1202  * starvation for less busy databases.
1203  */
1204  avdb = NULL;
1205  for_xid_wrap = false;
1206  for_multi_wrap = false;
1207  current_time = GetCurrentTimestamp();
1208  foreach(cell, dblist)
1209  {
1210  avw_dbase *tmp = lfirst(cell);
1211  dlist_iter iter;
1212 
1213  /* Check to see if this one is at risk of wraparound */
1214  if (TransactionIdPrecedes(tmp->adw_frozenxid, xidForceLimit))
1215  {
1216  if (avdb == NULL ||
1218  avdb->adw_frozenxid))
1219  avdb = tmp;
1220  for_xid_wrap = true;
1221  continue;
1222  }
1223  else if (for_xid_wrap)
1224  continue; /* ignore not-at-risk DBs */
1225  else if (MultiXactIdPrecedes(tmp->adw_minmulti, multiForceLimit))
1226  {
1227  if (avdb == NULL ||
1229  avdb = tmp;
1230  for_multi_wrap = true;
1231  continue;
1232  }
1233  else if (for_multi_wrap)
1234  continue; /* ignore not-at-risk DBs */
1235 
1236  /* Find pgstat entry if any */
1238 
1239  /*
1240  * Skip a database with no pgstat entry; it means it hasn't seen any
1241  * activity.
1242  */
1243  if (!tmp->adw_entry)
1244  continue;
1245 
1246  /*
1247  * Also, skip a database that appears on the database list as having
1248  * been processed recently (less than autovacuum_naptime seconds ago).
1249  * We do this so that we don't select a database which we just
1250  * selected, but that pgstat hasn't gotten around to updating the last
1251  * autovacuum time yet.
1252  */
1253  skipit = false;
1254 
1256  {
1257  avl_dbase *dbp = dlist_container(avl_dbase, adl_node, iter.cur);
1258 
1259  if (dbp->adl_datid == tmp->adw_datid)
1260  {
1261  /*
1262  * Skip this database if its next_worker value falls between
1263  * the current time and the current time plus naptime.
1264  */
1266  current_time, 0) &&
1267  !TimestampDifferenceExceeds(current_time,
1268  dbp->adl_next_worker,
1269  autovacuum_naptime * 1000))
1270  skipit = true;
1271 
1272  break;
1273  }
1274  }
1275  if (skipit)
1276  continue;
1277 
1278  /*
1279  * Remember the db with oldest autovac time. (If we are here, both
1280  * tmp->entry and db->entry must be non-null.)
1281  */
1282  if (avdb == NULL ||
1284  avdb = tmp;
1285  }
1286 
1287  /* Found a database -- process it */
1288  if (avdb != NULL)
1289  {
1290  WorkerInfo worker;
1291  dlist_node *wptr;
1292 
1293  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
1294 
1295  /*
1296  * Get a worker entry from the freelist. We checked above, so there
1297  * really should be a free slot.
1298  */
1300 
1301  worker = dlist_container(WorkerInfoData, wi_links, wptr);
1302  worker->wi_dboid = avdb->adw_datid;
1303  worker->wi_proc = NULL;
1304  worker->wi_launchtime = GetCurrentTimestamp();
1305 
1307 
1308  LWLockRelease(AutovacuumLock);
1309 
1311 
1312  retval = avdb->adw_datid;
1313  }
1314  else if (skipit)
1315  {
1316  /*
1317  * If we skipped all databases on the list, rebuild it, because it
1318  * probably contains a dropped database.
1319  */
1321  }
1322 
1323  MemoryContextSwitchTo(oldcxt);
1324  MemoryContextDelete(tmpcxt);
1325 
1326  return retval;
1327 }
int autovacuum_naptime
Definition: autovacuum.c:117
TimestampTz adl_next_worker
Definition: autovacuum.c:163
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
MultiXactId adw_minmulti
Definition: autovacuum.c:174
WorkerInfo av_startingWorker
Definition: autovacuum.c:289
dlist_head av_freeWorkers
Definition: autovacuum.c:287
uint32 TransactionId
Definition: c.h:391
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1570
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz wi_launchtime
Definition: autovacuum.c:227
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static MultiXactId recentMulti
Definition: autovacuum.c:148
static void autovac_refresh_stats(void)
Definition: autovacuum.c:3334
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
unsigned int Oid
Definition: postgres_ext.h:31
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: timestamp.c:1649
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
#define FirstNormalTransactionId
Definition: transam.h:34
int autovacuum_freeze_max_age
Definition: autovacuum.c:122
static List * get_database_list(void)
Definition: autovacuum.c:1864
Oid adl_datid
Definition: autovacuum.c:162
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
_stringlist * dblist
Definition: pg_regress.c:72
TimestampTz last_autovac_time
Definition: pgstat.h:587
TransactionId ReadNewTransactionId(void)
Definition: varsup.c:250
#define FirstMultiXactId
Definition: multixact.h:24
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
static dlist_head DatabaseList
Definition: autovacuum.c:299
int MultiXactMemberFreezeThreshold(void)
Definition: multixact.c:2817
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
TransactionId adw_frozenxid
Definition: autovacuum.c:173
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
PgStat_StatDBEntry * adw_entry
Definition: autovacuum.c:175
Oid adw_datid
Definition: autovacuum.c:171
static TransactionId recentXid
Definition: autovacuum.c:147
dlist_node * cur
Definition: ilist.h:161
#define InvalidOid
Definition: postgres_ext.h:36
TransactionId MultiXactId
Definition: c.h:401
#define lfirst(lc)
Definition: pg_list.h:106
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3140
static void rebuild_database_list(Oid newdb)
Definition: autovacuum.c:925
static dlist_node * dlist_pop_head_node(dlist_head *head)
Definition: ilist.h:368
PGPROC * wi_proc
Definition: autovacuum.c:226
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:113
Definition: pg_list.h:45
#define dlist_reverse_foreach(iter, lhead)
Definition: ilist.h:538
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:721
static AutoVacOpts * extract_autovac_opts ( HeapTuple  tup,
TupleDesc  pg_class_desc 
)
static

Definition at line 2703 of file autovacuum.c.

References Assert, av, extractRelOptions(), GETSTRUCT, palloc(), pfree(), RELKIND_MATVIEW, RELKIND_RELATION, and RELKIND_TOASTVALUE.

Referenced by do_autovacuum(), and table_recheck_autovac().

2704 {
2705  bytea *relopts;
2706  AutoVacOpts *av;
2707 
2708  Assert(((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_RELATION ||
2709  ((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_MATVIEW ||
2710  ((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_TOASTVALUE);
2711 
2712  relopts = extractRelOptions(tup, pg_class_desc, NULL);
2713  if (relopts == NULL)
2714  return NULL;
2715 
2716  av = palloc(sizeof(AutoVacOpts));
2717  memcpy(av, &(((StdRdOptions *) relopts)->autovacuum), sizeof(AutoVacOpts));
2718  pfree(relopts);
2719 
2720  return av;
2721 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define RELKIND_MATVIEW
Definition: pg_class.h:165
void pfree(void *pointer)
Definition: mcxt.c:949
struct @18::@19 av[32]
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
Definition: reloptions.c:956
#define Assert(condition)
Definition: c.h:681
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
void * palloc(Size size)
Definition: mcxt.c:848
Definition: c.h:433
#define RELKIND_RELATION
Definition: pg_class.h:160
static void FreeWorkerInfo ( int  code,
Datum  arg 
)
static

Definition at line 1711 of file autovacuum.c.

References AutoVacRebalance, AutovacuumLauncherPid, AutoVacuumShmemStruct::av_freeWorkers, AutoVacuumShmemStruct::av_launcherpid, AutoVacuumShmemStruct::av_signal, dlist_delete(), dlist_push_head(), InvalidOid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), WorkerInfoData::wi_cost_delay, WorkerInfoData::wi_cost_limit, WorkerInfoData::wi_cost_limit_base, WorkerInfoData::wi_dboid, WorkerInfoData::wi_dobalance, WorkerInfoData::wi_launchtime, WorkerInfoData::wi_links, WorkerInfoData::wi_proc, WorkerInfoData::wi_sharedrel, and WorkerInfoData::wi_tableoid.

Referenced by AutoVacWorkerMain().

1712 {
1713  if (MyWorkerInfo != NULL)
1714  {
1715  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
1716 
1717  /*
1718  * Wake the launcher up so that he can launch a new worker immediately
1719  * if required. We only save the launcher's PID in local memory here;
1720  * the actual signal will be sent when the PGPROC is recycled. Note
1721  * that we always do this, so that the launcher can rebalance the cost
1722  * limit setting of the remaining workers.
1723  *
1724  * We somewhat ignore the risk that the launcher changes its PID
1725  * between us reading it and the actual kill; we expect ProcKill to be
1726  * called shortly after us, and we assume that PIDs are not reused too
1727  * quickly after a process exits.
1728  */
1730 
1734  MyWorkerInfo->wi_sharedrel = false;
1735  MyWorkerInfo->wi_proc = NULL;
1737  MyWorkerInfo->wi_dobalance = false;
1743  /* not mine anymore */
1744  MyWorkerInfo = NULL;
1745 
1746  /*
1747  * now that we're inactive, cause a rebalancing of the surviving
1748  * workers
1749  */
1751  LWLockRelease(AutovacuumLock);
1752  }
1753 }
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:285
dlist_head av_freeWorkers
Definition: autovacuum.c:287
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
TimestampTz wi_launchtime
Definition: autovacuum.c:227
dlist_node wi_links
Definition: autovacuum.c:223
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
int AutovacuumLauncherPid
Definition: autovacuum.c:306
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:303
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
int wi_cost_limit_base
Definition: autovacuum.c:232
#define InvalidOid
Definition: postgres_ext.h:36
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
PGPROC * wi_proc
Definition: autovacuum.c:226
static List * get_database_list ( void  )
static

Definition at line 1864 of file autovacuum.c.

References AccessShareLock, avw_dbase::adw_datid, avw_dbase::adw_entry, avw_dbase::adw_frozenxid, avw_dbase::adw_minmulti, avw_dbase::adw_name, CommitTransactionCommand(), CurrentMemoryContext, DatabaseRelationId, dblist, ForwardScanDirection, GETSTRUCT, GetTransactionSnapshot(), heap_beginscan_catalog(), heap_close, heap_endscan(), heap_getnext(), heap_open(), HeapTupleGetOid, HeapTupleIsValid, lappend(), MemoryContextSwitchTo(), NameStr, NIL, palloc(), pstrdup(), and StartTransactionCommand().

Referenced by do_start_worker(), and rebuild_database_list().

1865 {
1866  List *dblist = NIL;
1867  Relation rel;
1868  HeapScanDesc scan;
1869  HeapTuple tup;
1870  MemoryContext resultcxt;
1871 
1872  /* This is the context that we will allocate our output data in */
1873  resultcxt = CurrentMemoryContext;
1874 
1875  /*
1876  * Start a transaction so we can access pg_database, and get a snapshot.
1877  * We don't have a use for the snapshot itself, but we're interested in
1878  * the secondary effect that it sets RecentGlobalXmin. (This is critical
1879  * for anything that reads heap pages, because HOT may decide to prune
1880  * them even if the process doesn't attempt to modify any tuples.)
1881  */
1883  (void) GetTransactionSnapshot();
1884 
1886  scan = heap_beginscan_catalog(rel, 0, NULL);
1887 
1888  while (HeapTupleIsValid(tup = heap_getnext(scan, ForwardScanDirection)))
1889  {
1890  Form_pg_database pgdatabase = (Form_pg_database) GETSTRUCT(tup);
1891  avw_dbase *avdb;
1892  MemoryContext oldcxt;
1893 
1894  /*
1895  * Allocate our results in the caller's context, not the
1896  * transaction's. We do this inside the loop, and restore the original
1897  * context at the end, so that leaky things like heap_getnext() are
1898  * not called in a potentially long-lived context.
1899  */
1900  oldcxt = MemoryContextSwitchTo(resultcxt);
1901 
1902  avdb = (avw_dbase *) palloc(sizeof(avw_dbase));
1903 
1904  avdb->adw_datid = HeapTupleGetOid(tup);
1905  avdb->adw_name = pstrdup(NameStr(pgdatabase->datname));
1906  avdb->adw_frozenxid = pgdatabase->datfrozenxid;
1907  avdb->adw_minmulti = pgdatabase->datminmxid;
1908  /* this gets set later: */
1909  avdb->adw_entry = NULL;
1910 
1911  dblist = lappend(dblist, avdb);
1912  MemoryContextSwitchTo(oldcxt);
1913  }
1914 
1915  heap_endscan(scan);
1917 
1919 
1920  return dblist;
1921 }
#define NIL
Definition: pg_list.h:69
MultiXactId adw_minmulti
Definition: autovacuum.c:174
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
FormData_pg_database * Form_pg_database
Definition: pg_database.h:57
char * pstrdup(const char *in)
Definition: mcxt.c:1076
#define DatabaseRelationId
Definition: pg_database.h:29
void CommitTransactionCommand(void)
Definition: xact.c:2744
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:304
_stringlist * dblist
Definition: pg_regress.c:72
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1405
char * adw_name
Definition: autovacuum.c:172
List * lappend(List *list, void *datum)
Definition: list.c:128
TransactionId adw_frozenxid
Definition: autovacuum.c:173
PgStat_StatDBEntry * adw_entry
Definition: autovacuum.c:175
Oid adw_datid
Definition: autovacuum.c:171
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1808
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
void StartTransactionCommand(void)
Definition: xact.c:2673
void * palloc(Size size)
Definition: mcxt.c:848
#define NameStr(name)
Definition: c.h:493
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
Definition: pg_list.h:45
static PgStat_StatTabEntry * get_pgstat_tabentry_relid ( Oid  relid,
bool  isshared,
PgStat_StatDBEntry shared,
PgStat_StatDBEntry dbentry 
)
static

Definition at line 2729 of file autovacuum.c.

References HASH_FIND, hash_search(), PointerIsValid, and PgStat_StatDBEntry::tables.

Referenced by do_autovacuum(), and table_recheck_autovac().

2731 {
2732  PgStat_StatTabEntry *tabentry = NULL;
2733 
2734  if (isshared)
2735  {
2736  if (PointerIsValid(shared))
2737  tabentry = hash_search(shared->tables, &relid,
2738  HASH_FIND, NULL);
2739  }
2740  else if (PointerIsValid(dbentry))
2741  tabentry = hash_search(dbentry->tables, &relid,
2742  HASH_FIND, NULL);
2743 
2744  return tabentry;
2745 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
#define PointerIsValid(pointer)
Definition: c.h:520
bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3250 of file autovacuum.c.

References am_autovacuum_launcher.

Referenced by autovac_refresh_stats(), backend_read_statsfile(), InitPostgres(), InitProcess(), pgstat_bestart(), and ProcKill().

3251 {
3252  return am_autovacuum_launcher;
3253 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:138
static void launch_worker ( TimestampTz  now)
static

Definition at line 1341 of file autovacuum.c.

References avl_dbase::adl_datid, avl_dbase::adl_next_worker, autovacuum_naptime, dlist_iter::cur, dlist_container, dlist_foreach, dlist_move_head(), do_start_worker(), OidIsValid, rebuild_database_list(), and TimestampTzPlusMilliseconds.

Referenced by AutoVacLauncherMain().

1342 {
1343  Oid dbid;
1344  dlist_iter iter;
1345 
1346  dbid = do_start_worker();
1347  if (OidIsValid(dbid))
1348  {
1349  bool found = false;
1350 
1351  /*
1352  * Walk the database list and update the corresponding entry. If the
1353  * database is not on the list, we'll recreate the list.
1354  */
1355  dlist_foreach(iter, &DatabaseList)
1356  {
1357  avl_dbase *avdb = dlist_container(avl_dbase, adl_node, iter.cur);
1358 
1359  if (avdb->adl_datid == dbid)
1360  {
1361  found = true;
1362 
1363  /*
1364  * add autovacuum_naptime seconds to the current time, and use
1365  * that as the new "next_worker" field for this database.
1366  */
1367  avdb->adl_next_worker =
1369 
1371  break;
1372  }
1373  }
1374 
1375  /*
1376  * If the database was not present in the database list, we rebuild
1377  * the list. It's possible that the database does not get into the
1378  * list anyway, for example if it's a database that doesn't have a
1379  * pgstat entry, but this is not a problem because we don't want to
1380  * schedule workers regularly into those in any case.
1381  */
1382  if (!found)
1383  rebuild_database_list(dbid);
1384  }
1385 }
int autovacuum_naptime
Definition: autovacuum.c:117
TimestampTz adl_next_worker
Definition: autovacuum.c:163
#define dlist_foreach(iter, lhead)
Definition: ilist.h:507
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
Oid adl_datid
Definition: autovacuum.c:162
static dlist_head DatabaseList
Definition: autovacuum.c:299
dlist_node * cur
Definition: ilist.h:161
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:56
static void dlist_move_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:385
static void rebuild_database_list(Oid newdb)
Definition: autovacuum.c:925
static Oid do_start_worker(void)
Definition: autovacuum.c:1126
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1534
static void launcher_determine_sleep ( bool  canlaunch,
bool  recursing,
struct timeval *  nap 
)
static

Definition at line 841 of file autovacuum.c.

References avl_dbase::adl_next_worker, autovacuum_naptime, dlist_is_empty(), dlist_tail_element, GetCurrentTimestamp(), InvalidOid, MAX_AUTOVAC_SLEEPTIME, MIN_AUTOVAC_SLEEPTIME, rebuild_database_list(), and TimestampDifference().

Referenced by AutoVacLauncherMain().

842 {
843  /*
844  * We sleep until the next scheduled vacuum. We trust that when the
845  * database list was built, care was taken so that no entries have times
846  * in the past; if the first entry has too close a next_worker value, or a
847  * time in the past, we will sleep a small nominal time.
848  */
849  if (!canlaunch)
850  {
851  nap->tv_sec = autovacuum_naptime;
852  nap->tv_usec = 0;
853  }
854  else if (!dlist_is_empty(&DatabaseList))
855  {
856  TimestampTz current_time = GetCurrentTimestamp();
857  TimestampTz next_wakeup;
858  avl_dbase *avdb;
859  long secs;
860  int usecs;
861 
862  avdb = dlist_tail_element(avl_dbase, adl_node, &DatabaseList);
863 
864  next_wakeup = avdb->adl_next_worker;
865  TimestampDifference(current_time, next_wakeup, &secs, &usecs);
866 
867  nap->tv_sec = secs;
868  nap->tv_usec = usecs;
869  }
870  else
871  {
872  /* list is empty, sleep for whole autovacuum_naptime seconds */
873  nap->tv_sec = autovacuum_naptime;
874  nap->tv_usec = 0;
875  }
876 
877  /*
878  * If the result is exactly zero, it means a database had an entry with
879  * time in the past. Rebuild the list so that the databases are evenly
880  * distributed again, and recalculate the time to sleep. This can happen
881  * if there are more tables needing vacuum than workers, and they all take
882  * longer to vacuum than autovacuum_naptime.
883  *
884  * We only recurse once. rebuild_database_list should always return times
885  * in the future, but it seems best not to trust too much on that.
886  */
887  if (nap->tv_sec == 0 && nap->tv_usec == 0 && !recursing)
888  {
890  launcher_determine_sleep(canlaunch, true, nap);
891  return;
892  }
893 
894  /* The smallest time we'll allow the launcher to sleep. */
895  if (nap->tv_sec <= 0 && nap->tv_usec <= MIN_AUTOVAC_SLEEPTIME * 1000)
896  {
897  nap->tv_sec = 0;
898  nap->tv_usec = MIN_AUTOVAC_SLEEPTIME * 1000;
899  }
900 
901  /*
902  * If the sleep time is too large, clamp it to an arbitrary maximum (plus
903  * any fractional seconds, for simplicity). This avoids an essentially
904  * infinite sleep in strange cases like the system clock going backwards a
905  * few years.
906  */
907  if (nap->tv_sec > MAX_AUTOVAC_SLEEPTIME)
908  nap->tv_sec = MAX_AUTOVAC_SLEEPTIME;
909 }
int autovacuum_naptime
Definition: autovacuum.c:117
TimestampTz adl_next_worker
Definition: autovacuum.c:163
#define MAX_AUTOVAC_SLEEPTIME
Definition: autovacuum.c:135
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1570
int64 TimestampTz
Definition: timestamp.h:39
#define MIN_AUTOVAC_SLEEPTIME
Definition: autovacuum.c:134
#define dlist_tail_element(type, membername, lhead)
Definition: ilist.h:496
static dlist_head DatabaseList
Definition: autovacuum.c:299
static void launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval *nap)
Definition: autovacuum.c:841
#define InvalidOid
Definition: postgres_ext.h:36
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
static void rebuild_database_list(Oid newdb)
Definition: autovacuum.c:925
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1624
static void perform_work_item ( AutoVacuumWorkItem workitem)
static

Definition at line 2595 of file autovacuum.c.

References AbortOutOfAnyTransaction(), Assert, autovac_report_workitem(), AutoVacuumWorkItem::avw_blockNumber, AVW_BRINSummarizeRange, AutoVacuumWorkItem::avw_relation, AutoVacuumWorkItem::avw_type, brin_summarize_range(), CurrentMemoryContext, DirectFunctionCall2, elog, EmitErrorReport(), errcontext, FlushErrorState(), get_database_name(), get_namespace_name(), get_rel_name(), get_rel_namespace(), HOLD_INTERRUPTS, Int64GetDatum(), MemoryContextResetAndDeleteChildren, MemoryContextSwitchTo(), MyDatabaseId, ObjectIdGetDatum, pfree(), PG_CATCH, PG_END_TRY, PG_TRY, PortalContext, QueryCancelPending, RESUME_INTERRUPTS, StartTransactionCommand(), and WARNING.

Referenced by do_autovacuum().

2596 {
2597  char *cur_datname = NULL;
2598  char *cur_nspname = NULL;
2599  char *cur_relname = NULL;
2600 
2601  /*
2602  * Note we do not store table info in MyWorkerInfo, since this is not
2603  * vacuuming proper.
2604  */
2605 
2606  /*
2607  * Save the relation name for a possible error message, to avoid a catalog
2608  * lookup in case of an error. If any of these return NULL, then the
2609  * relation has been dropped since last we checked; skip it. Note: they
2610  * must live in a long-lived memory context because we call vacuum and
2611  * analyze in different transactions.
2612  */
2614 
2615  cur_relname = get_rel_name(workitem->avw_relation);
2616  cur_nspname = get_namespace_name(get_rel_namespace(workitem->avw_relation));
2617  cur_datname = get_database_name(MyDatabaseId);
2618  if (!cur_relname || !cur_nspname || !cur_datname)
2619  goto deleted2;
2620 
2621  autovac_report_workitem(workitem, cur_nspname, cur_datname);
2622 
2623  /* clean up memory before each work item */
2625 
2626  /*
2627  * We will abort the current work item if something errors out, and
2628  * continue with the next one; in particular, this happens if we are
2629  * interrupted with SIGINT. Note that this means that the work item list
2630  * can be lossy.
2631  */
2632  PG_TRY();
2633  {
2634  /* Use PortalContext for any per-work-item allocations */
2636 
2637  /* have at it */
2638  switch (workitem->avw_type)
2639  {
2642  ObjectIdGetDatum(workitem->avw_relation),
2643  Int64GetDatum((int64) workitem->avw_blockNumber));
2644  break;
2645  default:
2646  elog(WARNING, "unrecognized work item found: type %d",
2647  workitem->avw_type);
2648  break;
2649  }
2650 
2651  /*
2652  * Clear a possible query-cancel signal, to avoid a late reaction to
2653  * an automatically-sent signal because of vacuuming the current table
2654  * (we're done with it, so it would make no sense to cancel at this
2655  * point.)
2656  */
2657  QueryCancelPending = false;
2658  }
2659  PG_CATCH();
2660  {
2661  /*
2662  * Abort the transaction, start a new one, and proceed with the next
2663  * table in our list.
2664  */
2665  HOLD_INTERRUPTS();
2666  errcontext("processing work entry for relation \"%s.%s.%s\"",
2667  cur_datname, cur_nspname, cur_relname);
2668  EmitErrorReport();
2669 
2670  /* this resets the PGXACT flags too */
2672  FlushErrorState();
2674 
2675  /* restart our transaction for the following operations */
2678  }
2679  PG_END_TRY();
2680 
2681  /* Make sure we're back in AutovacMemCxt */
2683 
2684  /* We intentionally do not set did_vacuum here */
2685 
2686  /* be tidy */
2687 deleted2:
2688  if (cur_datname)
2689  pfree(cur_datname);
2690  if (cur_nspname)
2691  pfree(cur_nspname);
2692  if (cur_relname)
2693  pfree(cur_relname);
2694 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:257
static MemoryContext AutovacMemCxt
Definition: autovacuum.c:157
Oid get_rel_namespace(Oid relid)
Definition: lsyscache.c:1750
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
volatile bool QueryCancelPending
Definition: globals.c:30
void AbortOutOfAnyTransaction(void)
Definition: xact.c:4343
void FlushErrorState(void)
Definition: elog.c:1587
MemoryContext PortalContext
Definition: mcxt.c:52
Datum brin_summarize_range(PG_FUNCTION_ARGS)
Definition: brin.c:853
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:117
void pfree(void *pointer)
Definition: mcxt.c:949
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2056
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
static void autovac_report_workitem(AutoVacuumWorkItem *workitem, const char *nspname, const char *relname)
Definition: autovacuum.c:3147
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1786
#define WARNING
Definition: elog.h:40
#define MemoryContextResetAndDeleteChildren(ctx)
Definition: memutils.h:67
Oid MyDatabaseId
Definition: globals.c:77
BlockNumber avw_blockNumber
Definition: autovacuum.c:262
void EmitErrorReport(void)
Definition: elog.c:1446
#define PG_CATCH()
Definition: elog.h:293
#define Assert(condition)
Definition: c.h:681
void StartTransactionCommand(void)
Definition: xact.c:2673
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:115
#define errcontext
Definition: elog.h:164
#define elog
Definition: elog.h:219
#define PG_TRY()
Definition: elog.h:284
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1726
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
#define PG_END_TRY()
Definition: elog.h:300
static void rebuild_database_list ( Oid  newdb)
static

Definition at line 925 of file autovacuum.c.

References avl_dbase::adl_datid, avl_dbase::adl_next_worker, avl_dbase::adl_node, avl_dbase::adl_score, avw_dbase::adw_datid, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), autovac_refresh_stats(), autovacuum_naptime, dlist_iter::cur, db_comparator(), dblist, dlist_container, dlist_foreach, dlist_init(), dlist_push_head(), HASHCTL::entrysize, get_database_list(), GetCurrentTimestamp(), HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), hash_seq_init(), hash_seq_search(), HASHCTL::hcxt, i, HASHCTL::keysize, lfirst, MemoryContextDelete(), MemoryContextSwitchTo(), MIN_AUTOVAC_SLEEPTIME, OidIsValid, palloc(), pgstat_fetch_stat_dbentry(), qsort, and TimestampTzPlusMilliseconds.

Referenced by AutoVacLauncherMain(), do_start_worker(), launch_worker(), and launcher_determine_sleep().

926 {
927  List *dblist;
928  ListCell *cell;
929  MemoryContext newcxt;
930  MemoryContext oldcxt;
931  MemoryContext tmpcxt;
932  HASHCTL hctl;
933  int score;
934  int nelems;
935  HTAB *dbhash;
936  dlist_iter iter;
937 
938  /* use fresh stats */
940 
942  "AV dblist",
944  tmpcxt = AllocSetContextCreate(newcxt,
945  "tmp AV dblist",
947  oldcxt = MemoryContextSwitchTo(tmpcxt);
948 
949  /*
950  * Implementing this is not as simple as it sounds, because we need to put
951  * the new database at the end of the list; next the databases that were
952  * already on the list, and finally (at the tail of the list) all the
953  * other databases that are not on the existing list.
954  *
955  * To do this, we build an empty hash table of scored databases. We will
956  * start with the lowest score (zero) for the new database, then
957  * increasing scores for the databases in the existing list, in order, and
958  * lastly increasing scores for all databases gotten via
959  * get_database_list() that are not already on the hash.
960  *
961  * Then we will put all the hash elements into an array, sort the array by
962  * score, and finally put the array elements into the new doubly linked
963  * list.
964  */
965  hctl.keysize = sizeof(Oid);
966  hctl.entrysize = sizeof(avl_dbase);
967  hctl.hcxt = tmpcxt;
968  dbhash = hash_create("db hash", 20, &hctl, /* magic number here FIXME */
970 
971  /* start by inserting the new database */
972  score = 0;
973  if (OidIsValid(newdb))
974  {
975  avl_dbase *db;
976  PgStat_StatDBEntry *entry;
977 
978  /* only consider this database if it has a pgstat entry */
979  entry = pgstat_fetch_stat_dbentry(newdb);
980  if (entry != NULL)
981  {
982  /* we assume it isn't found because the hash was just created */
983  db = hash_search(dbhash, &newdb, HASH_ENTER, NULL);
984 
985  /* hash_search already filled in the key */
986  db->adl_score = score++;
987  /* next_worker is filled in later */
988  }
989  }
990 
991  /* Now insert the databases from the existing list */
993  {
994  avl_dbase *avdb = dlist_container(avl_dbase, adl_node, iter.cur);
995  avl_dbase *db;
996  bool found;
997  PgStat_StatDBEntry *entry;
998 
999  /*
1000  * skip databases with no stat entries -- in particular, this gets rid
1001  * of dropped databases
1002  */
1003  entry = pgstat_fetch_stat_dbentry(avdb->adl_datid);
1004  if (entry == NULL)
1005  continue;
1006 
1007  db = hash_search(dbhash, &(avdb->adl_datid), HASH_ENTER, &found);
1008 
1009  if (!found)
1010  {
1011  /* hash_search already filled in the key */
1012  db->adl_score = score++;
1013  /* next_worker is filled in later */
1014  }
1015  }
1016 
1017  /* finally, insert all qualifying databases not previously inserted */
1018  dblist = get_database_list();
1019  foreach(cell, dblist)
1020  {
1021  avw_dbase *avdb = lfirst(cell);
1022  avl_dbase *db;
1023  bool found;
1024  PgStat_StatDBEntry *entry;
1025 
1026  /* only consider databases with a pgstat entry */
1027  entry = pgstat_fetch_stat_dbentry(avdb->adw_datid);
1028  if (entry == NULL)
1029  continue;
1030 
1031  db = hash_search(dbhash, &(avdb->adw_datid), HASH_ENTER, &found);
1032  /* only update the score if the database was not already on the hash */
1033  if (!found)
1034  {
1035  /* hash_search already filled in the key */
1036  db->adl_score = score++;
1037  /* next_worker is filled in later */
1038  }
1039  }
1040  nelems = score;
1041 
1042  /* from here on, the allocated memory belongs to the new list */
1043  MemoryContextSwitchTo(newcxt);
1045 
1046  if (nelems > 0)
1047  {
1048  TimestampTz current_time;
1049  int millis_increment;
1050  avl_dbase *dbary;
1051  avl_dbase *db;
1052  HASH_SEQ_STATUS seq;
1053  int i;
1054 
1055  /* put all the hash elements into an array */
1056  dbary = palloc(nelems * sizeof(avl_dbase));
1057 
1058  i = 0;
1059  hash_seq_init(&seq, dbhash);
1060  while ((db = hash_seq_search(&seq)) != NULL)
1061  memcpy(&(dbary[i++]), db, sizeof(avl_dbase));
1062 
1063  /* sort the array */
1064  qsort(dbary, nelems, sizeof(avl_dbase), db_comparator);
1065 
1066  /*
1067  * Determine the time interval between databases in the schedule. If
1068  * we see that the configured naptime would take us to sleep times
1069  * lower than our min sleep time (which launcher_determine_sleep is
1070  * coded not to allow), silently use a larger naptime (but don't touch
1071  * the GUC variable).
1072  */
1073  millis_increment = 1000.0 * autovacuum_naptime / nelems;
1074  if (millis_increment <= MIN_AUTOVAC_SLEEPTIME)
1075  millis_increment = MIN_AUTOVAC_SLEEPTIME * 1.1;
1076 
1077  current_time = GetCurrentTimestamp();
1078 
1079  /*
1080  * move the elements from the array into the dllist, setting the
1081  * next_worker while walking the array
1082  */
1083  for (i = 0; i < nelems; i++)
1084  {
1085  avl_dbase *db = &(dbary[i]);
1086 
1087  current_time = TimestampTzPlusMilliseconds(current_time,
1088  millis_increment);
1089  db->adl_next_worker = current_time;
1090 
1091  /* later elements should go closer to the head of the list */
1093  }
1094  }
1095 
1096  /* all done, clean up memory */
1097  if (DatabaseListCxt != NULL)
1099  MemoryContextDelete(tmpcxt);
1100  DatabaseListCxt = newcxt;
1101  MemoryContextSwitchTo(oldcxt);
1102 }
int autovacuum_naptime
Definition: autovacuum.c:117
TimestampTz adl_next_worker
Definition: autovacuum.c:163
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
#define HASH_CONTEXT
Definition: hsearch.h:93
#define HASH_ELEM
Definition: hsearch.h:87
MemoryContext hcxt
Definition: hsearch.h:78
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1570
int64 TimestampTz
Definition: timestamp.h:39
#define dlist_foreach(iter, lhead)
Definition: ilist.h:507
int adl_score
Definition: autovacuum.c:164
static MemoryContext AutovacMemCxt
Definition: autovacuum.c:157
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Size entrysize
Definition: hsearch.h:73
struct avl_dbase avl_dbase
static void autovac_refresh_stats(void)
Definition: autovacuum.c:3334
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
#define MIN_AUTOVAC_SLEEPTIME
Definition: autovacuum.c:134
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
Definition: dynahash.c:208
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
static List * get_database_list(void)
Definition: autovacuum.c:1864
Oid adl_datid
Definition: autovacuum.c:162
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
_stringlist * dblist
Definition: pg_regress.c:72
static dlist_head DatabaseList
Definition: autovacuum.c:299
static int db_comparator(const void *a, const void *b)
Definition: autovacuum.c:1106
#define HASH_BLOBS
Definition: hsearch.h:88
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
Oid adw_datid
Definition: autovacuum.c:171
Size keysize
Definition: hsearch.h:72
dlist_node * cur
Definition: ilist.h:161
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:56
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define lfirst(lc)
Definition: pg_list.h:106
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1385
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1375
dlist_node adl_node
Definition: autovacuum.c:165
void * palloc(Size size)
Definition: mcxt.c:848
static MemoryContext DatabaseListCxt
Definition: autovacuum.c:300
int i
#define qsort(a, b, c, d)
Definition: port.h:447
Definition: pg_list.h:45
static void relation_needs_vacanalyze ( Oid  relid,
AutoVacOpts relopts,
Form_pg_class  classForm,
PgStat_StatTabEntry tabentry,
int  effective_multixact_freeze_max_age,
bool dovacuum,
bool doanalyze,
bool wraparound 
)
static

Definition at line 2938 of file autovacuum.c.

References AutoVacOpts::analyze_scale_factor, AutoVacOpts::analyze_threshold, AssertArg, autovacuum_anl_scale, autovacuum_anl_thresh, autovacuum_freeze_max_age, autovacuum_vac_scale, autovacuum_vac_thresh, AutoVacuumingActive(), PgStat_StatTabEntry::changes_since_analyze, DEBUG3, elog, AutoVacOpts::enabled, FirstMultiXactId, FirstNormalTransactionId, AutoVacOpts::freeze_max_age, Min, AutoVacOpts::multixact_freeze_max_age, MultiXactIdPrecedes(), PgStat_StatTabEntry::n_dead_tuples, NameStr, OidIsValid, PointerIsValid, recentMulti, recentXid, StatisticRelationId, TransactionIdIsNormal, TransactionIdPrecedes(), AutoVacOpts::vacuum_scale_factor, and AutoVacOpts::vacuum_threshold.

Referenced by do_autovacuum(), and table_recheck_autovac().

2947 {
2948  bool force_vacuum;
2949  bool av_enabled;
2950  float4 reltuples; /* pg_class.reltuples */
2951 
2952  /* constants from reloptions or GUC variables */
2953  int vac_base_thresh,
2954  anl_base_thresh;
2955  float4 vac_scale_factor,
2956  anl_scale_factor;
2957 
2958  /* thresholds calculated from above constants */
2959  float4 vacthresh,
2960  anlthresh;
2961 
2962  /* number of vacuum (resp. analyze) tuples at this time */
2963  float4 vactuples,
2964  anltuples;
2965 
2966  /* freeze parameters */
2967  int freeze_max_age;
2968  int multixact_freeze_max_age;
2969  TransactionId xidForceLimit;
2970  MultiXactId multiForceLimit;
2971 
2972  AssertArg(classForm != NULL);
2973  AssertArg(OidIsValid(relid));
2974 
2975  /*
2976  * Determine vacuum/analyze equation parameters. We have two possible
2977  * sources: the passed reloptions (which could be a main table or a toast
2978  * table), or the autovacuum GUC variables.
2979  */
2980 
2981  /* -1 in autovac setting means use plain vacuum_cost_delay */
2982  vac_scale_factor = (relopts && relopts->vacuum_scale_factor >= 0)
2983  ? relopts->vacuum_scale_factor
2985 
2986  vac_base_thresh = (relopts && relopts->vacuum_threshold >= 0)
2987  ? relopts->vacuum_threshold
2989 
2990  anl_scale_factor = (relopts && relopts->analyze_scale_factor >= 0)
2991  ? relopts->analyze_scale_factor
2993 
2994  anl_base_thresh = (relopts && relopts->analyze_threshold >= 0)
2995  ? relopts->analyze_threshold
2997 
2998  freeze_max_age = (relopts && relopts->freeze_max_age >= 0)
3001 
3002  multixact_freeze_max_age = (relopts && relopts->multixact_freeze_max_age >= 0)
3003  ? Min(relopts->multixact_freeze_max_age, effective_multixact_freeze_max_age)
3004  : effective_multixact_freeze_max_age;
3005 
3006  av_enabled = (relopts ? relopts->enabled : true);
3007 
3008  /* Force vacuum if table is at risk of wraparound */
3009  xidForceLimit = recentXid - freeze_max_age;
3010  if (xidForceLimit < FirstNormalTransactionId)
3011  xidForceLimit -= FirstNormalTransactionId;
3012  force_vacuum = (TransactionIdIsNormal(classForm->relfrozenxid) &&
3013  TransactionIdPrecedes(classForm->relfrozenxid,
3014  xidForceLimit));
3015  if (!force_vacuum)
3016  {
3017  multiForceLimit = recentMulti - multixact_freeze_max_age;
3018  if (multiForceLimit < FirstMultiXactId)
3019  multiForceLimit -= FirstMultiXactId;
3020  force_vacuum = MultiXactIdPrecedes(classForm->relminmxid,
3021  multiForceLimit);
3022  }
3023  *wraparound = force_vacuum;
3024 
3025  /* User disabled it in pg_class.reloptions? (But ignore if at risk) */
3026  if (!av_enabled && !force_vacuum)
3027  {
3028  *doanalyze = false;
3029  *dovacuum = false;
3030  return;
3031  }
3032 
3033  /*
3034  * If we found the table in the stats hash, and autovacuum is currently
3035  * enabled, make a threshold-based decision whether to vacuum and/or
3036  * analyze. If autovacuum is currently disabled, we must be here for
3037  * anti-wraparound vacuuming only, so don't vacuum (or analyze) anything
3038  * that's not being forced.
3039  */
3040  if (PointerIsValid(tabentry) && AutoVacuumingActive())
3041  {
3042  reltuples = classForm->reltuples;
3043  vactuples = tabentry->n_dead_tuples;
3044  anltuples = tabentry->changes_since_analyze;
3045 
3046  vacthresh = (float4) vac_base_thresh + vac_scale_factor * reltuples;
3047  anlthresh = (float4) anl_base_thresh + anl_scale_factor * reltuples;
3048 
3049  /*
3050  * Note that we don't need to take special consideration for stat
3051  * reset, because if that happens, the last vacuum and analyze counts
3052  * will be reset too.
3053  */
3054  elog(DEBUG3, "%s: vac: %.0f (threshold %.0f), anl: %.0f (threshold %.0f)",
3055  NameStr(classForm->relname),
3056  vactuples, vacthresh, anltuples, anlthresh);
3057 
3058  /* Determine if this table needs vacuum or analyze. */
3059  *dovacuum = force_vacuum || (vactuples > vacthresh);
3060  *doanalyze = (anltuples > anlthresh);
3061  }
3062  else
3063  {
3064  /*
3065  * Skip a table not found in stat hash, unless we have to force vacuum
3066  * for anti-wrap purposes. If it's not acted upon, there's no need to
3067  * vacuum it.
3068  */
3069  *dovacuum = force_vacuum;
3070  *doanalyze = false;
3071  }
3072 
3073  /* ANALYZE refuses to work with pg_statistic */
3074  if (relid == StatisticRelationId)
3075  *doanalyze = false;
3076 }
double autovacuum_anl_scale
Definition: autovacuum.c:121
uint32 TransactionId
Definition: c.h:391
#define DEBUG3
Definition: elog.h:23
float8 vacuum_scale_factor
Definition: rel.h:272
#define Min(x, y)
Definition: c.h:812
static MultiXactId recentMulti
Definition: autovacuum.c:148
#define OidIsValid(objectId)
Definition: c.h:532
#define FirstNormalTransactionId
Definition: transam.h:34
bool AutoVacuumingActive(void)
Definition: autovacuum.c:3187
int autovacuum_freeze_max_age
Definition: autovacuum.c:122
PgStat_Counter n_dead_tuples
Definition: pgstat.h:630
int analyze_threshold
Definition: rel.h:262
int autovacuum_vac_thresh
Definition: autovacuum.c:118
#define FirstMultiXactId
Definition: multixact.h:24
#define AssertArg(condition)
Definition: c.h:683
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
float float4
Definition: c.h:374
int vacuum_threshold
Definition: rel.h:261
#define StatisticRelationId
Definition: pg_statistic.h:29
static TransactionId recentXid
Definition: autovacuum.c:147
PgStat_Counter changes_since_analyze
Definition: pgstat.h:631
double autovacuum_vac_scale
Definition: autovacuum.c:119
float8 analyze_scale_factor
Definition: rel.h:273
TransactionId MultiXactId
Definition: c.h:401
int freeze_max_age
Definition: rel.h:266
bool enabled
Definition: rel.h:260
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3140
#define NameStr(name)
Definition: c.h:493
int multixact_freeze_max_age
Definition: rel.h:269
#define elog
Definition: elog.h:219
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
#define PointerIsValid(pointer)
Definition: c.h:520
int autovacuum_anl_thresh
Definition: autovacuum.c:120
int StartAutoVacLauncher ( void  )

Definition at line 395 of file autovacuum.c.

References AutoVacLauncherMain(), AutoVacPID, ClosePostmasterPorts(), ereport, errmsg(), fork_process(), InitPostmasterChild(), and LOG.

Referenced by reaper(), and ServerLoop().

396 {
397  pid_t AutoVacPID;
398 
399 #ifdef EXEC_BACKEND
400  switch ((AutoVacPID = avlauncher_forkexec()))
401 #else
402  switch ((AutoVacPID = fork_process()))
403 #endif
404  {
405  case -1:
406  ereport(LOG,
407  (errmsg("could not fork autovacuum launcher process: %m")));
408  return 0;
409 
410 #ifndef EXEC_BACKEND
411  case 0:
412  /* in postmaster child ... */
414 
415  /* Close the postmaster's sockets */
416  ClosePostmasterPorts(false);
417 
418  AutoVacLauncherMain(0, NULL);
419  break;
420 #endif
421  default:
422  return (int) AutoVacPID;
423  }
424 
425  /* shouldn't get here */
426  return 0;
427 }
void InitPostmasterChild(void)
Definition: miscinit.c:176
NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: autovacuum.c:433
pid_t fork_process(void)
Definition: fork_process.c:31
#define LOG
Definition: elog.h:26
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2451
#define ereport(elevel, rest)
Definition: elog.h:122
static pid_t AutoVacPID
Definition: postmaster.c:252
int errmsg(const char *fmt,...)
Definition: elog.c:797
int StartAutoVacWorker ( void  )

Definition at line 1477 of file autovacuum.c.

References AutoVacWorkerMain(), ClosePostmasterPorts(), ereport, errmsg(), fork_process(), InitPostmasterChild(), and LOG.

Referenced by StartAutovacuumWorker().

1478 {
1479  pid_t worker_pid;
1480 
1481 #ifdef EXEC_BACKEND
1482  switch ((worker_pid = avworker_forkexec()))
1483 #else
1484  switch ((worker_pid = fork_process()))
1485 #endif
1486  {
1487  case -1:
1488  ereport(LOG,
1489  (errmsg("could not fork autovacuum worker process: %m")));
1490  return 0;
1491 
1492 #ifndef EXEC_BACKEND
1493  case 0:
1494  /* in postmaster child ... */
1496 
1497  /* Close the postmaster's sockets */
1498  ClosePostmasterPorts(false);
1499 
1500  AutoVacWorkerMain(0, NULL);
1501  break;
1502 #endif
1503  default:
1504  return (int) worker_pid;
1505  }
1506 
1507  /* shouldn't get here */
1508  return 0;
1509 }
void InitPostmasterChild(void)
Definition: miscinit.c:176
pid_t fork_process(void)
Definition: fork_process.c:31
#define LOG
Definition: elog.h:26
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: autovacuum.c:1515
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2451
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
static autovac_table * table_recheck_autovac ( Oid  relid,
HTAB table_toast_map,
TupleDesc  pg_class_desc,
int  effective_multixact_freeze_max_age 
)
static

Definition at line 2756 of file autovacuum.c.

References av_relation::ar_hasrelopts, av_relation::ar_reloptions, autovac_table::at_datname, autovac_table::at_dobalance, autovac_table::at_nspname, autovac_table::at_params, autovac_table::at_relid, autovac_table::at_relname, autovac_table::at_sharedrel, autovac_table::at_vacoptions, autovac_table::at_vacuum_cost_delay, autovac_table::at_vacuum_cost_limit, autovac_refresh_stats(), autovacuum_vac_cost_delay, autovacuum_vac_cost_limit, default_freeze_min_age, default_freeze_table_age, default_multixact_freeze_min_age, default_multixact_freeze_table_age, extract_autovac_opts(), VacuumParams::freeze_min_age, AutoVacOpts::freeze_min_age, VacuumParams::freeze_table_age, AutoVacOpts::freeze_table_age, get_pgstat_tabentry_relid(), GETSTRUCT, HASH_FIND, hash_search(), heap_freetuple(), HeapTupleIsValid, InvalidOid, VacuumParams::is_wraparound, Log_autovacuum_min_duration, VacuumParams::log_min_duration, AutoVacOpts::log_min_duration, VacuumParams::multixact_freeze_min_age, AutoVacOpts::multixact_freeze_min_age, VacuumParams::multixact_freeze_table_age, AutoVacOpts::multixact_freeze_table_age, MyDatabaseId, ObjectIdGetDatum, palloc(), pgstat_fetch_stat_dbentry(), relation_needs_vacanalyze(), RELKIND_TOASTVALUE, RELOID, SearchSysCacheCopy1, VACOPT_ANALYZE, VACOPT_NOWAIT, VACOPT_SKIPTOAST, VACOPT_VACUUM, AutoVacOpts::vacuum_cost_delay, AutoVacOpts::vacuum_cost_limit, VacuumCostDelay, and VacuumCostLimit.

Referenced by do_autovacuum().

2759 {
2760  Form_pg_class classForm;
2761  HeapTuple classTup;
2762  bool dovacuum;
2763  bool doanalyze;
2764  autovac_table *tab = NULL;
2765  PgStat_StatTabEntry *tabentry;
2766  PgStat_StatDBEntry *shared;
2767  PgStat_StatDBEntry *dbentry;
2768  bool wraparound;
2769  AutoVacOpts *avopts;
2770 
2771  /* use fresh stats */
2773 
2776 
2777  /* fetch the relation's relcache entry */
2778  classTup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relid));
2779  if (!HeapTupleIsValid(classTup))
2780  return NULL;
2781  classForm = (Form_pg_class) GETSTRUCT(classTup);
2782 
2783  /*
2784  * Get the applicable reloptions. If it is a TOAST table, try to get the
2785  * main table reloptions if the toast table itself doesn't have.
2786  */
2787  avopts = extract_autovac_opts(classTup, pg_class_desc);
2788  if (classForm->relkind == RELKIND_TOASTVALUE &&
2789  avopts == NULL && table_toast_map != NULL)
2790  {
2791  av_relation *hentry;
2792  bool found;
2793 
2794  hentry = hash_search(table_toast_map, &relid, HASH_FIND, &found);
2795  if (found && hentry->ar_hasrelopts)
2796  avopts = &hentry->ar_reloptions;
2797  }
2798 
2799  /* fetch the pgstat table entry */
2800  tabentry = get_pgstat_tabentry_relid(relid, classForm->relisshared,
2801  shared, dbentry);
2802 
2803  relation_needs_vacanalyze(relid, avopts, classForm, tabentry,
2804  effective_multixact_freeze_max_age,
2805  &dovacuum, &doanalyze, &wraparound);
2806 
2807  /* ignore ANALYZE for toast tables */
2808  if (classForm->relkind == RELKIND_TOASTVALUE)
2809  doanalyze = false;
2810 
2811  /* OK, it needs something done */
2812  if (doanalyze || dovacuum)
2813  {
2814  int freeze_min_age;
2815  int freeze_table_age;
2816  int multixact_freeze_min_age;
2817  int multixact_freeze_table_age;
2818  int vac_cost_limit;
2819  int vac_cost_delay;
2820  int log_min_duration;
2821 
2822  /*
2823  * Calculate the vacuum cost parameters and the freeze ages. If there
2824  * are options set in pg_class.reloptions, use them; in the case of a
2825  * toast table, try the main table too. Otherwise use the GUC
2826  * defaults, autovacuum's own first and plain vacuum second.
2827  */
2828 
2829  /* -1 in autovac setting means use plain vacuum_cost_delay */
2830  vac_cost_delay = (avopts && avopts->vacuum_cost_delay >= 0)
2831  ? avopts->vacuum_cost_delay
2832  : (autovacuum_vac_cost_delay >= 0)
2834  : VacuumCostDelay;
2835 
2836  /* 0 or -1 in autovac setting means use plain vacuum_cost_limit */
2837  vac_cost_limit = (avopts && avopts->vacuum_cost_limit > 0)
2838  ? avopts->vacuum_cost_limit
2841  : VacuumCostLimit;
2842 
2843  /* -1 in autovac setting means use log_autovacuum_min_duration */
2844  log_min_duration = (avopts && avopts->log_min_duration >= 0)
2845  ? avopts->log_min_duration
2847 
2848  /* these do not have autovacuum-specific settings */
2849  freeze_min_age = (avopts && avopts->freeze_min_age >= 0)
2850  ? avopts->freeze_min_age
2852 
2853  freeze_table_age = (avopts && avopts->freeze_table_age >= 0)
2854  ? avopts->freeze_table_age
2856 
2857  multixact_freeze_min_age = (avopts &&
2858  avopts->multixact_freeze_min_age >= 0)
2859  ? avopts->multixact_freeze_min_age
2861 
2862  multixact_freeze_table_age = (avopts &&
2863  avopts->multixact_freeze_table_age >= 0)
2864  ? avopts->multixact_freeze_table_age
2866 
2867  tab = palloc(sizeof(autovac_table));
2868  tab->at_relid = relid;
2869  tab->at_sharedrel = classForm->relisshared;
2871  (dovacuum ? VACOPT_VACUUM : 0) |
2872  (doanalyze ? VACOPT_ANALYZE : 0) |
2873  (!wraparound ? VACOPT_NOWAIT : 0);
2874  tab->at_params.freeze_min_age = freeze_min_age;
2875  tab->at_params.freeze_table_age = freeze_table_age;
2876  tab->at_params.multixact_freeze_min_age = multixact_freeze_min_age;
2877  tab->at_params.multixact_freeze_table_age = multixact_freeze_table_age;
2878  tab->at_params.is_wraparound = wraparound;
2879  tab->at_params.log_min_duration = log_min_duration;
2880  tab->at_vacuum_cost_limit = vac_cost_limit;
2881  tab->at_vacuum_cost_delay = vac_cost_delay;
2882  tab->at_relname = NULL;
2883  tab->at_nspname = NULL;
2884  tab->at_datname = NULL;
2885 
2886  /*
2887  * If any of the cost delay parameters has been set individually for
2888  * this table, disable the balancing algorithm.
2889  */
2890  tab->at_dobalance =
2891  !(avopts && (avopts->vacuum_cost_limit > 0 ||
2892  avopts->vacuum_cost_delay > 0));
2893  }
2894 
2895  heap_freetuple(classTup);
2896 
2897  return tab;
2898 }
int vacuum_cost_delay
Definition: rel.h:263
int multixact_freeze_table_age
Definition: vacuum.h:142
static int default_freeze_table_age
Definition: autovacuum.c:152
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
int at_vacuum_cost_delay
Definition: autovacuum.c:194
static int default_multixact_freeze_min_age
Definition: autovacuum.c:153
int freeze_min_age
Definition: rel.h:265
static void autovac_refresh_stats(void)
Definition: autovacuum.c:3334
PgStat_StatDBEntry * pgstat_fetch_stat_dbentry(Oid dbid)
Definition: pgstat.c:2387
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
char * at_datname
Definition: autovacuum.c:200
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
int freeze_table_age
Definition: vacuum.h:139
int autovacuum_vac_cost_limit
Definition: autovacuum.c:126
bool at_sharedrel
Definition: autovacuum.c:197
int freeze_table_age
Definition: rel.h:267
int at_vacuum_cost_limit
Definition: autovacuum.c:195
char * at_relname
Definition: autovacuum.c:198
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
int VacuumCostLimit
Definition: globals.c:131
int freeze_min_age
Definition: vacuum.h:138
bool is_wraparound
Definition: vacuum.h:144
static AutoVacOpts * extract_autovac_opts(HeapTuple tup, TupleDesc pg_class_desc)
Definition: autovacuum.c:2703
static PgStat_StatTabEntry * get_pgstat_tabentry_relid(Oid relid, bool isshared, PgStat_StatDBEntry *shared, PgStat_StatDBEntry *dbentry)
Definition: autovacuum.c:2729
static void relation_needs_vacanalyze(Oid relid, AutoVacOpts *relopts, Form_pg_class classForm, PgStat_StatTabEntry *tabentry, int effective_multixact_freeze_max_age, bool *dovacuum, bool *doanalyze, bool *wraparound)
Definition: autovacuum.c:2938
int autovacuum_vac_cost_delay
Definition: autovacuum.c:125
char * at_nspname
Definition: autovacuum.c:199
int multixact_freeze_table_age
Definition: rel.h:270
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
Oid MyDatabaseId
Definition: globals.c:77
#define InvalidOid
Definition: postgres_ext.h:36
int VacuumCostDelay
Definition: globals.c:132
VacuumParams at_params
Definition: autovacuum.c:193
int vacuum_cost_limit
Definition: rel.h:264
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
int multixact_freeze_min_age
Definition: rel.h:268
int log_min_duration
Definition: vacuum.h:145
int log_min_duration
Definition: rel.h:271
int Log_autovacuum_min_duration
Definition: autovacuum.c:128
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:173
AutoVacOpts ar_reloptions
Definition: autovacuum.c:184
void * palloc(Size size)
Definition: mcxt.c:848
bool ar_hasrelopts
Definition: autovacuum.c:183
static int default_multixact_freeze_table_age
Definition: autovacuum.c:154
int multixact_freeze_min_age
Definition: vacuum.h:140
static int default_freeze_min_age
Definition: autovacuum.c:151
bool at_dobalance
Definition: autovacuum.c:196

Variable Documentation

bool am_autovacuum_launcher = false
static

Definition at line 138 of file autovacuum.c.

Referenced by AutoVacLauncherMain(), and IsAutoVacuumLauncherProcess().

bool am_autovacuum_worker = false
static

Definition at line 139 of file autovacuum.c.

Referenced by AutoVacWorkerMain(), and IsAutoVacuumWorkerProcess().

MemoryContext AutovacMemCxt
static

Definition at line 157 of file autovacuum.c.

double autovacuum_anl_scale

Definition at line 121 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_anl_thresh

Definition at line 120 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_freeze_max_age
int autovacuum_multixact_freeze_max_age

Definition at line 123 of file autovacuum.c.

Referenced by MultiXactMemberFreezeThreshold(), and SetMultiXactIdLimit().

int autovacuum_naptime
bool autovacuum_start_daemon = false

Definition at line 114 of file autovacuum.c.

Referenced by autovac_init(), and AutoVacuumingActive().

int autovacuum_vac_cost_delay

Definition at line 125 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

int autovacuum_vac_cost_limit

Definition at line 126 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

double autovacuum_vac_scale

Definition at line 119 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_vac_thresh

Definition at line 118 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_work_mem = -1

Definition at line 116 of file autovacuum.c.

Referenced by ginInsertCleanup(), and lazy_space_alloc().

int AutovacuumLauncherPid = 0

Definition at line 306 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

AutoVacuumShmemStruct* AutoVacuumShmem
static

Definition at line 293 of file autovacuum.c.

dlist_head DatabaseList = DLIST_STATIC_INIT(DatabaseList)
static

Definition at line 299 of file autovacuum.c.

MemoryContext DatabaseListCxt = NULL
static

Definition at line 300 of file autovacuum.c.

int default_freeze_min_age
static

Definition at line 151 of file autovacuum.c.

Referenced by do_autovacuum(), and table_recheck_autovac().

int default_freeze_table_age
static

Definition at line 152 of file autovacuum.c.

Referenced by do_autovacuum(), and table_recheck_autovac().

int default_multixact_freeze_min_age
static

Definition at line 153 of file autovacuum.c.

Referenced by do_autovacuum(), and table_recheck_autovac().

int default_multixact_freeze_table_age
static

Definition at line 154 of file autovacuum.c.

Referenced by do_autovacuum(), and table_recheck_autovac().

volatile sig_atomic_t got_SIGHUP = false
static

Definition at line 142 of file autovacuum.c.

Referenced by AutoVacLauncherMain(), av_sighup_handler(), and do_autovacuum().

volatile sig_atomic_t got_SIGTERM = false
static

Definition at line 144 of file autovacuum.c.

Referenced by AutoVacLauncherMain(), and avl_sigterm_handler().

volatile sig_atomic_t got_SIGUSR2 = false
static

Definition at line 143 of file autovacuum.c.

Referenced by AutoVacLauncherMain(), and avl_sigusr2_handler().

int Log_autovacuum_min_duration = -1

Definition at line 128 of file autovacuum.c.

Referenced by table_recheck_autovac().

WorkerInfo MyWorkerInfo = NULL
static

Definition at line 303 of file autovacuum.c.

MultiXactId recentMulti
static

Definition at line 148 of file autovacuum.c.

Referenced by AutoVacWorkerMain(), do_start_worker(), and relation_needs_vacanalyze().

TransactionId recentXid
static

Definition at line 147 of file autovacuum.c.

Referenced by AutoVacWorkerMain(), do_start_worker(), and relation_needs_vacanalyze().