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

3348 {
3350  ereport(WARNING,
3351  (errmsg("autovacuum not started because of misconfiguration"),
3352  errhint("Enable the \"track_counts\" option.")));
3353 }
bool autovacuum_start_daemon
Definition: autovacuum.c:117
int errhint(const char *fmt,...)
Definition: elog.c:1320
int errmsg(const char *fmt,...)
Definition: elog.c:1073
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:149
bool pgstat_track_counts
Definition: pgstat.c:187

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

Referenced by PostmasterMain().

◆ AutoVacuumingActive()

bool AutoVacuumingActive ( void  )

Definition at line 3293 of file autovacuum.c.

3294 {
3296  return false;
3297  return true;
3298 }

References autovacuum_start_daemon, and pgstat_track_counts.

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

◆ AutoVacuumRequestWork()

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

Definition at line 3305 of file autovacuum.c.

3307 {
3308  int i;
3309  bool result = false;
3310 
3311  LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
3312 
3313  /*
3314  * Locate an unused work item and fill it with the given data.
3315  */
3316  for (i = 0; i < NUM_WORKITEMS; i++)
3317  {
3319 
3320  if (workitem->avw_used)
3321  continue;
3322 
3323  workitem->avw_used = true;
3324  workitem->avw_active = false;
3325  workitem->avw_type = type;
3326  workitem->avw_database = MyDatabaseId;
3327  workitem->avw_relation = relationId;
3328  workitem->avw_blockNumber = blkno;
3329  result = true;
3330 
3331  /* done */
3332  break;
3333  }
3334 
3335  LWLockRelease(AutovacuumLock);
3336 
3337  return result;
3338 }
#define NUM_WORKITEMS
Definition: autovacuum.c:273
static AutoVacuumShmemStruct * AutoVacuumShmem
Definition: autovacuum.c:304
Oid MyDatabaseId
Definition: globals.c:90
int i
Definition: isn.c:73
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1175
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1788
@ LW_EXCLUSIVE
Definition: lwlock.h:116
AutoVacuumWorkItem av_workItems[NUM_WORKITEMS]
Definition: autovacuum.c:300
BlockNumber avw_blockNumber
Definition: autovacuum.c:270
AutoVacuumWorkItemType avw_type
Definition: autovacuum.c:265
const char * type

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 type.

Referenced by brininsert().

◆ AutoVacuumShmemInit()

void AutoVacuumShmemInit ( void  )

Definition at line 3397 of file autovacuum.c.

3398 {
3399  bool found;
3400 
3402  ShmemInitStruct("AutoVacuum Data",
3404  &found);
3405 
3406  if (!IsUnderPostmaster)
3407  {
3408  WorkerInfo worker;
3409  int i;
3410 
3411  Assert(!found);
3412 
3417  memset(AutoVacuumShmem->av_workItems, 0,
3418  sizeof(AutoVacuumWorkItem) * NUM_WORKITEMS);
3419 
3420  worker = (WorkerInfo) ((char *) AutoVacuumShmem +
3421  MAXALIGN(sizeof(AutoVacuumShmemStruct)));
3422 
3423  /* initialize the WorkerInfo free list */
3424  for (i = 0; i < autovacuum_max_workers; i++)
3425  {
3427  &worker[i].wi_links);
3428  pg_atomic_init_flag(&worker[i].wi_dobalance);
3429  }
3430 
3432 
3433  }
3434  else
3435  Assert(found);
3436 }
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:216
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:165
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3378
int autovacuum_max_workers
Definition: autovacuum.c:118
struct WorkerInfoData * WorkerInfo
Definition: autovacuum.c:243
#define MAXALIGN(LEN)
Definition: c.h:798
bool IsUnderPostmaster
Definition: globals.c:116
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:347
Assert(fmt[strlen(fmt) - 1] !='\n')
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:388
dlist_head av_freeWorkers
Definition: autovacuum.c:297
WorkerInfo av_startingWorker
Definition: autovacuum.c:299
pg_atomic_uint32 av_nworkersForBalance
Definition: autovacuum.c:301
dlist_head av_runningWorkers
Definition: autovacuum.c:298

References Assert(), autovacuum_max_workers, AutoVacuumShmem, AutoVacuumShmemSize(), AutoVacuumShmemStruct::av_freeWorkers, AutoVacuumShmemStruct::av_launcherpid, AutoVacuumShmemStruct::av_nworkersForBalance, AutoVacuumShmemStruct::av_runningWorkers, AutoVacuumShmemStruct::av_startingWorker, AutoVacuumShmemStruct::av_workItems, dlist_init(), dlist_push_head(), i, IsUnderPostmaster, MAXALIGN, NUM_WORKITEMS, pg_atomic_init_flag(), pg_atomic_init_u32(), ShmemInitStruct(), and WorkerInfoData::wi_links.

