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_vac_ins_thresh
 
double autovacuum_vac_ins_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 55 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 3428 of file autovacuum.c.

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

Referenced by PostmasterMain().

3429 {
3431  ereport(WARNING,
3432  (errmsg("autovacuum not started because of misconfiguration"),
3433  errhint("Enable the \"track_counts\" option.")));
3434 }
int errhint(const char *fmt,...)
Definition: elog.c:1156
bool autovacuum_start_daemon
Definition: autovacuum.c:115
bool pgstat_track_counts
Definition: pgstat.c:115
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ AutoVacuumingActive()

bool AutoVacuumingActive ( void  )

Definition at line 3374 of file autovacuum.c.

References autovacuum_start_daemon, and pgstat_track_counts.

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

3375 {
3377  return false;
3378  return true;
3379 }
bool autovacuum_start_daemon
Definition: autovacuum.c:115
bool pgstat_track_counts
Definition: pgstat.c:115

◆ AutoVacuumRequestWork()

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

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

3388 {
3389  int i;
3390  bool result = false;
3391 
3392  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3393 
3394  /*
3395  * Locate an unused work item and fill it with the given data.
3396  */
3397  for (i = 0; i < NUM_WORKITEMS; i++)
3398  {
3400 
3401  if (workitem->avw_used)
3402  continue;
3403 
3404  workitem->avw_used = true;
3405  workitem->avw_active = false;
3406  workitem->avw_type = type;
3407  workitem->avw_database = MyDatabaseId;
3408  workitem->avw_relation = relationId;
3409  workitem->avw_blockNumber = blkno;
3410  result = true;
3411 
3412  /* done */
3413  break;
3414  }
3415 
3416  LWLockRelease(AutovacuumLock);
3417 
3418  return result;
3419 }
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:257
#define NUM_WORKITEMS
Definition: autovacuum.c:265
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1816
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:290
Oid MyDatabaseId
Definition: globals.c:88
BlockNumber avw_blockNumber
Definition: autovacuum.c:262
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
int i

◆ AutoVacuumShmemInit()

void AutoVacuumShmemInit ( void  )

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

3479 {
3480  bool found;
3481 
3483  ShmemInitStruct("AutoVacuum Data",
3485  &found);
3486 
3487  if (!IsUnderPostmaster)
3488  {
3489  WorkerInfo worker;
3490  int i;
3491 
3492  Assert(!found);
3493 
3498  memset(AutoVacuumShmem->av_workItems, 0,
3499  sizeof(AutoVacuumWorkItem) * NUM_WORKITEMS);
3500 
3501  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3502  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3503 
3504  /* initialize the WorkerInfo free list */
3505  for (i = 0; i < autovacuum_max_workers; i++)
3507  &worker[i].wi_links);
3508  }
3509  else
3510  Assert(found);
3511 }
#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:396
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:290
bool IsUnderPostmaster
Definition: globals.c:112
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3459
int autovacuum_max_workers
Definition: autovacuum.c:116
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
#define Assert(condition)
Definition: c.h:804
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293
#define MAXALIGN(LEN)
Definition: c.h:757
int i
dlist_head av_runningWorkers
Definition: autovacuum.c:288

◆ AutoVacuumShmemSize()

Size AutoVacuumShmemSize ( void  )

Definition at line 3459 of file autovacuum.c.

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

Referenced by AutoVacuumShmemInit(), and CreateSharedMemoryAndSemaphores().

3460 {
3461  Size size;
3462 
3463  /*
3464  * Need the fixed struct and the array of WorkerInfoData.
3465  */
3466  size = sizeof(AutoVacuumShmemStruct);
3467  size = MAXALIGN(size);
3469  sizeof(WorkerInfoData)));
3470  return size;
3471 }
Size mul_size(Size s1, Size s2)
Definition: shmem.c:519
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
int autovacuum_max_workers
Definition: autovacuum.c:116
size_t Size
Definition: c.h:540
#define MAXALIGN(LEN)
Definition: c.h:757

◆ AutoVacuumUpdateDelay()

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 }
double wi_cost_delay
Definition: autovacuum.c:230
int VacuumCostLimit
Definition: globals.c:144
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:303
double VacuumCostDelay
Definition: globals.c:145

◆ AutoVacWorkerFailed()

void AutoVacWorkerFailed ( void  )

Definition at line 1417 of file autovacuum.c.

References AutoVacForkFailed, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

1418 {
1420 }
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:285
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:293

◆ IsAutoVacuumLauncherProcess()

bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3442 of file autovacuum.c.

References am_autovacuum_launcher.

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

3443 {
3444  return am_autovacuum_launcher;
3445 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:141

◆ IsAutoVacuumWorkerProcess()

◆ StartAutoVacLauncher()

int StartAutoVacLauncher ( void  )

Referenced by reaper(), and ServerLoop().

◆ StartAutoVacWorker()

int StartAutoVacWorker ( void  )

Definition at line 1477 of file autovacuum.c.

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

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:93
pid_t fork_process(void)
Definition: fork_process.c:29
#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:2553
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

Variable Documentation

◆ autovacuum_anl_scale

double autovacuum_anl_scale

Definition at line 124 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_anl_thresh

int autovacuum_anl_thresh

Definition at line 123 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

◆ autovacuum_naptime

int autovacuum_naptime

◆ autovacuum_start_daemon

bool autovacuum_start_daemon

Definition at line 115 of file autovacuum.c.

Referenced by autovac_init(), and AutoVacuumingActive().

◆ autovacuum_vac_cost_delay

double autovacuum_vac_cost_delay

Definition at line 128 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 129 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

◆ autovacuum_vac_ins_scale

double autovacuum_vac_ins_scale

Definition at line 122 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_ins_thresh

int autovacuum_vac_ins_thresh

Definition at line 121 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_scale

double autovacuum_vac_scale

Definition at line 120 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_thresh

int autovacuum_vac_thresh

Definition at line 119 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_work_mem

int autovacuum_work_mem

Definition at line 117 of file autovacuum.c.

Referenced by compute_max_dead_tuples(), and ginInsertCleanup().

◆ AutovacuumLauncherPid

int AutovacuumLauncherPid

Definition at line 306 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

◆ Log_autovacuum_min_duration

int Log_autovacuum_min_duration

Definition at line 131 of file autovacuum.c.

Referenced by table_recheck_autovac().