PostgreSQL Source Code  git master
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)
 
bool 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
 
double autovacuum_vac_cost_delay
 
int autovacuum_vac_cost_limit
 
int AutovacuumLauncherPid
 
int Log_autovacuum_min_duration
 

Macro Definition Documentation

◆ IsAnyAutoVacuumProcess

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

Definition at line 53 of file autovacuum.h.

Referenced by InitProcess().

Enumeration Type Documentation

◆ AutoVacuumWorkItemType

Enumerator
AVW_BRINSummarizeRange 

Definition at line 23 of file autovacuum.h.

Function Documentation

◆ autovac_init()

void autovac_init ( void  )

Definition at line 3261 of file autovacuum.c.

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

Referenced by PostmasterMain().

3262 {
3264  ereport(WARNING,
3265  (errmsg("autovacuum not started because of misconfiguration"),
3266  errhint("Enable the \"track_counts\" option.")));
3267 }
int errhint(const char *fmt,...)
Definition: elog.c:1071
bool autovacuum_start_daemon
Definition: autovacuum.c:113
bool pgstat_track_counts
Definition: pgstat.c:124
#define ereport(elevel, rest)
Definition: elog.h:141
#define WARNING
Definition: elog.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ AutoVacuumingActive()

bool AutoVacuumingActive ( void  )

Definition at line 3207 of file autovacuum.c.

References autovacuum_start_daemon, and pgstat_track_counts.

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

3208 {
3210  return false;
3211  return true;
3212 }
bool autovacuum_start_daemon
Definition: autovacuum.c:113
bool pgstat_track_counts
Definition: pgstat.c:124

◆ AutoVacuumRequestWork()

bool AutoVacuumRequestWork ( AutoVacuumWorkItemType  type,
Oid  relationId,
BlockNumber  blkno 
)

Definition at line 3219 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, NUM_WORKITEMS, and generate_unaccent_rules::type.

Referenced by brininsert().

3221 {
3222  int i;
3223  bool result = false;
3224 
3225  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3226 
3227  /*
3228  * Locate an unused work item and fill it with the given data.
3229  */
3230  for (i = 0; i < NUM_WORKITEMS; i++)
3231  {
3233 
3234  if (workitem->avw_used)
3235  continue;
3236 
3237  workitem->avw_used = true;
3238  workitem->avw_active = false;
3239  workitem->avw_type = type;
3240  workitem->avw_database = MyDatabaseId;
3241  workitem->avw_relation = relationId;
3242  workitem->avw_blockNumber = blkno;
3243  result = true;
3244 
3245  /* done */
3246  break;
3247  }
3248 
3249  LWLockRelease(AutovacuumLock);
3250 
3251  return result;
3252 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:255
#define NUM_WORKITEMS
Definition: autovacuum.c:263
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:288
Oid MyDatabaseId
Definition: globals.c:85
BlockNumber avw_blockNumber
Definition: autovacuum.c:260
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:291
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
int i

◆ AutoVacuumShmemInit()

void AutoVacuumShmemInit ( void  )

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

3312 {
3313  bool found;
3314 
3316  ShmemInitStruct("AutoVacuum Data",
3318  &found);
3319 
3320  if (!IsUnderPostmaster)
3321  {
3322  WorkerInfo worker;
3323  int i;
3324 
3325  Assert(!found);
3326 
3331  memset(AutoVacuumShmem->av_workItems, 0,
3332  sizeof(AutoVacuumWorkItem) * NUM_WORKITEMS);
3333 
3334  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3335  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3336 
3337  /* initialize the WorkerInfo free list */
3338  for (i = 0; i < autovacuum_max_workers; i++)
3340  &worker[i].wi_links);
3341  }
3342  else
3343  Assert(found);
3344 }
#define NUM_WORKITEMS
Definition: autovacuum.c:263
WorkerInfo av_startingWorker
Definition: autovacuum.c:287
dlist_head av_freeWorkers
Definition: autovacuum.c:285
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
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:288
bool IsUnderPostmaster
Definition: globals.c:109
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3292
int autovacuum_max_workers
Definition: autovacuum.c:114
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define Assert(condition)
Definition: c.h:733
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:291
#define MAXALIGN(LEN)
Definition: c.h:686
int i
dlist_head av_runningWorkers
Definition: autovacuum.c:286

◆ AutoVacuumShmemSize()

Size AutoVacuumShmemSize ( void  )

Definition at line 3292 of file autovacuum.c.

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

