PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
autovacuum.h File Reference
#include "storage/block.h"
Include dependency graph for autovacuum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IsAnyAutoVacuumProcess()   (IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess())
 

Enumerations

enum  AutoVacuumWorkItemType { AVW_BRINSummarizeRange }
 

Functions

bool AutoVacuumingActive (void)
 
bool IsAutoVacuumLauncherProcess (void)
 
bool IsAutoVacuumWorkerProcess (void)
 
void autovac_init (void)
 
int StartAutoVacLauncher (void)
 
int StartAutoVacWorker (void)
 
void AutoVacWorkerFailed (void)
 
void AutoVacuumUpdateDelay (void)
 
void AutoVacuumRequestWork (AutoVacuumWorkItemType type, Oid relationId, BlockNumber blkno)
 
Size AutoVacuumShmemSize (void)
 
void AutoVacuumShmemInit (void)
 

Variables

bool autovacuum_start_daemon
 
int autovacuum_max_workers
 
int autovacuum_work_mem
 
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 AutovacuumLauncherPid
 
int Log_autovacuum_min_duration
 

Macro Definition Documentation

#define IsAnyAutoVacuumProcess ( )    (IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess())

Definition at line 53 of file autovacuum.h.

Referenced by InitProcess().

Enumeration Type Documentation

Enumerator
AVW_BRINSummarizeRange 

Definition at line 23 of file autovacuum.h.

Function Documentation

void autovac_init ( void  )

Definition at line 3340 of file autovacuum.c.

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

Referenced by PostmasterMain().

3341 {
3343  ereport(WARNING,
3344  (errmsg("autovacuum not started because of misconfiguration"),
3345  errhint("Enable the \"track_counts\" option.")));
3346 }
int errhint(const char *fmt,...)
Definition: elog.c:987
bool autovacuum_start_daemon
Definition: autovacuum.c:112
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
bool AutoVacuumingActive ( void  )

Definition at line 3219 of file autovacuum.c.

References autovacuum_start_daemon, and pgstat_track_counts.

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

3220 {
3222  return false;
3223  return true;
3224 }
bool autovacuum_start_daemon
Definition: autovacuum.c:112
bool pgstat_track_counts
Definition: pgstat.c:126
void AutoVacuumRequestWork ( AutoVacuumWorkItemType  type,
Oid  relationId,
BlockNumber  blkno 
)

Definition at line 3230 of file autovacuum.c.

References add_wi_to_list(), AutoVacuumShmemStruct::av_dsa_handle, AutoVacuumShmemStruct::av_workitems, AutovacWorkItems::avs_freeItems, AutovacWorkItems::avs_usedItems, AutoVacuumWorkItem::avw_active, AutoVacuumWorkItem::avw_blockNumber, AutoVacuumWorkItem::avw_database, AutoVacuumWorkItem::avw_next, AutoVacuumWorkItem::avw_relation, AutoVacuumWorkItem::avw_type, DSA_ALLOC_NO_OOM, dsa_allocate_extended(), dsa_attach(), dsa_detach(), dsa_get_address(), dsa_pin_mapping(), i, InvalidDsaPointer, InvalidOid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyDatabaseId, NULL, NUM_WORKITEMS, and remove_wi_from_list().

Referenced by brininsert().