Referenced by CreateOrAttachShmemStructs().

◆ AutoVacuumShmemSize()

Size AutoVacuumShmemSize ( void  )

Definition at line 3378 of file autovacuum.c.

3379 {
3380  Size size;
3381 
3382  /*
3383  * Need the fixed struct and the array of WorkerInfoData.
3384  */
3385  size = sizeof(AutoVacuumShmemStruct);
3386  size = MAXALIGN(size);
3388  sizeof(WorkerInfoData)));
3389  return size;
3390 }
size_t Size
Definition: c.h:592
Size add_size(Size s1, Size s2)
Definition: shmem.c:494
Size mul_size(Size s1, Size s2)
Definition: shmem.c:511
static pg_noinline void Size size
Definition: slab.c:607

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

Referenced by AutoVacuumShmemInit(), and CalculateShmemSize().

◆ AutoVacWorkerFailed()

void AutoVacWorkerFailed ( void  )

Definition at line 1404 of file autovacuum.c.

1405 {
1407 }
@ AutoVacForkFailed
Definition: autovacuum.c:252
sig_atomic_t av_signal[AutoVacNumSignals]
Definition: autovacuum.c:295

References AutoVacForkFailed, AutoVacuumShmem, and AutoVacuumShmemStruct::av_signal.

Referenced by StartAutovacuumWorker().

◆ IsAutoVacuumLauncherProcess()

bool IsAutoVacuumLauncherProcess ( void  )

Definition at line 3361 of file autovacuum.c.

3362 {
3363  return am_autovacuum_launcher;
3364 }
static bool am_autovacuum_launcher
Definition: autovacuum.c:140

References am_autovacuum_launcher.

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

◆ IsAutoVacuumWorkerProcess()

◆ StartAutoVacLauncher()

int StartAutoVacLauncher ( void  )

◆ StartAutoVacWorker()

int StartAutoVacWorker ( void  )

Definition at line 1451 of file autovacuum.c.

1452 {
1453  pid_t worker_pid;
1454 
1455 #ifdef EXEC_BACKEND
1456  switch ((worker_pid = avworker_forkexec()))
1457 #else
1458  switch ((worker_pid = fork_process()))
1459 #endif
1460  {
1461  case -1:
1462  ereport(LOG,
1463  (errmsg("could not fork autovacuum worker process: %m")));
1464  return 0;
1465 
1466 #ifndef EXEC_BACKEND
1467  case 0:
1468  /* in postmaster child ... */
1470 
1471  /* Close the postmaster's sockets */
1472  ClosePostmasterPorts(false);
1473 
1474  AutoVacWorkerMain(0, NULL);
1475  break;
1476 #endif
1477  default:
1478  return (int) worker_pid;
1479  }
1480 
1481  /* shouldn't get here */
1482  return 0;
1483 }
NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: autovacuum.c:1489
#define LOG
Definition: elog.h:31
pid_t fork_process(void)
Definition: fork_process.c:32
void InitPostmasterChild(void)
Definition: miscinit.c:96
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2502

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

Referenced by relation_needs_vacanalyze().

◆ autovacuum_anl_thresh

PGDLLIMPORT int autovacuum_anl_thresh
extern

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

Referenced by autovac_init(), and AutoVacuumingActive().

◆ autovacuum_vac_cost_delay

PGDLLIMPORT double autovacuum_vac_cost_delay
extern

Definition at line 130 of file autovacuum.c.

Referenced by VacuumUpdateCosts().

◆ autovacuum_vac_cost_limit

PGDLLIMPORT int autovacuum_vac_cost_limit
extern

Definition at line 131 of file autovacuum.c.

Referenced by AutoVacuumUpdateCostLimit().

◆ autovacuum_vac_ins_scale

PGDLLIMPORT double autovacuum_vac_ins_scale
extern

Definition at line 124 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_ins_thresh

PGDLLIMPORT int autovacuum_vac_ins_thresh
extern

Definition at line 123 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_scale

PGDLLIMPORT double autovacuum_vac_scale
extern

Definition at line 122 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_vac_thresh

PGDLLIMPORT int autovacuum_vac_thresh
extern

Definition at line 121 of file autovacuum.c.

Referenced by relation_needs_vacanalyze().

◆ autovacuum_work_mem

PGDLLIMPORT int autovacuum_work_mem
extern

Definition at line 119 of file autovacuum.c.

Referenced by dead_items_max_items(), and ginInsertCleanup().

◆ AutovacuumLauncherPid

PGDLLIMPORT int AutovacuumLauncherPid
extern

Definition at line 317 of file autovacuum.c.

Referenced by FreeWorkerInfo(), and ProcKill().

◆ Log_autovacuum_min_duration

PGDLLIMPORT int Log_autovacuum_min_duration
extern

Definition at line 133 of file autovacuum.c.

Referenced by table_recheck_autovac().