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

PGDLLIMPORT bool autovacuum_start_daemon
 
PGDLLIMPORT int autovacuum_max_workers
 
PGDLLIMPORT int autovacuum_work_mem
 
PGDLLIMPORT int autovacuum_naptime
 
PGDLLIMPORT int autovacuum_vac_thresh
 
PGDLLIMPORT double autovacuum_vac_scale
 
PGDLLIMPORT int autovacuum_vac_ins_thresh
 
PGDLLIMPORT double autovacuum_vac_ins_scale
 
PGDLLIMPORT int autovacuum_anl_thresh
 
PGDLLIMPORT double autovacuum_anl_scale
 
PGDLLIMPORT int autovacuum_freeze_max_age
 
PGDLLIMPORT int autovacuum_multixact_freeze_max_age
 
PGDLLIMPORT double autovacuum_vac_cost_delay
 
PGDLLIMPORT int autovacuum_vac_cost_limit
 
PGDLLIMPORT int AutovacuumLauncherPid
 
PGDLLIMPORT int Log_autovacuum_min_duration
 

Macro Definition Documentation

◆ IsAnyAutoVacuumProcess

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

Definition at line 55 of file autovacuum.h.

Enumeration Type Documentation

◆ AutoVacuumWorkItemType

Enumerator
AVW_BRINSummarizeRange 

Definition at line 23 of file autovacuum.h.

24 {
AutoVacuumWorkItemType
Definition: autovacuum.h:24
@ AVW_BRINSummarizeRange
Definition: autovacuum.h:25

Function Documentation

◆ autovac_init()

void autovac_init ( void  )

Definition at line 3294 of file autovacuum.c.

3295 {
3297  ereport(WARNING,
3298  (errmsg("autovacuum not started because of misconfiguration"),
3299  errhint("Enable the \"track_counts\" option.")));
3300 }
bool autovacuum_start_daemon
Definition: autovacuum.c:116
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define WARNING
Definition: elog.h:32
#define ereport(elevel,...)
Definition: elog.h:145
bool pgstat_track_counts
Definition: pgstat.c:186

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

Referenced by PostmasterMain().

◆ AutoVacuumingActive()

bool AutoVacuumingActive ( void  )

Definition at line 3240 of file autovacuum.c.

3241 {
3243  return false;
3244  return true;
3245 }

References autovacuum_start_daemon, and pgstat_track_counts.

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

◆ AutoVacuumRequestWork()

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

Definition at line 3252 of file autovacuum.c.

3254 {
3255  int i;
3256  bool result = false;
3257 
3258  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3259 
3260  /*
3261  * Locate an unused work item and fill it with the given data.
3262  */
3263  for (i = 0; i < NUM_WORKITEMS; i++)
3264  {
3266 
3267  if (workitem->avw_used)
3268  continue;
3269 
3270  workitem->avw_used = true;
3271  workitem->avw_active = false;
3272  workitem->avw_type = type;
3273  workitem->avw_database = MyDatabaseId;
3274  workitem->avw_relation = relationId;
3275  workitem->avw_blockNumber = blkno;
3276  result = true;
3277 
3278  /* done */
3279  break;
3280  }
3281 
3282  LWLockRelease(AutovacuumLock);
3283 
3284  return result;
3285 }
#define NUM_WORKITEMS
Definition: autovacuum.c:263
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:291
Oid MyDatabaseId
Definition: globals.c:89
int i
Definition: isn.c:73
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1194
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1802
@ LW_EXCLUSIVE
Definition: lwlock.h:112
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:288
BlockNumber avw_blockNumber
Definition: autovacuum.c:260
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:255

References AutoVacuumShmem, 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().

◆ AutoVacuumShmemInit()

void AutoVacuumShmemInit ( void  )

Definition at line 3344 of file autovacuum.c.

3345 {
3346  bool found;
3347 
3349  ShmemInitStruct("AutoVacuum Data",
3351  &found);
3352 
3353  if (!IsUnderPostmaster)
3354  {
3355  WorkerInfo worker;
3356  int i;
3357 
3358  Assert(!found);
3359 
3364  memset(AutoVacuumShmem->av_workItems, 0,
3365  sizeof(AutoVacuumWorkItem) * NUM_WORKITEMS);
3366 
3367  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3368  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3369 
3370  /* initialize the WorkerInfo free list */
3371  for (i = 0; i < autovacuum_max_workers; i++)
3373  &worker[i].wi_links);
3374  }
3375  else
3376  Assert(found);
3377 }
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3325
int autovacuum_max_workers
Definition: autovacuum.c:117
struct WorkerInfoData * WorkerInfo
Definition: autovacuum.c:233
#define MAXALIGN(LEN)
Definition: c.h:747
bool IsUnderPostmaster
Definition: globals.c:113
static void dlist_init(dlist_head *head)
Definition: ilist.h:314
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:336
Assert(fmt[strlen(fmt) - 1] !='\n')
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
dlist_head av_freeWorkers
Definition: autovacuum.c:285
WorkerInfo av_startingWorker
Definition: autovacuum.c:287
dlist_head av_runningWorkers
Definition: autovacuum.c:286

