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

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

Referenced by PostmasterMain().

3225 {
3227  ereport(WARNING,
3228  (errmsg("autovacuum not started because of misconfiguration"),
3229  errhint("Enable the \"track_counts\" option.")));
3230 }
int errhint(const char *fmt,...)
Definition: elog.c:987
bool autovacuum_start_daemon
Definition: autovacuum.c:113
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 3175 of file autovacuum.c.

References autovacuum_start_daemon, and pgstat_track_counts.

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

3176 {
3178  return false;
3179  return true;
3180 }
bool autovacuum_start_daemon
Definition: autovacuum.c:113
bool pgstat_track_counts
Definition: pgstat.c:126
void AutoVacuumRequestWork ( AutoVacuumWorkItemType  type,
Oid  relationId,
BlockNumber  blkno 
)

Definition at line 3186 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().

3188 {
3189  int i;
3190 
3191  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3192 
3193  /*
3194  * Locate an unused work item and fill it with the given data.
3195  */
3196  for (i = 0; i < NUM_WORKITEMS; i++)
3197  {
3199 
3200  if (workitem->avw_used)
3201  continue;
3202 
3203  workitem->avw_used = true;
3204  workitem->avw_active = false;
3205  workitem->avw_type = type;
3206  workitem->avw_database = MyDatabaseId;
3207  workitem->avw_relation = relationId;
3208  workitem->avw_blockNumber = blkno;
3209 
3210  /* done */
3211  break;
3212  }
3213 
3214  LWLockRelease(AutovacuumLock);
3215 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:256
#define NUM_WORKITEMS
Definition: autovacuum.c:264
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:289
Oid MyDatabaseId
Definition: globals.c:77
BlockNumber avw_blockNumber
Definition: autovacuum.c:261
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:292
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
int i
void AutoVacuumShmemInit ( void  )

Definition at line 3274 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, NULL, NUM_WORKITEMS, ShmemInitStruct(), and WorkerInfoData::wi_links.

Referenced by CreateSharedMemoryAndSemaphores().

3275 {
3276  bool found;
3277 
3279  ShmemInitStruct("AutoVacuum Data",
3281  &found);
3282 
3283  if (!IsUnderPostmaster)
3284  {
3285  WorkerInfo worker;
3286  int i;
3287 
3288  Assert(!found);
3289 
3294  memset(AutoVacuumShmem->av_workItems, 0,
3295  sizeof(AutoVacuumWorkItem) * NUM_WORKITEMS);
3296 
3297  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3298  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3299 
3300  /* initialize the WorkerInfo free list */
3301  for (i = 0; i < autovacuum_max_workers; i++)
3303  &worker[i].wi_links);
3304  }
3305  else
3306  Assert(found);
3307 }
#define NUM_WORKITEMS
Definition: autovacuum.c:264
WorkerInfo av_startingWorker
Definition: autovacuum.c:288
dlist_head av_freeWorkers
Definition: autovacuum.c:286
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
struct WorkerInfoData * WorkerInfo
Definition: autovacuum.c:234
dlist_node wi_links
Definition: autovacuum.c:222
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:289
bool IsUnderPostmaster
Definition: globals.c:101
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3255
int autovacuum_max_workers
Definition: autovacuum.c:114
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:292
#define MAXALIGN(LEN)
Definition: c.h:588
int i
dlist_head av_runningWorkers
Definition: autovacuum.c:287
Size AutoVacuumShmemSize ( void  )

Definition at line 3255 of file autovacuum.c.

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

Referenced by AutoVacuumShmemInit(), and CreateSharedMemoryAndSemaphores().

3256 {
3257  Size size;
3258 
3259  /*
3260  * Need the fixed struct and the array of WorkerInfoData.
3261  */
3262  size = sizeof(AutoVacuumShmemStruct);
3263  size = MAXALIGN(size);
3265  sizeof(WorkerInfoData)));
3266  return size;
3267 }
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:114
size_t Size
Definition: c.h:356
#define MAXALIGN(LEN)
Definition: c.h:588
void AutoVacuumUpdateDelay ( void  )

Definition at line 1759 of file autovacuum.c.

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

Referenced by do_autovacuum(), and vacuum_delay_point().

1760 {
1761  if (MyWorkerInfo)
1762  {
1765  }
1766 }
int VacuumCostLimit
Definition: globals.c:132
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:302
int VacuumCostDelay
Definition: globals.c:133
void AutoVacWorkerFailed ( void  )

Definition at line 1392 of file autovacuum.c.

References AutoVacForkFailed, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

1393 {
1395 }
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:284
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:292
bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3238 of file autovacuum.c.

References am_autovacuum_launcher.

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

3239 {
3240  return am_autovacuum_launcher;
3241 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:137
int StartAutoVacLauncher ( void  )

Definition at line 394 of file autovacuum.c.

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

Referenced by reaper(), and ServerLoop().

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

Definition at line 1476 of file autovacuum.c.

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

Referenced by StartAutovacuumWorker().

1477 {
1478  pid_t worker_pid;
1479 
1480 #ifdef EXEC_BACKEND
1481  switch ((worker_pid = avworker_forkexec()))
1482 #else
1483  switch ((worker_pid = fork_process()))
1484 #endif
1485  {
1486  case -1:
1487  ereport(LOG,
1488  (errmsg("could not fork autovacuum worker process: %m")));
1489  return 0;
1490 
1491 #ifndef EXEC_BACKEND
1492  case 0:
1493  /* in postmaster child ... */
1495 
1496  /* Close the postmaster's sockets */
1497  ClosePostmasterPorts(false);
1498 
1499  AutoVacWorkerMain(0, NULL);
1500  break;
1501 #endif
1502  default:
1503  return (int) worker_pid;
1504  }
1505 
1506  /* shouldn't get here */
1507  return 0;
1508 }
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:1514
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2449
#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 120 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_anl_thresh

Definition at line 119 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_freeze_max_age
int autovacuum_multixact_freeze_max_age

Definition at line 122 of file autovacuum.c.

Referenced by MultiXactMemberFreezeThreshold(), and SetMultiXactIdLimit().

int autovacuum_naptime
bool autovacuum_start_daemon

Definition at line 113 of file autovacuum.c.

Referenced by autovac_init(), and AutoVacuumingActive().

int autovacuum_vac_cost_delay

Definition at line 124 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

int autovacuum_vac_cost_limit

Definition at line 125 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

double autovacuum_vac_scale

Definition at line 118 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_vac_thresh

Definition at line 117 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

int autovacuum_work_mem

Definition at line 115 of file autovacuum.c.

Referenced by ginInsertCleanup(), and lazy_space_alloc().

int AutovacuumLauncherPid

Definition at line 305 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

int Log_autovacuum_min_duration

Definition at line 127 of file autovacuum.c.

Referenced by table_recheck_autovac().