3232 {
3233  AutovacWorkItems *workitems;
3234  dsa_pointer wi_ptr;
3235  AutoVacuumWorkItem *workitem;
3236 
3237  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3238 
3239  /*
3240  * It may be useful to de-duplicate the list upon insertion. For the only
3241  * currently existing caller, this is not necessary.
3242  */
3243 
3244  /* First use in this process? Set up DSA */
3245  if (!AutoVacuumDSA)
3246  {
3248  {
3249  /* autovacuum launcher not started; nothing can be done */
3250  LWLockRelease(AutovacuumLock);
3251  return;
3252  }
3255  }
3256 
3257  /* First use overall? Allocate work items array */
3259  {
3260  int i;
3261  AutovacWorkItems *workitems;
3262 
3265  sizeof(AutovacWorkItems) +
3268  /* if out of memory, silently disregard the request */
3270  {
3271  LWLockRelease(AutovacuumLock);
3273  AutoVacuumDSA = NULL;
3274  return;
3275  }
3276 
3277  /* Initialize each array entry as a member of the free list */
3279 
3280  workitems->avs_usedItems = InvalidDsaPointer;
3281  workitems->avs_freeItems = InvalidDsaPointer;
3282  for (i = 0; i < NUM_WORKITEMS; i++)
3283  {
3284  /* XXX surely there is a simpler way to do this */
3285  wi_ptr = AutoVacuumShmem->av_workitems + sizeof(AutovacWorkItems) +
3286  sizeof(AutoVacuumWorkItem) * i;
3287  workitem = (AutoVacuumWorkItem *) dsa_get_address(AutoVacuumDSA, wi_ptr);
3288 
3289  workitem->avw_type = 0;
3290  workitem->avw_database = InvalidOid;
3291  workitem->avw_relation = InvalidOid;
3292  workitem->avw_active = false;
3293 
3294  /* put this item in the free list */
3295  workitem->avw_next = workitems->avs_freeItems;
3296  workitems->avs_freeItems = wi_ptr;
3297  }
3298  }
3299 
3300  workitems = (AutovacWorkItems *)
3302 
3303  /* If array is full, disregard the request */
3304  if (workitems->avs_freeItems == InvalidDsaPointer)
3305  {
3306  LWLockRelease(AutovacuumLock);
3308  AutoVacuumDSA = NULL;
3309  return;
3310  }
3311 
3312  /* remove workitem struct from free list ... */
3313  wi_ptr = workitems->avs_freeItems;
3314  remove_wi_from_list(&workitems->avs_freeItems, wi_ptr);
3315 
3316  /* ... initialize it ... */
3317  workitem = dsa_get_address(AutoVacuumDSA, wi_ptr);
3318  workitem->avw_type = type;
3319  workitem->avw_database = MyDatabaseId;
3320  workitem->avw_relation = relationId;
3321  workitem->avw_blockNumber = blkno;
3322  workitem->avw_active = false;
3323 
3324  /* ... and put it on autovacuum's to-do list */
3325  add_wi_to_list(&workitems->avs_usedItems, wi_ptr);
3326 
3327  LWLockRelease(AutovacuumLock);
3328 
3330  AutoVacuumDSA = NULL;
3331 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:294
static void remove_wi_from_list(dsa_pointer *list, dsa_pointer wi_ptr)
Definition: autovacuum.c:3465
#define NUM_WORKITEMS
Definition: autovacuum.c:303
#define DSA_ALLOC_NO_OOM
Definition: dsa.h:74
#define InvalidDsaPointer
Definition: dsa.h:78
dsa_pointer dsa_allocate_extended(dsa_area *area, Size size, int flags)
Definition: dsa.c:664
uint64 dsa_pointer
Definition: dsa.h:62
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition: dsa.c:924
dsa_handle av_dsa_handle
Definition: autovacuum.c:270
dsa_pointer avw_next
Definition: autovacuum.c:299
static void add_wi_to_list(dsa_pointer *list, dsa_pointer wi_ptr)
Definition: autovacuum.c:3492
dsa_pointer avs_freeItems
Definition: autovacuum.c:307
void dsa_detach(dsa_area *area)
Definition: dsa.c:1884
void dsa_pin_mapping(dsa_area *area)
Definition: dsa.c:630
dsa_pointer av_workitems
Definition: autovacuum.c:271
Oid MyDatabaseId
Definition: globals.c:76
BlockNumber avw_blockNumber
Definition: autovacuum.c:297
dsa_area * dsa_attach(dsa_handle handle)
Definition: dsa.c:505
dsa_pointer avs_usedItems
Definition: autovacuum.c:306
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:274
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
int i
static dsa_area * AutoVacuumDSA
Definition: autovacuum.c:310
void AutoVacuumShmemInit ( void  )

Definition at line 3390 of file autovacuum.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

3391 {
3392  bool found;
3393 
3395  ShmemInitStruct("AutoVacuum Data",
3397  &found);
3398 
3399  if (!IsUnderPostmaster)
3400  {
3401  WorkerInfo worker;
3402  int i;
3403 
3404  Assert(!found);
3405 
3410 
3411  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3412  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3413 
3414  /* initialize the WorkerInfo free list */
3415  for (i = 0; i < autovacuum_max_workers; i++)
3417  &worker[i].wi_links);
3418  }
3419  else
3420  Assert(found);
3421 }
WorkerInfo av_startingWorker
Definition: autovacuum.c:269
dlist_head av_freeWorkers
Definition: autovacuum.c:267
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
struct WorkerInfoData * WorkerInfo
Definition: autovacuum.c:233
dlist_node wi_links
Definition: autovacuum.c:221
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
bool IsUnderPostmaster
Definition: globals.c:100
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3371
int autovacuum_max_workers
Definition: autovacuum.c:113
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:274
#define MAXALIGN(LEN)
Definition: c.h:588
int i
dlist_head av_runningWorkers
Definition: autovacuum.c:268
Size AutoVacuumShmemSize ( void  )

