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 3341 of file autovacuum.c.

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

Referenced by PostmasterMain().

3342 {
3344  ereport(WARNING,
3345  (errmsg("autovacuum not started because of misconfiguration"),
3346  errhint("Enable the \"track_counts\" option.")));
3347 }
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 3220 of file autovacuum.c.

References autovacuum_start_daemon, and pgstat_track_counts.

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

3221 {
3223  return false;
3224  return true;
3225 }
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 3231 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().

3233 {
3234  AutovacWorkItems *workitems;
3235  dsa_pointer wi_ptr;
3236  AutoVacuumWorkItem *workitem;
3237 
3238  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3239 
3240  /*
3241  * It may be useful to de-duplicate the list upon insertion. For the only
3242  * currently existing caller, this is not necessary.
3243  */
3244 
3245  /* First use in this process? Set up DSA */
3246  if (!AutoVacuumDSA)
3247  {
3249  {
3250  /* autovacuum launcher not started; nothing can be done */
3251  LWLockRelease(AutovacuumLock);
3252  return;
3253  }
3256  }
3257 
3258  /* First use overall? Allocate work items array */
3260  {
3261  int i;
3262  AutovacWorkItems *workitems;
3263 
3266  sizeof(AutovacWorkItems) +
3269  /* if out of memory, silently disregard the request */
3271  {
3272  LWLockRelease(AutovacuumLock);
3274  AutoVacuumDSA = NULL;
3275  return;
3276  }
3277 
3278  /* Initialize each array entry as a member of the free list */
3280 
3281  workitems->avs_usedItems = InvalidDsaPointer;
3282  workitems->avs_freeItems = InvalidDsaPointer;
3283  for (i = 0; i < NUM_WORKITEMS; i++)
3284  {
3285  /* XXX surely there is a simpler way to do this */
3286  wi_ptr = AutoVacuumShmem->av_workitems + sizeof(AutovacWorkItems) +
3287  sizeof(AutoVacuumWorkItem) * i;
3288  workitem = (AutoVacuumWorkItem *) dsa_get_address(AutoVacuumDSA, wi_ptr);
3289 
3290  workitem->avw_type = 0;
3291  workitem->avw_database = InvalidOid;
3292  workitem->avw_relation = InvalidOid;
3293  workitem->avw_active = false;
3294 
3295  /* put this item in the free list */
3296  workitem->avw_next = workitems->avs_freeItems;
3297  workitems->avs_freeItems = wi_ptr;
3298  }
3299  }
3300 
3301  workitems = (AutovacWorkItems *)
3303 
3304  /* If array is full, disregard the request */
3305  if (workitems->avs_freeItems == InvalidDsaPointer)
3306  {
3307  LWLockRelease(AutovacuumLock);
3309  AutoVacuumDSA = NULL;
3310  return;
3311  }
3312 
3313  /* remove workitem struct from free list ... */
3314  wi_ptr = workitems->avs_freeItems;
3315  remove_wi_from_list(&workitems->avs_freeItems, wi_ptr);
3316 
3317  /* ... initialize it ... */
3318  workitem = dsa_get_address(AutoVacuumDSA, wi_ptr);
3319  workitem->avw_type = type;
3320  workitem->avw_database = MyDatabaseId;
3321  workitem->avw_relation = relationId;
3322  workitem->avw_blockNumber = blkno;
3323  workitem->avw_active = false;
3324 
3325  /* ... and put it on autovacuum's to-do list */
3326  add_wi_to_list(&workitems->avs_usedItems, wi_ptr);
3327 
3328  LWLockRelease(AutovacuumLock);
3329 
3331  AutoVacuumDSA = NULL;
3332 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:294
static void remove_wi_from_list(dsa_pointer *list, dsa_pointer wi_ptr)
Definition: autovacuum.c:3466
#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:3493
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:77
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 3391 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().

3392 {
3393  bool found;
3394 
3396  ShmemInitStruct("AutoVacuum Data",
3398  &found);
3399 
3400  if (!IsUnderPostmaster)
3401  {
3402  WorkerInfo worker;
3403  int i;
3404 
3405  Assert(!found);
3406 
3411 
3412  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3413  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3414 
3415  /* initialize the WorkerInfo free list */
3416  for (i = 0; i < autovacuum_max_workers; i++)
3418  &worker[i].wi_links);
3419  }
3420  else
3421  Assert(found);
3422 }
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:101
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3372
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 3372 of file autovacuum.c.

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

Referenced by AutoVacuumShmemInit(), and CreateSharedMemoryAndSemaphores().

3373 {
3374  Size size;
3375 
3376  /*
3377  * Need the fixed struct and the array of WorkerInfoData.
3378  */
3379  size = sizeof(AutoVacuumShmemStruct);
3380  size = MAXALIGN(size);
3382  sizeof(WorkerInfoData)));
3383  return size;
3384 }
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 1780 of file autovacuum.c.

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

Referenced by do_autovacuum(), and vacuum_delay_point().

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

Definition at line 1405 of file autovacuum.c.

References AutoVacForkFailed, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

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

Definition at line 3355 of file autovacuum.c.

References am_autovacuum_launcher.

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

3356 {
3357  return am_autovacuum_launcher;
3358 }
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:2434
#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 1489 of file autovacuum.c.

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

Referenced by StartAutovacuumWorker().

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