References Assert(), autovacuum_max_workers, AutoVacuumShmem, 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().

◆ AutoVacuumShmemSize()

Size AutoVacuumShmemSize ( void  )

Definition at line 3325 of file autovacuum.c.

3326 {
3327  Size size;
3328 
3329  /*
3330  * Need the fixed struct and the array of WorkerInfoData.
3331  */
3332  size = sizeof(AutoVacuumShmemStruct);
3333  size = MAXALIGN(size);
3335  sizeof(WorkerInfoData)));
3336  return size;
3337 }
size_t Size
Definition: c.h:541
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
Size mul_size(Size s1, Size s2)
Definition: shmem.c:519

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

Referenced by AutoVacuumShmemInit(), and CalculateShmemSize().

◆ AutoVacuumUpdateDelay()

void AutoVacuumUpdateDelay ( void  )

Definition at line 1781 of file autovacuum.c.

1782 {
1783  if (MyWorkerInfo)
1784  {
1787  }
1788 }
static WorkerInfo MyWorkerInfo
Definition: autovacuum.c:301
int VacuumCostLimit
Definition: globals.c:145
double VacuumCostDelay
Definition: globals.c:146
double wi_cost_delay
Definition: autovacuum.c:228

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

Referenced by do_autovacuum(), and vacuum_delay_point().

◆ AutoVacWorkerFailed()

void AutoVacWorkerFailed ( void  )

Definition at line 1411 of file autovacuum.c.

1412 {
1414 }
@ AutoVacForkFailed
Definition: autovacuum.c:242
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:283

References AutoVacForkFailed, AutoVacuumShmem, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

◆ IsAutoVacuumLauncherProcess()

bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3308 of file autovacuum.c.

3309 {
3310  return am_autovacuum_launcher;
3311 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:139

References am_autovacuum_launcher.

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

◆ IsAutoVacuumWorkerProcess()

◆ StartAutoVacLauncher()

int StartAutoVacLauncher ( void  )

Referenced by reaper(), and ServerLoop().

◆ StartAutoVacWorker()

int StartAutoVacWorker ( void  )

Definition at line 1471 of file autovacuum.c.

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

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

Referenced by StartAutovacuumWorker().

Variable Documentation

◆ autovacuum_anl_scale

PGDLLIMPORT double autovacuum_anl_scale
extern

Definition at line 125 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_anl_thresh

PGDLLIMPORT int autovacuum_anl_thresh
extern

Definition at line 124 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_freeze_max_age

PGDLLIMPORT int autovacuum_freeze_max_age
extern

◆ autovacuum_max_workers

◆ autovacuum_multixact_freeze_max_age

PGDLLIMPORT int autovacuum_multixact_freeze_max_age
extern

◆ autovacuum_naptime

PGDLLIMPORT int autovacuum_naptime
extern

◆ autovacuum_start_daemon

PGDLLIMPORT bool autovacuum_start_daemon
extern

Definition at line 116 of file autovacuum.c.

Referenced by autovac_init(), and AutoVacuumingActive().

◆ autovacuum_vac_cost_delay

PGDLLIMPORT double autovacuum_vac_cost_delay
extern

Definition at line 129 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

◆ autovacuum_vac_cost_limit

PGDLLIMPORT int autovacuum_vac_cost_limit
extern

Definition at line 130 of file autovacuum.c.

Referenced by autovac_balance_cost(), and table_recheck_autovac().

◆ autovacuum_vac_ins_scale

PGDLLIMPORT double autovacuum_vac_ins_scale
extern

Definition at line 123 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_ins_thresh

PGDLLIMPORT int autovacuum_vac_ins_thresh
extern

Definition at line 122 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_scale

PGDLLIMPORT double autovacuum_vac_scale
extern

Definition at line 121 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_thresh

PGDLLIMPORT int autovacuum_vac_thresh
extern

Definition at line 120 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_work_mem

PGDLLIMPORT int autovacuum_work_mem
extern

Definition at line 118 of file autovacuum.c.

Referenced by dead_items_max_items(), and ginInsertCleanup().

◆ AutovacuumLauncherPid

PGDLLIMPORT int AutovacuumLauncherPid
extern

Definition at line 304 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

◆ Log_autovacuum_min_duration

PGDLLIMPORT int Log_autovacuum_min_duration
extern

Definition at line 132 of file autovacuum.c.

Referenced by table_recheck_autovac().