Definition at line 3371 of file autovacuum.c.

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

Referenced by AutoVacuumShmemInit(), and CreateSharedMemoryAndSemaphores().

3372 {
3373  Size size;
3374 
3375  /*
3376  * Need the fixed struct and the array of WorkerInfoData.
3377  */
3378  size = sizeof(AutoVacuumShmemStruct);
3379  size = MAXALIGN(size);
3381  sizeof(WorkerInfoData)));
3382  return size;
3383 }
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:113
size_t Size
Definition: c.h:356
#define MAXALIGN(LEN)
Definition: c.h:588
void AutoVacuumUpdateDelay ( void  )

Definition at line 1779 of file autovacuum.c.

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

Referenced by do_autovacuum(), and vacuum_delay_point().

1780 {
1781  if (MyWorkerInfo)
1782  {
1785  }
1786 }
int VacuumCostLimit
Definition: globals.c:131
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:284
int VacuumCostDelay
Definition: globals.c:132
void AutoVacWorkerFailed ( void  )

Definition at line 1404 of file autovacuum.c.

References AutoVacForkFailed, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

1405 {
1407 }
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:265
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:274
bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3354 of file autovacuum.c.

References am_autovacuum_launcher.

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

3355 {
3356  return am_autovacuum_launcher;
3357 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:136
int StartAutoVacLauncher ( void  )

Definition at line 404 of file autovacuum.c.

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

Referenced by reaper(), and ServerLoop().

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

Definition at line 1488 of file autovacuum.c.

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

Referenced by StartAutovacuumWorker().

1489 {
1490  pid_t worker_pid;
1491 
1492 #ifdef EXEC_BACKEND
1493  switch ((worker_pid = avworker_forkexec()))
1494 #else
1495  switch ((worker_pid = fork_process()))
1496 #endif
1497  {
1498  case -1:
1499  ereport(LOG,
1500  (errmsg("could not fork autovacuum worker process: %m")));
1501  return 0;
1502 
1503 #ifndef EXEC_BACKEND
1504  case 0:
1505  /* in postmaster child ... */
1507 
1508  /* Close the postmaster's sockets */
1509  ClosePostmasterPorts(false);
1510 
1511  AutoVacWorkerMain(0, NULL);
1512  break;
1513 #endif
1514  default:
1515  return (int) worker_pid;
1516  }
1517 
1518  /* shouldn't get here */
1519  return 0;
1520 }
void InitPostmasterChild(void)
Definition: miscinit.c:175
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:1526
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2435
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797

Variable Documentation

double autovacuum_anl_scale

Definition at line 119 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_anl_thresh

Definition at line 118 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_freeze_max_age
int autovacuum_multixact_freeze_max_age

Definition at line 121 of file autovacuum.c.

Referenced by MultiXactMemberFreezeThreshold(), and SetMultiXactIdLimit().

int autovacuum_naptime
bool autovacuum_start_daemon

Definition at line 112 of file autovacuum.c.

Referenced by autovac_init(), and AutoVacuumingActive().

int autovacuum_vac_cost_delay

Definition at line 123 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

int autovacuum_vac_cost_limit

Definition at line 124 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

double autovacuum_vac_scale

Definition at line 117 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_vac_thresh

Definition at line 116 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_work_mem

Definition at line 114 of file autovacuum.c.

Referenced by ginInsertCleanup(), and lazy_space_alloc().

int AutovacuumLauncherPid

Definition at line 313 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

int Log_autovacuum_min_duration

Definition at line 126 of file autovacuum.c.

Referenced by table_recheck_autovac().