Referenced by AutoVacuumShmemInit(), and CreateSharedMemoryAndSemaphores().

3293 {
3294  Size size;
3295 
3296  /*
3297  * Need the fixed struct and the array of WorkerInfoData.
3298  */
3299  size = sizeof(AutoVacuumShmemStruct);
3300  size = MAXALIGN(size);
3302  sizeof(WorkerInfoData)));
3303  return size;
3304 }
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:467
#define MAXALIGN(LEN)
Definition: c.h:686

◆ AutoVacuumUpdateDelay()

void AutoVacuumUpdateDelay ( void  )

Definition at line 1763 of file autovacuum.c.

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

Referenced by do_autovacuum(), and vacuum_delay_point().

1764 {
1765  if (MyWorkerInfo)
1766  {
1769  }
1770 }
double wi_cost_delay
Definition: autovacuum.c:228
int VacuumCostLimit
Definition: globals.c:140
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:301
double VacuumCostDelay
Definition: globals.c:141

◆ AutoVacWorkerFailed()

void AutoVacWorkerFailed ( void  )

Definition at line 1385 of file autovacuum.c.

References AutoVacForkFailed, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

1386 {
1388 }
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:283
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:291

◆ IsAutoVacuumLauncherProcess()

bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3275 of file autovacuum.c.

References am_autovacuum_launcher.

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

3276 {
3277  return am_autovacuum_launcher;
3278 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:137

◆ IsAutoVacuumWorkerProcess()

◆ StartAutoVacLauncher()

int StartAutoVacLauncher ( void  )

Definition at line 393 of file autovacuum.c.

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

Referenced by reaper(), and ServerLoop().

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

◆ StartAutoVacWorker()

int StartAutoVacWorker ( void  )

Definition at line 1469 of file autovacuum.c.

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

Referenced by StartAutovacuumWorker().

1470 {
1471  pid_t worker_pid;
1472 
1473 #ifdef EXEC_BACKEND
1474  switch ((worker_pid = avworker_forkexec()))
1475 #else
1476  switch ((worker_pid = fork_process()))
1477 #endif
1478  {
1479  case -1:
1480  ereport(LOG,
1481  (errmsg("could not fork autovacuum worker process: %m")));
1482  return 0;
1483 
1484 #ifndef EXEC_BACKEND
1485  case 0:
1486  /* in postmaster child ... */
1488 
1489  /* Close the postmaster's sockets */
1490  ClosePostmasterPorts(false);
1491 
1492  AutoVacWorkerMain(0, NULL);
1493  break;
1494 #endif
1495  default:
1496  return (int) worker_pid;
1497  }
1498 
1499  /* shouldn't get here */
1500  return 0;
1501 }
void InitPostmasterChild(void)
Definition: miscinit.c:273
pid_t fork_process(void)
Definition: fork_process.c:32
#define LOG
Definition: elog.h:26
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: autovacuum.c:1507
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2541
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822

Variable Documentation

◆ autovacuum_anl_scale

double autovacuum_anl_scale

Definition at line 120 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_anl_thresh

int autovacuum_anl_thresh

Definition at line 119 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_freeze_max_age

int autovacuum_freeze_max_age

◆ autovacuum_max_workers

◆ autovacuum_multixact_freeze_max_age

int autovacuum_multixact_freeze_max_age

Definition at line 122 of file autovacuum.c.

Referenced by MultiXactMemberFreezeThreshold(), and SetMultiXactIdLimit().

◆ autovacuum_naptime

int autovacuum_naptime

◆ autovacuum_start_daemon

bool autovacuum_start_daemon

Definition at line 113 of file autovacuum.c.

Referenced by autovac_init(), and AutoVacuumingActive().

◆ autovacuum_vac_cost_delay

double autovacuum_vac_cost_delay

Definition at line 124 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

◆ autovacuum_vac_cost_limit

int autovacuum_vac_cost_limit

Definition at line 125 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

◆ autovacuum_vac_scale

double autovacuum_vac_scale

Definition at line 118 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_thresh

int autovacuum_vac_thresh

Definition at line 117 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_work_mem

int autovacuum_work_mem

Definition at line 115 of file autovacuum.c.

Referenced by ginInsertCleanup(), and lazy_space_alloc().

◆ AutovacuumLauncherPid

int AutovacuumLauncherPid

Definition at line 304 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

◆ Log_autovacuum_min_duration

int Log_autovacuum_min_duration

Definition at line 127 of file autovacuum.c.

Referenced by table_recheck_autovac().