PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vacuum.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/clog.h"
#include "access/commit_ts.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/namespace.h"
#include "catalog/pg_database.h"
#include "catalog/pg_inherits.h"
#include "commands/cluster.h"
#include "commands/defrem.h"
#include "commands/progress.h"
#include "commands/vacuum.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "postmaster/bgworker_internals.h"
#include "postmaster/interrupt.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
#include "utils/guc_hooks.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Include dependency graph for vacuum.c:

Go to the source code of this file.

Macros

#define PARALLEL_VACUUM_DELAY_REPORT_INTERVAL_NS   (NS_PER_S)
 

Functions

static Listexpand_vacuum_rel (VacuumRelation *vrel, MemoryContext vac_context, int options)
 
static Listget_all_vacuum_rels (MemoryContext vac_context, int options)
 
static void vac_truncate_clog (TransactionId frozenXID, MultiXactId minMulti, TransactionId lastSaneFrozenXid, MultiXactId lastSaneMinMulti)
 
static bool vacuum_rel (Oid relid, RangeVar *relation, VacuumParams *params, BufferAccessStrategy bstrategy)
 
static double compute_parallel_delay (void)
 
static VacOptValue get_vacoptval_from_boolean (DefElem *def)
 
static bool vac_tid_reaped (ItemPointer itemptr, void *state)
 
bool check_vacuum_buffer_usage_limit (int *newval, void **extra, GucSource source)
 
void ExecVacuum (ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
 
void vacuum (List *relations, VacuumParams *params, BufferAccessStrategy bstrategy, MemoryContext vac_context, bool isTopLevel)
 
bool vacuum_is_permitted_for_relation (Oid relid, Form_pg_class reltuple, bits32 options)
 
Relation vacuum_open_relation (Oid relid, RangeVar *relation, bits32 options, bool verbose, LOCKMODE lmode)
 
bool vacuum_get_cutoffs (Relation rel, const VacuumParams *params, struct VacuumCutoffs *cutoffs)
 
bool vacuum_xid_failsafe_check (const struct VacuumCutoffs *cutoffs)
 
double vac_estimate_reltuples (Relation relation, BlockNumber total_pages, BlockNumber scanned_pages, double scanned_tuples)
 
void vac_update_relstats (Relation relation, BlockNumber num_pages, double num_tuples, BlockNumber num_all_visible_pages, BlockNumber num_all_frozen_pages, bool hasindex, TransactionId frozenxid, MultiXactId minmulti, bool *frozenxid_updated, bool *minmulti_updated, bool in_outer_xact)
 
void vac_update_datfrozenxid (void)
 
void vac_open_indexes (Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel)
 
void vac_close_indexes (int nindexes, Relation *Irel, LOCKMODE lockmode)
 
void vacuum_delay_point (bool is_analyze)
 
IndexBulkDeleteResultvac_bulkdel_one_index (IndexVacuumInfo *ivinfo, IndexBulkDeleteResult *istat, TidStore *dead_items, VacDeadItemsInfo *dead_items_info)
 
IndexBulkDeleteResultvac_cleanup_one_index (IndexVacuumInfo *ivinfo, IndexBulkDeleteResult *istat)
 

Variables

int vacuum_freeze_min_age
 
int vacuum_freeze_table_age
 
int vacuum_multixact_freeze_min_age
 
int vacuum_multixact_freeze_table_age
 
int vacuum_failsafe_age
 
int vacuum_multixact_failsafe_age
 
double vacuum_max_eager_freeze_failure_rate
 
bool track_cost_delay_timing
 
bool vacuum_truncate
 
double vacuum_cost_delay = 0
 
int vacuum_cost_limit = 200
 
int64 parallel_vacuum_worker_delay_ns = 0
 
bool VacuumFailsafeActive = false
 
pg_atomic_uint32VacuumSharedCostBalance = NULL
 
pg_atomic_uint32VacuumActiveNWorkers = NULL
 
int VacuumCostBalanceLocal = 0
 

Macro Definition Documentation

◆ PARALLEL_VACUUM_DELAY_REPORT_INTERVAL_NS

#define PARALLEL_VACUUM_DELAY_REPORT_INTERVAL_NS   (NS_PER_S)

Definition at line 68 of file vacuum.c.

Function Documentation

◆ check_vacuum_buffer_usage_limit()

bool check_vacuum_buffer_usage_limit ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 137 of file vacuum.c.

139{
140 /* Value upper and lower hard limits are inclusive */
141 if (*newval == 0 || (*newval >= MIN_BAS_VAC_RING_SIZE_KB &&
143 return true;
144
145 /* Value does not fall within any allowable range */
146 GUC_check_errdetail("\"%s\" must be 0 or between %d kB and %d kB.",
147 "vacuum_buffer_usage_limit",
149
150 return false;
151}
#define newval
#define GUC_check_errdetail
Definition: guc.h:481
#define MIN_BAS_VAC_RING_SIZE_KB
Definition: miscadmin.h:278
#define MAX_BAS_VAC_RING_SIZE_KB
Definition: miscadmin.h:279

References GUC_check_errdetail, MAX_BAS_VAC_RING_SIZE_KB, MIN_BAS_VAC_RING_SIZE_KB, and newval.

◆ compute_parallel_delay()

static double compute_parallel_delay ( void  )
static

Definition at line 2556 of file vacuum.c.

2557{
2558 double msec = 0;
2559 uint32 shared_balance;
2560 int nworkers;
2561
2562 /* Parallel vacuum must be active */
2564
2566
2567 /* At least count itself */
2568 Assert(nworkers >= 1);
2569
2570 /* Update the shared cost balance value atomically */
2572
2573 /* Compute the total local balance for the current worker */
2575
2576 if ((shared_balance >= vacuum_cost_limit) &&
2577 (VacuumCostBalanceLocal > 0.5 * ((double) vacuum_cost_limit / nworkers)))
2578 {
2579 /* Compute sleep time based on the local cost balance */
2583 }
2584
2585 /*
2586 * Reset the local balance as we accumulated it into the shared value.
2587 */
2589
2590 return msec;
2591}
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:439
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:424
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:239
uint32_t uint32
Definition: c.h:502
int VacuumCostBalance
Definition: globals.c:158
Assert(PointerIsAligned(start, uint64))
pg_atomic_uint32 * VacuumActiveNWorkers
Definition: vacuum.c:115
double vacuum_cost_delay
Definition: vacuum.c:89
int VacuumCostBalanceLocal
Definition: vacuum.c:116
pg_atomic_uint32 * VacuumSharedCostBalance
Definition: vacuum.c:114
int vacuum_cost_limit
Definition: vacuum.c:90

References Assert(), pg_atomic_add_fetch_u32(), pg_atomic_read_u32(), pg_atomic_sub_fetch_u32(), vacuum_cost_delay, vacuum_cost_limit, VacuumActiveNWorkers, VacuumCostBalance, VacuumCostBalanceLocal, and VacuumSharedCostBalance.

Referenced by vacuum_delay_point().

◆ ExecVacuum()

void ExecVacuum ( ParseState pstate,
VacuumStmt vacstmt,
bool  isTopLevel 
)

Definition at line 160 of file vacuum.c.

161{
162 VacuumParams params;
163 BufferAccessStrategy bstrategy = NULL;
164 bool verbose = false;
165 bool skip_locked = false;
166 bool analyze = false;
167 bool freeze = false;
168 bool full = false;
169 bool disable_page_skipping = false;
170 bool process_main = true;
171 bool process_toast = true;
172 int ring_size;
173 bool skip_database_stats = false;
174 bool only_database_stats = false;
175 MemoryContext vac_context;
176 ListCell *lc;
177
178 /* index_cleanup and truncate values unspecified for now */
181
182 /* By default parallel vacuum is enabled */
183 params.nworkers = 0;
184
185 /* Will be set later if we recurse to a TOAST table. */
186 params.toast_parent = InvalidOid;
187
188 /*
189 * Set this to an invalid value so it is clear whether or not a
190 * BUFFER_USAGE_LIMIT was specified when making the access strategy.
191 */
192 ring_size = -1;
193
194 /* Parse options list */
195 foreach(lc, vacstmt->options)
196 {
197 DefElem *opt = (DefElem *) lfirst(lc);
198
199 /* Parse common options for VACUUM and ANALYZE */
200 if (strcmp(opt->defname, "verbose") == 0)
201 verbose = defGetBoolean(opt);
202 else if (strcmp(opt->defname, "skip_locked") == 0)
203 skip_locked = defGetBoolean(opt);
204 else if (strcmp(opt->defname, "buffer_usage_limit") == 0)
205 {
206 const char *hintmsg;
207 int result;
208 char *vac_buffer_size;
209
210 vac_buffer_size = defGetString(opt);
211
212 /*
213 * Check that the specified value is valid and the size falls
214 * within the hard upper and lower limits if it is not 0.
215 */
216 if (!parse_int(vac_buffer_size, &result, GUC_UNIT_KB, &hintmsg) ||
217 (result != 0 &&
218 (result < MIN_BAS_VAC_RING_SIZE_KB || result > MAX_BAS_VAC_RING_SIZE_KB)))
219 {
221 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
222 errmsg("BUFFER_USAGE_LIMIT option must be 0 or between %d kB and %d kB",
224 hintmsg ? errhint("%s", _(hintmsg)) : 0));
225 }
226
227 ring_size = result;
228 }
229 else if (!vacstmt->is_vacuumcmd)
231 (errcode(ERRCODE_SYNTAX_ERROR),
232 errmsg("unrecognized ANALYZE option \"%s\"", opt->defname),
233 parser_errposition(pstate, opt->location)));
234
235 /* Parse options available on VACUUM */
236 else if (strcmp(opt->defname, "analyze") == 0)
237 analyze = defGetBoolean(opt);
238 else if (strcmp(opt->defname, "freeze") == 0)
239 freeze = defGetBoolean(opt);
240 else if (strcmp(opt->defname, "full") == 0)
241 full = defGetBoolean(opt);
242 else if (strcmp(opt->defname, "disable_page_skipping") == 0)
243 disable_page_skipping = defGetBoolean(opt);
244 else if (strcmp(opt->defname, "index_cleanup") == 0)
245 {
246 /* Interpret no string as the default, which is 'auto' */
247 if (!opt->arg)
249 else
250 {
251 char *sval = defGetString(opt);
252
253 /* Try matching on 'auto' string, or fall back on boolean */
254 if (pg_strcasecmp(sval, "auto") == 0)
256 else
258 }
259 }
260 else if (strcmp(opt->defname, "process_main") == 0)
261 process_main = defGetBoolean(opt);
262 else if (strcmp(opt->defname, "process_toast") == 0)
263 process_toast = defGetBoolean(opt);
264 else if (strcmp(opt->defname, "truncate") == 0)
266 else if (strcmp(opt->defname, "parallel") == 0)
267 {
268 if (opt->arg == NULL)
269 {
271 (errcode(ERRCODE_SYNTAX_ERROR),
272 errmsg("parallel option requires a value between 0 and %d",
274 parser_errposition(pstate, opt->location)));
275 }
276 else
277 {
278 int nworkers;
279
280 nworkers = defGetInt32(opt);
281 if (nworkers < 0 || nworkers > MAX_PARALLEL_WORKER_LIMIT)
283 (errcode(ERRCODE_SYNTAX_ERROR),
284 errmsg("parallel workers for vacuum must be between 0 and %d",
286 parser_errposition(pstate, opt->location)));
287
288 /*
289 * Disable parallel vacuum, if user has specified parallel
290 * degree as zero.
291 */
292 if (nworkers == 0)
293 params.nworkers = -1;
294 else
295 params.nworkers = nworkers;
296 }
297 }
298 else if (strcmp(opt->defname, "skip_database_stats") == 0)
299 skip_database_stats = defGetBoolean(opt);
300 else if (strcmp(opt->defname, "only_database_stats") == 0)
301 only_database_stats = defGetBoolean(opt);
302 else
304 (errcode(ERRCODE_SYNTAX_ERROR),
305 errmsg("unrecognized VACUUM option \"%s\"", opt->defname),
306 parser_errposition(pstate, opt->location)));
307 }
308
309 /* Set vacuum options */
310 params.options =
312 (verbose ? VACOPT_VERBOSE : 0) |
313 (skip_locked ? VACOPT_SKIP_LOCKED : 0) |
314 (analyze ? VACOPT_ANALYZE : 0) |
315 (freeze ? VACOPT_FREEZE : 0) |
316 (full ? VACOPT_FULL : 0) |
317 (disable_page_skipping ? VACOPT_DISABLE_PAGE_SKIPPING : 0) |
318 (process_main ? VACOPT_PROCESS_MAIN : 0) |
319 (process_toast ? VACOPT_PROCESS_TOAST : 0) |
320 (skip_database_stats ? VACOPT_SKIP_DATABASE_STATS : 0) |
321 (only_database_stats ? VACOPT_ONLY_DATABASE_STATS : 0);
322
323 /* sanity checks on options */
325 Assert((params.options & VACOPT_VACUUM) ||
326 !(params.options & (VACOPT_FULL | VACOPT_FREEZE)));
327
328 if ((params.options & VACOPT_FULL) && params.nworkers > 0)
330 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
331 errmsg("VACUUM FULL cannot be performed in parallel")));
332
333 /*
334 * BUFFER_USAGE_LIMIT does nothing for VACUUM (FULL) so just raise an
335 * ERROR for that case. VACUUM (FULL, ANALYZE) does make use of it, so
336 * we'll permit that.
337 */
338 if (ring_size != -1 && (params.options & VACOPT_FULL) &&
339 !(params.options & VACOPT_ANALYZE))
341 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
342 errmsg("BUFFER_USAGE_LIMIT cannot be specified for VACUUM FULL")));
343
344 /*
345 * Make sure VACOPT_ANALYZE is specified if any column lists are present.
346 */
347 if (!(params.options & VACOPT_ANALYZE))
348 {
349 foreach(lc, vacstmt->rels)
350 {
352
353 if (vrel->va_cols != NIL)
355 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
356 errmsg("ANALYZE option must be specified when a column list is provided")));
357 }
358 }
359
360
361 /*
362 * Sanity check DISABLE_PAGE_SKIPPING option.
363 */
364 if ((params.options & VACOPT_FULL) != 0 &&
367 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
368 errmsg("VACUUM option DISABLE_PAGE_SKIPPING cannot be used with FULL")));
369
370 /* sanity check for PROCESS_TOAST */
371 if ((params.options & VACOPT_FULL) != 0 &&
372 (params.options & VACOPT_PROCESS_TOAST) == 0)
374 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
375 errmsg("PROCESS_TOAST required with VACUUM FULL")));
376
377 /* sanity check for ONLY_DATABASE_STATS */
379 {
380 Assert(params.options & VACOPT_VACUUM);
381 if (vacstmt->rels != NIL)
383 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
384 errmsg("ONLY_DATABASE_STATS cannot be specified with a list of tables")));
385 /* don't require people to turn off PROCESS_TOAST/MAIN explicitly */
386 if (params.options & ~(VACOPT_VACUUM |
392 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
393 errmsg("ONLY_DATABASE_STATS cannot be specified with other VACUUM options")));
394 }
395
396 /*
397 * All freeze ages are zero if the FREEZE option is given; otherwise pass
398 * them as -1 which means to use the default values.
399 */
400 if (params.options & VACOPT_FREEZE)
401 {
402 params.freeze_min_age = 0;
403 params.freeze_table_age = 0;
404 params.multixact_freeze_min_age = 0;
406 }
407 else
408 {
409 params.freeze_min_age = -1;
410 params.freeze_table_age = -1;
411 params.multixact_freeze_min_age = -1;
412 params.multixact_freeze_table_age = -1;
413 }
414
415 /* user-invoked vacuum is never "for wraparound" */
416 params.is_wraparound = false;
417
418 /* user-invoked vacuum uses VACOPT_VERBOSE instead of log_min_duration */
419 params.log_min_duration = -1;
420
421 /*
422 * Later, in vacuum_rel(), we check if a reloption override was specified.
423 */
425
426 /*
427 * Create special memory context for cross-transaction storage.
428 *
429 * Since it is a child of PortalContext, it will go away eventually even
430 * if we suffer an error; there's no need for special abort cleanup logic.
431 */
433 "Vacuum",
435
436 /*
437 * Make a buffer strategy object in the cross-transaction memory context.
438 * We needn't bother making this for VACUUM (FULL) or VACUUM
439 * (ONLY_DATABASE_STATS) as they'll not make use of it. VACUUM (FULL,
440 * ANALYZE) is possible, so we'd better ensure that we make a strategy
441 * when we see ANALYZE.
442 */
443 if ((params.options & (VACOPT_ONLY_DATABASE_STATS |
444 VACOPT_FULL)) == 0 ||
445 (params.options & VACOPT_ANALYZE) != 0)
446 {
447
448 MemoryContext old_context = MemoryContextSwitchTo(vac_context);
449
450 Assert(ring_size >= -1);
451
452 /*
453 * If BUFFER_USAGE_LIMIT was specified by the VACUUM or ANALYZE
454 * command, it overrides the value of VacuumBufferUsageLimit. Either
455 * value may be 0, in which case GetAccessStrategyWithSize() will
456 * return NULL, effectively allowing full use of shared buffers.
457 */
458 if (ring_size == -1)
459 ring_size = VacuumBufferUsageLimit;
460
461 bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, ring_size);
462
463 MemoryContextSwitchTo(old_context);
464 }
465
466 /* Now go through the common routine */
467 vacuum(vacstmt->rels, &params, bstrategy, vac_context, isTopLevel);
468
469 /* Finally, clean up the vacuum memory context */
470 MemoryContextDelete(vac_context);
471}
#define MAX_PARALLEL_WORKER_LIMIT
@ BAS_VACUUM
Definition: bufmgr.h:40
int32 defGetInt32(DefElem *def)
Definition: define.c:149
char * defGetString(DefElem *def)
Definition: define.c:35
bool defGetBoolean(DefElem *def)
Definition: define.c:94
int errhint(const char *fmt,...)
Definition: elog.c:1318
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define _(x)
Definition: elog.c:91
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
BufferAccessStrategy GetAccessStrategyWithSize(BufferAccessStrategyType btype, int ring_size_kb)
Definition: freelist.c:626
int VacuumBufferUsageLimit
Definition: globals.c:150
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:2871
#define GUC_UNIT_KB
Definition: guc.h:232
int verbose
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:485
MemoryContext PortalContext
Definition: mcxt.c:174
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
#define lfirst(lc)
Definition: pg_list.h:172
#define lfirst_node(type, lc)
Definition: pg_list.h:176
#define NIL
Definition: pg_list.h:68
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define InvalidOid
Definition: postgres_ext.h:35
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:3051
char * defname
Definition: parsenodes.h:826
ParseLoc location
Definition: parsenodes.h:830
Node * arg
Definition: parsenodes.h:827
int nworkers
Definition: vacuum.h:246
int freeze_table_age
Definition: vacuum.h:221
VacOptValue truncate
Definition: vacuum.h:231
bits32 options
Definition: vacuum.h:219
int freeze_min_age
Definition: vacuum.h:220
bool is_wraparound
Definition: vacuum.h:226
int multixact_freeze_min_age
Definition: vacuum.h:222
int multixact_freeze_table_age
Definition: vacuum.h:224
int log_min_duration
Definition: vacuum.h:227
Oid toast_parent
Definition: vacuum.h:232
VacOptValue index_cleanup
Definition: vacuum.h:230
double max_eager_freeze_failure_rate
Definition: vacuum.h:239
List * options
Definition: parsenodes.h:3936
bool is_vacuumcmd
Definition: parsenodes.h:3938
List * rels
Definition: parsenodes.h:3937
double vacuum_max_eager_freeze_failure_rate
Definition: vacuum.c:79
static VacOptValue get_vacoptval_from_boolean(DefElem *def)
Definition: vacuum.c:2600
void vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy, MemoryContext vac_context, bool isTopLevel)
Definition: vacuum.c:496
#define VACOPT_FREEZE
Definition: vacuum.h:183
#define VACOPT_SKIP_LOCKED
Definition: vacuum.h:185
#define VACOPT_VACUUM
Definition: vacuum.h:180
#define VACOPT_VERBOSE
Definition: vacuum.h:182
#define VACOPT_FULL
Definition: vacuum.h:184
#define VACOPT_SKIP_DATABASE_STATS
Definition: vacuum.h:189
@ VACOPTVALUE_AUTO
Definition: vacuum.h:203
@ VACOPTVALUE_UNSPECIFIED
Definition: vacuum.h:202
#define VACOPT_PROCESS_TOAST
Definition: vacuum.h:187
#define VACOPT_DISABLE_PAGE_SKIPPING
Definition: vacuum.h:188
#define VACOPT_ONLY_DATABASE_STATS
Definition: vacuum.h:190
#define VACOPT_PROCESS_MAIN
Definition: vacuum.h:186
#define VACOPT_ANALYZE
Definition: vacuum.h:181

References _, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, analyze(), DefElem::arg, Assert(), BAS_VACUUM, defGetBoolean(), defGetInt32(), defGetString(), DefElem::defname, ereport, errcode(), errhint(), errmsg(), ERROR, VacuumParams::freeze_min_age, VacuumParams::freeze_table_age, get_vacoptval_from_boolean(), GetAccessStrategyWithSize(), GUC_UNIT_KB, VacuumParams::index_cleanup, InvalidOid, VacuumStmt::is_vacuumcmd, VacuumParams::is_wraparound, lfirst, lfirst_node, DefElem::location, VacuumParams::log_min_duration, MAX_BAS_VAC_RING_SIZE_KB, VacuumParams::max_eager_freeze_failure_rate, MAX_PARALLEL_WORKER_LIMIT, MemoryContextDelete(), MemoryContextSwitchTo(), MIN_BAS_VAC_RING_SIZE_KB, VacuumParams::multixact_freeze_min_age, VacuumParams::multixact_freeze_table_age, NIL, VacuumParams::nworkers, VacuumParams::options, VacuumStmt::options, parse_int(), parser_errposition(), pg_strcasecmp(), PortalContext, VacuumStmt::rels, VacuumParams::toast_parent, VacuumParams::truncate, VacuumRelation::va_cols, VACOPT_ANALYZE, VACOPT_DISABLE_PAGE_SKIPPING, VACOPT_FREEZE, VACOPT_FULL, VACOPT_ONLY_DATABASE_STATS, VACOPT_PROCESS_MAIN, VACOPT_PROCESS_TOAST, VACOPT_SKIP_DATABASE_STATS, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, VACOPT_VERBOSE, VACOPTVALUE_AUTO, VACOPTVALUE_UNSPECIFIED, vacuum(), vacuum_max_eager_freeze_failure_rate, VacuumBufferUsageLimit, and verbose.

Referenced by standard_ProcessUtility().

◆ expand_vacuum_rel()

static List * expand_vacuum_rel ( VacuumRelation vrel,
MemoryContext  vac_context,
int  options 
)
static

Definition at line 887 of file vacuum.c.

889{
890 List *vacrels = NIL;
891 MemoryContext oldcontext;
892
893 /* If caller supplied OID, there's nothing we need do here. */
894 if (OidIsValid(vrel->oid))
895 {
896 oldcontext = MemoryContextSwitchTo(vac_context);
897 vacrels = lappend(vacrels, vrel);
898 MemoryContextSwitchTo(oldcontext);
899 }
900 else
901 {
902 /*
903 * Process a specific relation, and possibly partitions or child
904 * tables thereof.
905 */
906 Oid relid;
907 HeapTuple tuple;
908 Form_pg_class classForm;
909 bool include_children;
910 bool is_partitioned_table;
911 int rvr_opts;
912
913 /*
914 * Since autovacuum workers supply OIDs when calling vacuum(), no
915 * autovacuum worker should reach this code.
916 */
918
919 /*
920 * We transiently take AccessShareLock to protect the syscache lookup
921 * below, as well as find_all_inheritors's expectation that the caller
922 * holds some lock on the starting relation.
923 */
924 rvr_opts = (options & VACOPT_SKIP_LOCKED) ? RVR_SKIP_LOCKED : 0;
927 rvr_opts,
928 NULL, NULL);
929
930 /*
931 * If the lock is unavailable, emit the same log statement that
932 * vacuum_rel() and analyze_rel() would.
933 */
934 if (!OidIsValid(relid))
935 {
938 (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
939 errmsg("skipping vacuum of \"%s\" --- lock not available",
940 vrel->relation->relname)));
941 else
943 (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
944 errmsg("skipping analyze of \"%s\" --- lock not available",
945 vrel->relation->relname)));
946 return vacrels;
947 }
948
949 /*
950 * To check whether the relation is a partitioned table and its
951 * ownership, fetch its syscache entry.
952 */
953 tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
954 if (!HeapTupleIsValid(tuple))
955 elog(ERROR, "cache lookup failed for relation %u", relid);
956 classForm = (Form_pg_class) GETSTRUCT(tuple);
957
958 /*
959 * Make a returnable VacuumRelation for this rel if the user has the
960 * required privileges.
961 */
962 if (vacuum_is_permitted_for_relation(relid, classForm, options))
963 {
964 oldcontext = MemoryContextSwitchTo(vac_context);
965 vacrels = lappend(vacrels, makeVacuumRelation(vrel->relation,
966 relid,
967 vrel->va_cols));
968 MemoryContextSwitchTo(oldcontext);
969 }
970
971 /*
972 * Vacuuming a partitioned table with ONLY will not do anything since
973 * the partitioned table itself is empty. Issue a warning if the user
974 * requests this.
975 */
976 include_children = vrel->relation->inh;
977 is_partitioned_table = (classForm->relkind == RELKIND_PARTITIONED_TABLE);
978 if ((options & VACOPT_VACUUM) && is_partitioned_table && !include_children)
980 (errmsg("VACUUM ONLY of partitioned table \"%s\" has no effect",
981 vrel->relation->relname)));
982
983 ReleaseSysCache(tuple);
984
985 /*
986 * Unless the user has specified ONLY, make relation list entries for
987 * its partitions or inheritance child tables. Note that the list
988 * returned by find_all_inheritors() includes the passed-in OID, so we
989 * have to skip that. There's no point in taking locks on the
990 * individual partitions or child tables yet, and doing so would just
991 * add unnecessary deadlock risk. For this last reason, we do not yet
992 * check the ownership of the partitions/tables, which get added to
993 * the list to process. Ownership will be checked later on anyway.
994 */
995 if (include_children)
996 {
997 List *part_oids = find_all_inheritors(relid, NoLock, NULL);
998 ListCell *part_lc;
999
1000 foreach(part_lc, part_oids)
1001 {
1002 Oid part_oid = lfirst_oid(part_lc);
1003
1004 if (part_oid == relid)
1005 continue; /* ignore original table */
1006
1007 /*
1008 * We omit a RangeVar since it wouldn't be appropriate to
1009 * complain about failure to open one of these relations
1010 * later.
1011 */
1012 oldcontext = MemoryContextSwitchTo(vac_context);
1013 vacrels = lappend(vacrels, makeVacuumRelation(NULL,
1014 part_oid,
1015 vrel->va_cols));
1016 MemoryContextSwitchTo(oldcontext);
1017 }
1018 }
1019
1020 /*
1021 * Release lock again. This means that by the time we actually try to
1022 * process the table, it might be gone or renamed. In the former case
1023 * we'll silently ignore it; in the latter case we'll process it
1024 * anyway, but we must beware that the RangeVar doesn't necessarily
1025 * identify it anymore. This isn't ideal, perhaps, but there's little
1026 * practical alternative, since we're typically going to commit this
1027 * transaction and begin a new one between now and then. Moreover,
1028 * holding locks on multiple relations would create significant risk
1029 * of deadlock.
1030 */
1032 }
1033
1034 return vacrels;
1035}
#define OidIsValid(objectId)
Definition: c.h:746
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:225
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
List * lappend(List *list, void *datum)
Definition: list.c:339
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:229
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
VacuumRelation * makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
Definition: makefuncs.c:907
#define AmAutoVacuumWorkerProcess()
Definition: miscadmin.h:383
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:441
@ RVR_SKIP_LOCKED
Definition: namespace.h:74
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:255
#define lfirst_oid(lc)
Definition: pg_list.h:174
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
unsigned int Oid
Definition: postgres_ext.h:30
Definition: pg_list.h:54
char * relname
Definition: primnodes.h:83
bool inh
Definition: primnodes.h:86
RangeVar * relation
Definition: parsenodes.h:3951
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221
bool vacuum_is_permitted_for_relation(Oid relid, Form_pg_class reltuple, bits32 options)
Definition: vacuum.c:723

References AccessShareLock, AmAutoVacuumWorkerProcess, Assert(), elog, ereport, errcode(), errmsg(), ERROR, find_all_inheritors(), GETSTRUCT(), HeapTupleIsValid, RangeVar::inh, lappend(), lfirst_oid, makeVacuumRelation(), MemoryContextSwitchTo(), NIL, NoLock, ObjectIdGetDatum(), VacuumRelation::oid, OidIsValid, RangeVarGetRelidExtended(), VacuumRelation::relation, ReleaseSysCache(), RangeVar::relname, RVR_SKIP_LOCKED, SearchSysCache1(), UnlockRelationOid(), VacuumRelation::va_cols, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, vacuum_is_permitted_for_relation(), and WARNING.

Referenced by vacuum().

◆ get_all_vacuum_rels()

static List * get_all_vacuum_rels ( MemoryContext  vac_context,
int  options 
)
static

Definition at line 1042 of file vacuum.c.

1043{
1044 List *vacrels = NIL;
1045 Relation pgclass;
1046 TableScanDesc scan;
1047 HeapTuple tuple;
1048
1049 pgclass = table_open(RelationRelationId, AccessShareLock);
1050
1051 scan = table_beginscan_catalog(pgclass, 0, NULL);
1052
1053 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1054 {
1055 Form_pg_class classForm = (Form_pg_class) GETSTRUCT(tuple);
1056 MemoryContext oldcontext;
1057 Oid relid = classForm->oid;
1058
1059 /*
1060 * We include partitioned tables here; depending on which operation is
1061 * to be performed, caller will decide whether to process or ignore
1062 * them.
1063 */
1064 if (classForm->relkind != RELKIND_RELATION &&
1065 classForm->relkind != RELKIND_MATVIEW &&
1066 classForm->relkind != RELKIND_PARTITIONED_TABLE)
1067 continue;
1068
1069 /* check permissions of relation */
1070 if (!vacuum_is_permitted_for_relation(relid, classForm, options))
1071 continue;
1072
1073 /*
1074 * Build VacuumRelation(s) specifying the table OIDs to be processed.
1075 * We omit a RangeVar since it wouldn't be appropriate to complain
1076 * about failure to open one of these relations later.
1077 */
1078 oldcontext = MemoryContextSwitchTo(vac_context);
1079 vacrels = lappend(vacrels, makeVacuumRelation(NULL,
1080 relid,
1081 NIL));
1082 MemoryContextSwitchTo(oldcontext);
1083 }
1084
1085 table_endscan(scan);
1086 table_close(pgclass, AccessShareLock);
1087
1088 return vacrels;
1089}
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1314
@ ForwardScanDirection
Definition: sdir.h:28
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:113
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:979

References AccessShareLock, ForwardScanDirection, GETSTRUCT(), heap_getnext(), lappend(), makeVacuumRelation(), MemoryContextSwitchTo(), NIL, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), and vacuum_is_permitted_for_relation().

Referenced by vacuum().

◆ get_vacoptval_from_boolean()

static VacOptValue get_vacoptval_from_boolean ( DefElem def)
static

Definition at line 2600 of file vacuum.c.

2601{
2603}
@ VACOPTVALUE_ENABLED
Definition: vacuum.h:205
@ VACOPTVALUE_DISABLED
Definition: vacuum.h:204

References defGetBoolean(), VACOPTVALUE_DISABLED, and VACOPTVALUE_ENABLED.

Referenced by ExecVacuum().

◆ vac_bulkdel_one_index()

IndexBulkDeleteResult * vac_bulkdel_one_index ( IndexVacuumInfo ivinfo,
IndexBulkDeleteResult istat,
TidStore dead_items,
VacDeadItemsInfo dead_items_info 
)

Definition at line 2611 of file vacuum.c.

2613{
2614 /* Do bulk deletion */
2615 istat = index_bulk_delete(ivinfo, istat, vac_tid_reaped,
2616 dead_items);
2617
2618 ereport(ivinfo->message_level,
2619 (errmsg("scanned index \"%s\" to remove %" PRId64 " row versions",
2621 dead_items_info->num_items)));
2622
2623 return istat;
2624}
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)
Definition: indexam.c:795
#define RelationGetRelationName(relation)
Definition: rel.h:550
Relation index
Definition: genam.h:69
int message_level
Definition: genam.h:74
int64 num_items
Definition: vacuum.h:295
static bool vac_tid_reaped(ItemPointer itemptr, void *state)
Definition: vacuum.c:2658

References ereport, errmsg(), IndexVacuumInfo::index, index_bulk_delete(), IndexVacuumInfo::message_level, VacDeadItemsInfo::num_items, RelationGetRelationName, and vac_tid_reaped().

Referenced by lazy_vacuum_one_index(), and parallel_vacuum_process_one_index().

◆ vac_cleanup_one_index()

IndexBulkDeleteResult * vac_cleanup_one_index ( IndexVacuumInfo ivinfo,
IndexBulkDeleteResult istat 
)

Definition at line 2632 of file vacuum.c.

2633{
2634 istat = index_vacuum_cleanup(ivinfo, istat);
2635
2636 if (istat)
2637 ereport(ivinfo->message_level,
2638 (errmsg("index \"%s\" now contains %.0f row versions in %u pages",
2640 istat->num_index_tuples,
2641 istat->num_pages),
2642 errdetail("%.0f index row versions were removed.\n"
2643 "%u index pages were newly deleted.\n"
2644 "%u index pages are currently deleted, of which %u are currently reusable.",
2645 istat->tuples_removed,
2646 istat->pages_newly_deleted,
2647 istat->pages_deleted, istat->pages_free)));
2648
2649 return istat;
2650}
int errdetail(const char *fmt,...)
Definition: elog.c:1204
IndexBulkDeleteResult * index_vacuum_cleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *istat)
Definition: indexam.c:816
BlockNumber pages_deleted
Definition: genam.h:105
BlockNumber pages_newly_deleted
Definition: genam.h:104
BlockNumber pages_free
Definition: genam.h:106
BlockNumber num_pages
Definition: genam.h:100
double tuples_removed
Definition: genam.h:103
double num_index_tuples
Definition: genam.h:102

References ereport, errdetail(), errmsg(), IndexVacuumInfo::index, index_vacuum_cleanup(), IndexVacuumInfo::message_level, IndexBulkDeleteResult::num_index_tuples, IndexBulkDeleteResult::num_pages, IndexBulkDeleteResult::pages_deleted, IndexBulkDeleteResult::pages_free, IndexBulkDeleteResult::pages_newly_deleted, RelationGetRelationName, and IndexBulkDeleteResult::tuples_removed.

Referenced by lazy_cleanup_one_index(), and parallel_vacuum_process_one_index().

◆ vac_close_indexes()

void vac_close_indexes ( int  nindexes,
Relation Irel,
LOCKMODE  lockmode 
)

Definition at line 2383 of file vacuum.c.

2384{
2385 if (Irel == NULL)
2386 return;
2387
2388 while (nindexes--)
2389 {
2390 Relation ind = Irel[nindexes];
2391
2392 index_close(ind, lockmode);
2393 }
2394 pfree(Irel);
2395}
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
void pfree(void *pointer)
Definition: mcxt.c:2150

References index_close(), and pfree().

Referenced by do_analyze_rel(), heap_vacuum_rel(), and parallel_vacuum_main().

◆ vac_estimate_reltuples()

double vac_estimate_reltuples ( Relation  relation,
BlockNumber  total_pages,
BlockNumber  scanned_pages,
double  scanned_tuples 
)

Definition at line 1334 of file vacuum.c.

1338{
1339 BlockNumber old_rel_pages = relation->rd_rel->relpages;
1340 double old_rel_tuples = relation->rd_rel->reltuples;
1341 double old_density;
1342 double unscanned_pages;
1343 double total_tuples;
1344
1345 /* If we did scan the whole table, just use the count as-is */
1346 if (scanned_pages >= total_pages)
1347 return scanned_tuples;
1348
1349 /*
1350 * When successive VACUUM commands scan the same few pages again and
1351 * again, without anything from the table really changing, there is a risk
1352 * that our beliefs about tuple density will gradually become distorted.
1353 * This might be caused by vacuumlazy.c implementation details, such as
1354 * its tendency to always scan the last heap page. Handle that here.
1355 *
1356 * If the relation is _exactly_ the same size according to the existing
1357 * pg_class entry, and only a few of its pages (less than 2%) were
1358 * scanned, keep the existing value of reltuples. Also keep the existing
1359 * value when only a subset of rel's pages <= a single page were scanned.
1360 *
1361 * (Note: we might be returning -1 here.)
1362 */
1363 if (old_rel_pages == total_pages &&
1364 scanned_pages < (double) total_pages * 0.02)
1365 return old_rel_tuples;
1366 if (scanned_pages <= 1)
1367 return old_rel_tuples;
1368
1369 /*
1370 * If old density is unknown, we can't do much except scale up
1371 * scanned_tuples to match total_pages.
1372 */
1373 if (old_rel_tuples < 0 || old_rel_pages == 0)
1374 return floor((scanned_tuples / scanned_pages) * total_pages + 0.5);
1375
1376 /*
1377 * Okay, we've covered the corner cases. The normal calculation is to
1378 * convert the old measurement to a density (tuples per page), then
1379 * estimate the number of tuples in the unscanned pages using that figure,
1380 * and finally add on the number of tuples in the scanned pages.
1381 */
1382 old_density = old_rel_tuples / old_rel_pages;
1383 unscanned_pages = (double) total_pages - (double) scanned_pages;
1384 total_tuples = old_density * unscanned_pages + scanned_tuples;
1385 return floor(total_tuples + 0.5);
1386}
uint32 BlockNumber
Definition: block.h:31
Form_pg_class rd_rel
Definition: rel.h:111

References RelationData::rd_rel.

Referenced by lazy_scan_heap(), and statapprox_heap().

◆ vac_open_indexes()

void vac_open_indexes ( Relation  relation,
LOCKMODE  lockmode,
int *  nindexes,
Relation **  Irel 
)

Definition at line 2340 of file vacuum.c.

2342{
2343 List *indexoidlist;
2344 ListCell *indexoidscan;
2345 int i;
2346
2347 Assert(lockmode != NoLock);
2348
2349 indexoidlist = RelationGetIndexList(relation);
2350
2351 /* allocate enough memory for all indexes */
2352 i = list_length(indexoidlist);
2353
2354 if (i > 0)
2355 *Irel = (Relation *) palloc(i * sizeof(Relation));
2356 else
2357 *Irel = NULL;
2358
2359 /* collect just the ready indexes */
2360 i = 0;
2361 foreach(indexoidscan, indexoidlist)
2362 {
2363 Oid indexoid = lfirst_oid(indexoidscan);
2364 Relation indrel;
2365
2366 indrel = index_open(indexoid, lockmode);
2367 if (indrel->rd_index->indisready)
2368 (*Irel)[i++] = indrel;
2369 else
2370 index_close(indrel, lockmode);
2371 }
2372
2373 *nindexes = i;
2374
2375 list_free(indexoidlist);
2376}
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
int i
Definition: isn.c:77
void list_free(List *list)
Definition: list.c:1546
void * palloc(Size size)
Definition: mcxt.c:1943
static int list_length(const List *l)
Definition: pg_list.h:152
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4833
Form_pg_index rd_index
Definition: rel.h:192

References Assert(), i, index_close(), index_open(), lfirst_oid, list_free(), list_length(), NoLock, palloc(), RelationData::rd_index, and RelationGetIndexList().

Referenced by do_analyze_rel(), heap_vacuum_rel(), and parallel_vacuum_main().

◆ vac_tid_reaped()

static bool vac_tid_reaped ( ItemPointer  itemptr,
void *  state 
)
static

Definition at line 2658 of file vacuum.c.

2659{
2660 TidStore *dead_items = (TidStore *) state;
2661
2662 return TidStoreIsMember(dead_items, itemptr);
2663}
Definition: regguts.h:323
bool TidStoreIsMember(TidStore *ts, ItemPointer tid)
Definition: tidstore.c:421

References TidStoreIsMember().

Referenced by vac_bulkdel_one_index().

◆ vac_truncate_clog()

static void vac_truncate_clog ( TransactionId  frozenXID,
MultiXactId  minMulti,
TransactionId  lastSaneFrozenXid,
MultiXactId  lastSaneMinMulti 
)
static

Definition at line 1831 of file vacuum.c.

1835{
1837 Relation relation;
1838 TableScanDesc scan;
1839 HeapTuple tuple;
1840 Oid oldestxid_datoid;
1841 Oid minmulti_datoid;
1842 bool bogus = false;
1843 bool frozenAlreadyWrapped = false;
1844
1845 /* Restrict task to one backend per cluster; see SimpleLruTruncate(). */
1846 LWLockAcquire(WrapLimitsVacuumLock, LW_EXCLUSIVE);
1847
1848 /* init oldest datoids to sync with my frozenXID/minMulti values */
1849 oldestxid_datoid = MyDatabaseId;
1850 minmulti_datoid = MyDatabaseId;
1851
1852 /*
1853 * Scan pg_database to compute the minimum datfrozenxid/datminmxid
1854 *
1855 * Since vac_update_datfrozenxid updates datfrozenxid/datminmxid in-place,
1856 * the values could change while we look at them. Fetch each one just
1857 * once to ensure sane behavior of the comparison logic. (Here, as in
1858 * many other places, we assume that fetching or updating an XID in shared
1859 * storage is atomic.)
1860 *
1861 * Note: we need not worry about a race condition with new entries being
1862 * inserted by CREATE DATABASE. Any such entry will have a copy of some
1863 * existing DB's datfrozenxid, and that source DB cannot be ours because
1864 * of the interlock against copying a DB containing an active backend.
1865 * Hence the new entry will not reduce the minimum. Also, if two VACUUMs
1866 * concurrently modify the datfrozenxid's of different databases, the
1867 * worst possible outcome is that pg_xact is not truncated as aggressively
1868 * as it could be.
1869 */
1870 relation = table_open(DatabaseRelationId, AccessShareLock);
1871
1872 scan = table_beginscan_catalog(relation, 0, NULL);
1873
1874 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1875 {
1876 volatile FormData_pg_database *dbform = (Form_pg_database) GETSTRUCT(tuple);
1877 TransactionId datfrozenxid = dbform->datfrozenxid;
1878 TransactionId datminmxid = dbform->datminmxid;
1879
1882
1883 /*
1884 * If database is in the process of getting dropped, or has been
1885 * interrupted while doing so, no connections to it are possible
1886 * anymore. Therefore we don't need to take it into account here.
1887 * Which is good, because it can't be processed by autovacuum either.
1888 */
1890 {
1891 elog(DEBUG2,
1892 "skipping invalid database \"%s\" while computing relfrozenxid",
1893 NameStr(dbform->datname));
1894 continue;
1895 }
1896
1897 /*
1898 * If things are working properly, no database should have a
1899 * datfrozenxid or datminmxid that is "in the future". However, such
1900 * cases have been known to arise due to bugs in pg_upgrade. If we
1901 * see any entries that are "in the future", chicken out and don't do
1902 * anything. This ensures we won't truncate clog before those
1903 * databases have been scanned and cleaned up. (We will issue the
1904 * "already wrapped" warning if appropriate, though.)
1905 */
1906 if (TransactionIdPrecedes(lastSaneFrozenXid, datfrozenxid) ||
1907 MultiXactIdPrecedes(lastSaneMinMulti, datminmxid))
1908 bogus = true;
1909
1910 if (TransactionIdPrecedes(nextXID, datfrozenxid))
1911 frozenAlreadyWrapped = true;
1912 else if (TransactionIdPrecedes(datfrozenxid, frozenXID))
1913 {
1914 frozenXID = datfrozenxid;
1915 oldestxid_datoid = dbform->oid;
1916 }
1917
1918 if (MultiXactIdPrecedes(datminmxid, minMulti))
1919 {
1920 minMulti = datminmxid;
1921 minmulti_datoid = dbform->oid;
1922 }
1923 }
1924
1925 table_endscan(scan);
1926
1927 table_close(relation, AccessShareLock);
1928
1929 /*
1930 * Do not truncate CLOG if we seem to have suffered wraparound already;
1931 * the computed minimum XID might be bogus. This case should now be
1932 * impossible due to the defenses in GetNewTransactionId, but we keep the
1933 * test anyway.
1934 */
1935 if (frozenAlreadyWrapped)
1936 {
1938 (errmsg("some databases have not been vacuumed in over 2 billion transactions"),
1939 errdetail("You might have already suffered transaction-wraparound data loss.")));
1940 LWLockRelease(WrapLimitsVacuumLock);
1941 return;
1942 }
1943
1944 /* chicken out if data is bogus in any other way */
1945 if (bogus)
1946 {
1947 LWLockRelease(WrapLimitsVacuumLock);
1948 return;
1949 }
1950
1951 /*
1952 * Advance the oldest value for commit timestamps before truncating, so
1953 * that if a user requests a timestamp for a transaction we're truncating
1954 * away right after this point, they get NULL instead of an ugly "file not
1955 * found" error from slru.c. This doesn't matter for xact/multixact
1956 * because they are not subject to arbitrary lookups from users.
1957 */
1958 AdvanceOldestCommitTsXid(frozenXID);
1959
1960 /*
1961 * Truncate CLOG, multixact and CommitTs to the oldest computed value.
1962 */
1963 TruncateCLOG(frozenXID, oldestxid_datoid);
1964 TruncateCommitTs(frozenXID);
1965 TruncateMultiXact(minMulti, minmulti_datoid);
1966
1967 /*
1968 * Update the wrap limit for GetNewTransactionId and creation of new
1969 * MultiXactIds. Note: these functions will also signal the postmaster
1970 * for an(other) autovac cycle if needed. XXX should we avoid possibly
1971 * signaling twice?
1972 */
1973 SetTransactionIdLimit(frozenXID, oldestxid_datoid);
1974 SetMultiXactIdLimit(minMulti, minmulti_datoid, false);
1975
1976 LWLockRelease(WrapLimitsVacuumLock);
1977}
#define NameStr(name)
Definition: c.h:717
uint32 TransactionId
Definition: c.h:623
void TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid)
Definition: clog.c:1000
void AdvanceOldestCommitTsXid(TransactionId oldestXact)
Definition: commit_ts.c:936
void TruncateCommitTs(TransactionId oldestXact)
Definition: commit_ts.c:883
bool database_is_invalid_form(Form_pg_database datform)
Definition: dbcommands.c:3212
#define DEBUG2
Definition: elog.h:29
Oid MyDatabaseId
Definition: globals.c:95
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1182
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1902
@ LW_EXCLUSIVE
Definition: lwlock.h:114
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3317
void SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, bool is_startup)
Definition: multixact.c:2362
void TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB)
Definition: multixact.c:3102
#define MultiXactIdIsValid(multi)
Definition: multixact.h:28
TransactionId datfrozenxid
Definition: pg_database.h:62
TransactionId datminmxid
Definition: pg_database.h:65
FormData_pg_database * Form_pg_database
Definition: pg_database.h:96
FormData_pg_database
Definition: pg_database.h:89
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280
static TransactionId ReadNextTransactionId(void)
Definition: transam.h:315
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid)
Definition: varsup.c:372

References AccessShareLock, AdvanceOldestCommitTsXid(), Assert(), database_is_invalid_form(), datfrozenxid, datminmxid, DEBUG2, elog, ereport, errdetail(), errmsg(), FormData_pg_database, ForwardScanDirection, GETSTRUCT(), heap_getnext(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MultiXactIdIsValid, MultiXactIdPrecedes(), MyDatabaseId, NameStr, ReadNextTransactionId(), SetMultiXactIdLimit(), SetTransactionIdLimit(), table_beginscan_catalog(), table_close(), table_endscan(), table_open(), TransactionIdIsNormal, TransactionIdPrecedes(), TruncateCLOG(), TruncateCommitTs(), TruncateMultiXact(), and WARNING.

Referenced by vac_update_datfrozenxid().

◆ vac_update_datfrozenxid()

void vac_update_datfrozenxid ( void  )

Definition at line 1612 of file vacuum.c.

1613{
1614 HeapTuple tuple;
1615 Form_pg_database dbform;
1616 Relation relation;
1617 SysScanDesc scan;
1618 HeapTuple classTup;
1619 TransactionId newFrozenXid;
1620 MultiXactId newMinMulti;
1621 TransactionId lastSaneFrozenXid;
1622 MultiXactId lastSaneMinMulti;
1623 bool bogus = false;
1624 bool dirty = false;
1625 ScanKeyData key[1];
1626 void *inplace_state;
1627
1628 /*
1629 * Restrict this task to one backend per database. This avoids race
1630 * conditions that would move datfrozenxid or datminmxid backward. It
1631 * avoids calling vac_truncate_clog() with a datfrozenxid preceding a
1632 * datfrozenxid passed to an earlier vac_truncate_clog() call.
1633 */
1635
1636 /*
1637 * Initialize the "min" calculation with
1638 * GetOldestNonRemovableTransactionId(), which is a reasonable
1639 * approximation to the minimum relfrozenxid for not-yet-committed
1640 * pg_class entries for new tables; see AddNewRelationTuple(). So we
1641 * cannot produce a wrong minimum by starting with this.
1642 */
1643 newFrozenXid = GetOldestNonRemovableTransactionId(NULL);
1644
1645 /*
1646 * Similarly, initialize the MultiXact "min" with the value that would be
1647 * used on pg_class for new tables. See AddNewRelationTuple().
1648 */
1649 newMinMulti = GetOldestMultiXactId();
1650
1651 /*
1652 * Identify the latest relfrozenxid and relminmxid values that we could
1653 * validly see during the scan. These are conservative values, but it's
1654 * not really worth trying to be more exact.
1655 */
1656 lastSaneFrozenXid = ReadNextTransactionId();
1657 lastSaneMinMulti = ReadNextMultiXactId();
1658
1659 /*
1660 * We must seqscan pg_class to find the minimum Xid, because there is no
1661 * index that can help us here.
1662 *
1663 * See vac_truncate_clog() for the race condition to prevent.
1664 */
1665 relation = table_open(RelationRelationId, AccessShareLock);
1666
1667 scan = systable_beginscan(relation, InvalidOid, false,
1668 NULL, 0, NULL);
1669
1670 while ((classTup = systable_getnext(scan)) != NULL)
1671 {
1672 volatile FormData_pg_class *classForm = (Form_pg_class) GETSTRUCT(classTup);
1673 TransactionId relfrozenxid = classForm->relfrozenxid;
1674 TransactionId relminmxid = classForm->relminmxid;
1675
1676 /*
1677 * Only consider relations able to hold unfrozen XIDs (anything else
1678 * should have InvalidTransactionId in relfrozenxid anyway).
1679 */
1680 if (classForm->relkind != RELKIND_RELATION &&
1681 classForm->relkind != RELKIND_MATVIEW &&
1682 classForm->relkind != RELKIND_TOASTVALUE)
1683 {
1684 Assert(!TransactionIdIsValid(relfrozenxid));
1685 Assert(!MultiXactIdIsValid(relminmxid));
1686 continue;
1687 }
1688
1689 /*
1690 * Some table AMs might not need per-relation xid / multixid horizons.
1691 * It therefore seems reasonable to allow relfrozenxid and relminmxid
1692 * to not be set (i.e. set to their respective Invalid*Id)
1693 * independently. Thus validate and compute horizon for each only if
1694 * set.
1695 *
1696 * If things are working properly, no relation should have a
1697 * relfrozenxid or relminmxid that is "in the future". However, such
1698 * cases have been known to arise due to bugs in pg_upgrade. If we
1699 * see any entries that are "in the future", chicken out and don't do
1700 * anything. This ensures we won't truncate clog & multixact SLRUs
1701 * before those relations have been scanned and cleaned up.
1702 */
1703
1704 if (TransactionIdIsValid(relfrozenxid))
1705 {
1706 Assert(TransactionIdIsNormal(relfrozenxid));
1707
1708 /* check for values in the future */
1709 if (TransactionIdPrecedes(lastSaneFrozenXid, relfrozenxid))
1710 {
1711 bogus = true;
1712 break;
1713 }
1714
1715 /* determine new horizon */
1716 if (TransactionIdPrecedes(relfrozenxid, newFrozenXid))
1717 newFrozenXid = relfrozenxid;
1718 }
1719
1720 if (MultiXactIdIsValid(relminmxid))
1721 {
1722 /* check for values in the future */
1723 if (MultiXactIdPrecedes(lastSaneMinMulti, relminmxid))
1724 {
1725 bogus = true;
1726 break;
1727 }
1728
1729 /* determine new horizon */
1730 if (MultiXactIdPrecedes(relminmxid, newMinMulti))
1731 newMinMulti = relminmxid;
1732 }
1733 }
1734
1735 /* we're done with pg_class */
1736 systable_endscan(scan);
1737 table_close(relation, AccessShareLock);
1738
1739 /* chicken out if bogus data found */
1740 if (bogus)
1741 return;
1742
1743 Assert(TransactionIdIsNormal(newFrozenXid));
1744 Assert(MultiXactIdIsValid(newMinMulti));
1745
1746 /* Now fetch the pg_database tuple we need to update. */
1747 relation = table_open(DatabaseRelationId, RowExclusiveLock);
1748
1749 /*
1750 * Fetch a copy of the tuple to scribble on. We could check the syscache
1751 * tuple first. If that concluded !dirty, we'd avoid waiting on
1752 * concurrent heap_update() and would avoid exclusive-locking the buffer.
1753 * For now, don't optimize that.
1754 */
1755 ScanKeyInit(&key[0],
1756 Anum_pg_database_oid,
1757 BTEqualStrategyNumber, F_OIDEQ,
1759
1760 systable_inplace_update_begin(relation, DatabaseOidIndexId, true,
1761 NULL, 1, key, &tuple, &inplace_state);
1762
1763 if (!HeapTupleIsValid(tuple))
1764 elog(ERROR, "could not find tuple for database %u", MyDatabaseId);
1765
1766 dbform = (Form_pg_database) GETSTRUCT(tuple);
1767
1768 /*
1769 * As in vac_update_relstats(), we ordinarily don't want to let
1770 * datfrozenxid go backward; but if it's "in the future" then it must be
1771 * corrupt and it seems best to overwrite it.
1772 */
1773 if (dbform->datfrozenxid != newFrozenXid &&
1774 (TransactionIdPrecedes(dbform->datfrozenxid, newFrozenXid) ||
1775 TransactionIdPrecedes(lastSaneFrozenXid, dbform->datfrozenxid)))
1776 {
1777 dbform->datfrozenxid = newFrozenXid;
1778 dirty = true;
1779 }
1780 else
1781 newFrozenXid = dbform->datfrozenxid;
1782
1783 /* Ditto for datminmxid */
1784 if (dbform->datminmxid != newMinMulti &&
1785 (MultiXactIdPrecedes(dbform->datminmxid, newMinMulti) ||
1786 MultiXactIdPrecedes(lastSaneMinMulti, dbform->datminmxid)))
1787 {
1788 dbform->datminmxid = newMinMulti;
1789 dirty = true;
1790 }
1791 else
1792 newMinMulti = dbform->datminmxid;
1793
1794 if (dirty)
1795 systable_inplace_update_finish(inplace_state, tuple);
1796 else
1797 systable_inplace_update_cancel(inplace_state);
1798
1799 heap_freetuple(tuple);
1800 table_close(relation, RowExclusiveLock);
1801
1802 /*
1803 * If we were able to advance datfrozenxid or datminmxid, see if we can
1804 * truncate pg_xact and/or pg_multixact. Also do it if the shared
1805 * XID-wrap-limit info is stale, since this action will update that too.
1806 */
1807 if (dirty || ForceTransactionIdLimitUpdate())
1808 vac_truncate_clog(newFrozenXid, newMinMulti,
1809 lastSaneFrozenXid, lastSaneMinMulti);
1810}
TransactionId MultiXactId
Definition: c.h:633
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:603
void systable_inplace_update_cancel(void *state)
Definition: genam.c:902
void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)
Definition: genam.c:807
void systable_inplace_update_finish(void *state, HeapTuple tuple)
Definition: genam.c:883
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:388
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
void LockDatabaseFrozenIds(LOCKMODE lockmode)
Definition: lmgr.c:491
#define ExclusiveLock
Definition: lockdefs.h:42
#define RowExclusiveLock
Definition: lockdefs.h:38
MultiXactId GetOldestMultiXactId(void)
Definition: multixact.c:2660
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:771
FormData_pg_class
Definition: pg_class.h:145
TransactionId GetOldestNonRemovableTransactionId(Relation rel)
Definition: procarray.c:2005
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define TransactionIdIsValid(xid)
Definition: transam.h:41
static void vac_truncate_clog(TransactionId frozenXID, MultiXactId minMulti, TransactionId lastSaneFrozenXid, MultiXactId lastSaneMinMulti)
Definition: vacuum.c:1831
bool ForceTransactionIdLimitUpdate(void)
Definition: varsup.c:517

References AccessShareLock, Assert(), BTEqualStrategyNumber, elog, ERROR, ExclusiveLock, ForceTransactionIdLimitUpdate(), FormData_pg_class, GetOldestMultiXactId(), GetOldestNonRemovableTransactionId(), GETSTRUCT(), heap_freetuple(), HeapTupleIsValid, InvalidOid, sort-test::key, LockDatabaseFrozenIds(), MultiXactIdIsValid, MultiXactIdPrecedes(), MyDatabaseId, ObjectIdGetDatum(), ReadNextMultiXactId(), ReadNextTransactionId(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), systable_inplace_update_begin(), systable_inplace_update_cancel(), systable_inplace_update_finish(), table_close(), table_open(), TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), and vac_truncate_clog().

Referenced by do_autovacuum(), and vacuum().

◆ vac_update_relstats()

void vac_update_relstats ( Relation  relation,
BlockNumber  num_pages,
double  num_tuples,
BlockNumber  num_all_visible_pages,
BlockNumber  num_all_frozen_pages,
bool  hasindex,
TransactionId  frozenxid,
MultiXactId  minmulti,
bool *  frozenxid_updated,
bool *  minmulti_updated,
bool  in_outer_xact 
)

Definition at line 1430 of file vacuum.c.

1438{
1439 Oid relid = RelationGetRelid(relation);
1440 Relation rd;
1441 ScanKeyData key[1];
1442 HeapTuple ctup;
1443 void *inplace_state;
1444 Form_pg_class pgcform;
1445 bool dirty,
1446 futurexid,
1447 futuremxid;
1448 TransactionId oldfrozenxid;
1449 MultiXactId oldminmulti;
1450
1451 rd = table_open(RelationRelationId, RowExclusiveLock);
1452
1453 /* Fetch a copy of the tuple to scribble on */
1454 ScanKeyInit(&key[0],
1455 Anum_pg_class_oid,
1456 BTEqualStrategyNumber, F_OIDEQ,
1457 ObjectIdGetDatum(relid));
1458 systable_inplace_update_begin(rd, ClassOidIndexId, true,
1459 NULL, 1, key, &ctup, &inplace_state);
1460 if (!HeapTupleIsValid(ctup))
1461 elog(ERROR, "pg_class entry for relid %u vanished during vacuuming",
1462 relid);
1463 pgcform = (Form_pg_class) GETSTRUCT(ctup);
1464
1465 /* Apply statistical updates, if any, to copied tuple */
1466
1467 dirty = false;
1468 if (pgcform->relpages != (int32) num_pages)
1469 {
1470 pgcform->relpages = (int32) num_pages;
1471 dirty = true;
1472 }
1473 if (pgcform->reltuples != (float4) num_tuples)
1474 {
1475 pgcform->reltuples = (float4) num_tuples;
1476 dirty = true;
1477 }
1478 if (pgcform->relallvisible != (int32) num_all_visible_pages)
1479 {
1480 pgcform->relallvisible = (int32) num_all_visible_pages;
1481 dirty = true;
1482 }
1483 if (pgcform->relallfrozen != (int32) num_all_frozen_pages)
1484 {
1485 pgcform->relallfrozen = (int32) num_all_frozen_pages;
1486 dirty = true;
1487 }
1488
1489 /* Apply DDL updates, but not inside an outer transaction (see above) */
1490
1491 if (!in_outer_xact)
1492 {
1493 /*
1494 * If we didn't find any indexes, reset relhasindex.
1495 */
1496 if (pgcform->relhasindex && !hasindex)
1497 {
1498 pgcform->relhasindex = false;
1499 dirty = true;
1500 }
1501
1502 /* We also clear relhasrules and relhastriggers if needed */
1503 if (pgcform->relhasrules && relation->rd_rules == NULL)
1504 {
1505 pgcform->relhasrules = false;
1506 dirty = true;
1507 }
1508 if (pgcform->relhastriggers && relation->trigdesc == NULL)
1509 {
1510 pgcform->relhastriggers = false;
1511 dirty = true;
1512 }
1513 }
1514
1515 /*
1516 * Update relfrozenxid, unless caller passed InvalidTransactionId
1517 * indicating it has no new data.
1518 *
1519 * Ordinarily, we don't let relfrozenxid go backwards. However, if the
1520 * stored relfrozenxid is "in the future" then it seems best to assume
1521 * it's corrupt, and overwrite with the oldest remaining XID in the table.
1522 * This should match vac_update_datfrozenxid() concerning what we consider
1523 * to be "in the future".
1524 */
1525 oldfrozenxid = pgcform->relfrozenxid;
1526 futurexid = false;
1527 if (frozenxid_updated)
1528 *frozenxid_updated = false;
1529 if (TransactionIdIsNormal(frozenxid) && oldfrozenxid != frozenxid)
1530 {
1531 bool update = false;
1532
1533 if (TransactionIdPrecedes(oldfrozenxid, frozenxid))
1534 update = true;
1535 else if (TransactionIdPrecedes(ReadNextTransactionId(), oldfrozenxid))
1536 futurexid = update = true;
1537
1538 if (update)
1539 {
1540 pgcform->relfrozenxid = frozenxid;
1541 dirty = true;
1542 if (frozenxid_updated)
1543 *frozenxid_updated = true;
1544 }
1545 }
1546
1547 /* Similarly for relminmxid */
1548 oldminmulti = pgcform->relminmxid;
1549 futuremxid = false;
1550 if (minmulti_updated)
1551 *minmulti_updated = false;
1552 if (MultiXactIdIsValid(minmulti) && oldminmulti != minmulti)
1553 {
1554 bool update = false;
1555
1556 if (MultiXactIdPrecedes(oldminmulti, minmulti))
1557 update = true;
1558 else if (MultiXactIdPrecedes(ReadNextMultiXactId(), oldminmulti))
1559 futuremxid = update = true;
1560
1561 if (update)
1562 {
1563 pgcform->relminmxid = minmulti;
1564 dirty = true;
1565 if (minmulti_updated)
1566 *minmulti_updated = true;
1567 }
1568 }
1569
1570 /* If anything changed, write out the tuple. */
1571 if (dirty)
1572 systable_inplace_update_finish(inplace_state, ctup);
1573 else
1574 systable_inplace_update_cancel(inplace_state);
1575
1577
1578 if (futurexid)
1581 errmsg_internal("overwrote invalid relfrozenxid value %u with new value %u for table \"%s\"",
1582 oldfrozenxid, frozenxid,
1583 RelationGetRelationName(relation))));
1584 if (futuremxid)
1587 errmsg_internal("overwrote invalid relminmxid value %u with new value %u for table \"%s\"",
1588 oldminmulti, minmulti,
1589 RelationGetRelationName(relation))));
1590}
int32_t int32
Definition: c.h:498
float float4
Definition: c.h:600
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1158
#define ERRCODE_DATA_CORRUPTED
Definition: pg_basebackup.c:41
#define RelationGetRelid(relation)
Definition: rel.h:516
TriggerDesc * trigdesc
Definition: rel.h:117
RuleLock * rd_rules
Definition: rel.h:115

References BTEqualStrategyNumber, elog, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errmsg_internal(), ERROR, GETSTRUCT(), HeapTupleIsValid, sort-test::key, MultiXactIdIsValid, MultiXactIdPrecedes(), ObjectIdGetDatum(), RelationData::rd_rules, ReadNextMultiXactId(), ReadNextTransactionId(), RelationGetRelationName, RelationGetRelid, RowExclusiveLock, ScanKeyInit(), systable_inplace_update_begin(), systable_inplace_update_cancel(), systable_inplace_update_finish(), table_close(), table_open(), TransactionIdIsNormal, TransactionIdPrecedes(), RelationData::trigdesc, and WARNING.

Referenced by do_analyze_rel(), heap_vacuum_rel(), and update_relstats_all_indexes().

◆ vacuum()

void vacuum ( List relations,
VacuumParams params,
BufferAccessStrategy  bstrategy,
MemoryContext  vac_context,
bool  isTopLevel 
)

Definition at line 496 of file vacuum.c.

498{
499 static bool in_vacuum = false;
500
501 const char *stmttype;
502 volatile bool in_outer_xact,
503 use_own_xacts;
504
505 Assert(params != NULL);
506
507 stmttype = (params->options & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE";
508
509 /*
510 * We cannot run VACUUM inside a user transaction block; if we were inside
511 * a transaction, then our commit- and start-transaction-command calls
512 * would not have the intended effect! There are numerous other subtle
513 * dependencies on this, too.
514 *
515 * ANALYZE (without VACUUM) can run either way.
516 */
517 if (params->options & VACOPT_VACUUM)
518 {
519 PreventInTransactionBlock(isTopLevel, stmttype);
520 in_outer_xact = false;
521 }
522 else
523 in_outer_xact = IsInTransactionBlock(isTopLevel);
524
525 /*
526 * Check for and disallow recursive calls. This could happen when VACUUM
527 * FULL or ANALYZE calls a hostile index expression that itself calls
528 * ANALYZE.
529 */
530 if (in_vacuum)
532 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
533 errmsg("%s cannot be executed from VACUUM or ANALYZE",
534 stmttype)));
535
536 /*
537 * Build list of relation(s) to process, putting any new data in
538 * vac_context for safekeeping.
539 */
541 {
542 /* We don't process any tables in this case */
543 Assert(relations == NIL);
544 }
545 else if (relations != NIL)
546 {
547 List *newrels = NIL;
548 ListCell *lc;
549
550 foreach(lc, relations)
551 {
553 List *sublist;
554 MemoryContext old_context;
555
556 sublist = expand_vacuum_rel(vrel, vac_context, params->options);
557 old_context = MemoryContextSwitchTo(vac_context);
558 newrels = list_concat(newrels, sublist);
559 MemoryContextSwitchTo(old_context);
560 }
561 relations = newrels;
562 }
563 else
564 relations = get_all_vacuum_rels(vac_context, params->options);
565
566 /*
567 * Decide whether we need to start/commit our own transactions.
568 *
569 * For VACUUM (with or without ANALYZE): always do so, so that we can
570 * release locks as soon as possible. (We could possibly use the outer
571 * transaction for a one-table VACUUM, but handling TOAST tables would be
572 * problematic.)
573 *
574 * For ANALYZE (no VACUUM): if inside a transaction block, we cannot
575 * start/commit our own transactions. Also, there's no need to do so if
576 * only processing one relation. For multiple relations when not within a
577 * transaction block, and also in an autovacuum worker, use own
578 * transactions so we can release locks sooner.
579 */
580 if (params->options & VACOPT_VACUUM)
581 use_own_xacts = true;
582 else
583 {
584 Assert(params->options & VACOPT_ANALYZE);
586 use_own_xacts = true;
587 else if (in_outer_xact)
588 use_own_xacts = false;
589 else if (list_length(relations) > 1)
590 use_own_xacts = true;
591 else
592 use_own_xacts = false;
593 }
594
595 /*
596 * vacuum_rel expects to be entered with no transaction active; it will
597 * start and commit its own transaction. But we are called by an SQL
598 * command, and so we are executing inside a transaction already. We
599 * commit the transaction started in PostgresMain() here, and start
600 * another one before exiting to match the commit waiting for us back in
601 * PostgresMain().
602 */
603 if (use_own_xacts)
604 {
605 Assert(!in_outer_xact);
606
607 /* ActiveSnapshot is not set by autovacuum */
608 if (ActiveSnapshotSet())
610
611 /* matches the StartTransaction in PostgresMain() */
613 }
614
615 /* Turn vacuum cost accounting on or off, and set/clear in_vacuum */
616 PG_TRY();
617 {
618 ListCell *cur;
619
620 in_vacuum = true;
621 VacuumFailsafeActive = false;
627
628 /*
629 * Loop to process each selected relation.
630 */
631 foreach(cur, relations)
632 {
634
635 if (params->options & VACOPT_VACUUM)
636 {
637 if (!vacuum_rel(vrel->oid, vrel->relation, params, bstrategy))
638 continue;
639 }
640
641 if (params->options & VACOPT_ANALYZE)
642 {
643 /*
644 * If using separate xacts, start one for analyze. Otherwise,
645 * we can use the outer transaction.
646 */
647 if (use_own_xacts)
648 {
650 /* functions in indexes may want a snapshot set */
652 }
653
654 analyze_rel(vrel->oid, vrel->relation, params,
655 vrel->va_cols, in_outer_xact, bstrategy);
656
657 if (use_own_xacts)
658 {
660 /* standard_ProcessUtility() does CCI if !use_own_xacts */
663 }
664 else
665 {
666 /*
667 * If we're not using separate xacts, better separate the
668 * ANALYZE actions with CCIs. This avoids trouble if user
669 * says "ANALYZE t, t".
670 */
672 }
673 }
674
675 /*
676 * Ensure VacuumFailsafeActive has been reset before vacuuming the
677 * next relation.
678 */
679 VacuumFailsafeActive = false;
680 }
681 }
682 PG_FINALLY();
683 {
684 in_vacuum = false;
685 VacuumCostActive = false;
686 VacuumFailsafeActive = false;
688 }
689 PG_END_TRY();
690
691 /*
692 * Finish up processing.
693 */
694 if (use_own_xacts)
695 {
696 /* here, we are not in a transaction */
697
698 /*
699 * This matches the CommitTransaction waiting for us in
700 * PostgresMain().
701 */
703 }
704
705 if ((params->options & VACOPT_VACUUM) &&
707 {
708 /*
709 * Update pg_database.datfrozenxid, and truncate pg_xact if possible.
710 */
712 }
713
714}
void VacuumUpdateCosts(void)
Definition: autovacuum.c:1658
void analyze_rel(Oid relid, RangeVar *relation, VacuumParams *params, List *va_cols, bool in_outer_xact, BufferAccessStrategy bstrategy)
Definition: analyze.c:109
struct cursor * cur
Definition: ecpg.c:29
#define PG_TRY(...)
Definition: elog.h:371
#define PG_END_TRY(...)
Definition: elog.h:396
#define PG_FINALLY(...)
Definition: elog.h:388
bool VacuumCostActive
Definition: globals.c:159
List * list_concat(List *list1, const List *list2)
Definition: list.c:561
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:271
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:669
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:799
void PopActiveSnapshot(void)
Definition: snapmgr.c:762
static List * expand_vacuum_rel(VacuumRelation *vrel, MemoryContext vac_context, int options)
Definition: vacuum.c:887
static List * get_all_vacuum_rels(MemoryContext vac_context, int options)
Definition: vacuum.c:1042
static bool vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: vacuum.c:2000
void vac_update_datfrozenxid(void)
Definition: vacuum.c:1612
bool VacuumFailsafeActive
Definition: vacuum.c:108
bool IsInTransactionBlock(bool isTopLevel)
Definition: xact.c:3769
void CommandCounterIncrement(void)
Definition: xact.c:1100
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3648
void StartTransactionCommand(void)
Definition: xact.c:3059
void CommitTransactionCommand(void)
Definition: xact.c:3157

References ActiveSnapshotSet(), AmAutoVacuumWorkerProcess, analyze_rel(), Assert(), CommandCounterIncrement(), CommitTransactionCommand(), cur, ereport, errcode(), errmsg(), ERROR, expand_vacuum_rel(), get_all_vacuum_rels(), GetTransactionSnapshot(), IsInTransactionBlock(), lfirst_node, list_concat(), list_length(), MemoryContextSwitchTo(), NIL, VacuumRelation::oid, VacuumParams::options, PG_END_TRY, PG_FINALLY, PG_TRY, PopActiveSnapshot(), PreventInTransactionBlock(), PushActiveSnapshot(), VacuumRelation::relation, StartTransactionCommand(), VacuumRelation::va_cols, vac_update_datfrozenxid(), VACOPT_ANALYZE, VACOPT_ONLY_DATABASE_STATS, VACOPT_SKIP_DATABASE_STATS, VACOPT_VACUUM, vacuum_rel(), VacuumActiveNWorkers, VacuumCostActive, VacuumCostBalance, VacuumCostBalanceLocal, VacuumFailsafeActive, VacuumSharedCostBalance, and VacuumUpdateCosts().

Referenced by autovacuum_do_vac_analyze(), ExecVacuum(), parallel_vacuum_index_is_parallel_safe(), and parallel_vacuum_process_all_indexes().

◆ vacuum_delay_point()

void vacuum_delay_point ( bool  is_analyze)

Definition at line 2404 of file vacuum.c.

2405{
2406 double msec = 0;
2407
2408 /* Always check for interrupts */
2410
2411 if (InterruptPending ||
2413 return;
2414
2415 /*
2416 * Autovacuum workers should reload the configuration file if requested.
2417 * This allows changes to [autovacuum_]vacuum_cost_limit and
2418 * [autovacuum_]vacuum_cost_delay to take effect while a table is being
2419 * vacuumed or analyzed.
2420 */
2422 {
2423 ConfigReloadPending = false;
2426 }
2427
2428 /*
2429 * If we disabled cost-based delays after reloading the config file,
2430 * return.
2431 */
2432 if (!VacuumCostActive)
2433 return;
2434
2435 /*
2436 * For parallel vacuum, the delay is computed based on the shared cost
2437 * balance. See compute_parallel_delay.
2438 */
2439 if (VacuumSharedCostBalance != NULL)
2440 msec = compute_parallel_delay();
2443
2444 /* Nap if appropriate */
2445 if (msec > 0)
2446 {
2447 instr_time delay_start;
2448
2449 if (msec > vacuum_cost_delay * 4)
2450 msec = vacuum_cost_delay * 4;
2451
2453 INSTR_TIME_SET_CURRENT(delay_start);
2454
2455 pgstat_report_wait_start(WAIT_EVENT_VACUUM_DELAY);
2456 pg_usleep(msec * 1000);
2458
2460 {
2461 instr_time delay_end;
2462 instr_time delay;
2463
2464 INSTR_TIME_SET_CURRENT(delay_end);
2465 INSTR_TIME_SET_ZERO(delay);
2466 INSTR_TIME_ACCUM_DIFF(delay, delay_end, delay_start);
2467
2468 /*
2469 * For parallel workers, we only report the delay time every once
2470 * in a while to avoid overloading the leader with messages and
2471 * interrupts.
2472 */
2473 if (IsParallelWorker())
2474 {
2475 static instr_time last_report_time;
2476 instr_time time_since_last_report;
2477
2478 Assert(!is_analyze);
2479
2480 /* Accumulate the delay time */
2482
2483 /* Calculate interval since last report */
2484 INSTR_TIME_SET_ZERO(time_since_last_report);
2485 INSTR_TIME_ACCUM_DIFF(time_since_last_report, delay_end, last_report_time);
2486
2487 /* If we haven't reported in a while, do so now */
2488 if (INSTR_TIME_GET_NANOSEC(time_since_last_report) >=
2490 {
2493
2494 /* Reset variables */
2495 last_report_time = delay_end;
2497 }
2498 }
2499 else if (is_analyze)
2501 INSTR_TIME_GET_NANOSEC(delay));
2502 else
2504 INSTR_TIME_GET_NANOSEC(delay));
2505 }
2506
2507 /*
2508 * We don't want to ignore postmaster death during very long vacuums
2509 * with vacuum_cost_delay configured. We can't use the usual
2510 * WaitLatch() approach here because we want microsecond-based sleep
2511 * durations above.
2512 */
2514 exit(1);
2515
2517
2518 /*
2519 * Balance and update limit values for autovacuum workers. We must do
2520 * this periodically, as the number of workers across which we are
2521 * balancing the limit may have changed.
2522 *
2523 * TODO: There may be better criteria for determining when to do this
2524 * besides "check after napping".
2525 */
2527
2528 /* Might have gotten an interrupt while sleeping */
2530 }
2531}
void AutoVacuumUpdateCostLimit(void)
Definition: autovacuum.c:1727
void pgstat_progress_parallel_incr_param(int index, int64 incr)
void pgstat_progress_incr_param(int index, int64 incr)
volatile sig_atomic_t InterruptPending
Definition: globals.c:32
bool IsUnderPostmaster
Definition: globals.c:121
void ProcessConfigFile(GucContext context)
Definition: guc-file.l:120
@ PGC_SIGHUP
Definition: guc.h:75
#define IsParallelWorker()
Definition: parallel.h:60
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:122
#define INSTR_TIME_GET_NANOSEC(t)
Definition: instr_time.h:125
#define INSTR_TIME_SET_ZERO(t)
Definition: instr_time.h:172
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
Definition: instr_time.h:184
volatile sig_atomic_t ConfigReloadPending
Definition: interrupt.c:27
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
#define PostmasterIsAlive()
Definition: pmsignal.h:107
#define PROGRESS_VACUUM_DELAY_TIME
Definition: progress.h:31
#define PROGRESS_ANALYZE_DELAY_TIME
Definition: progress.h:50
void pg_usleep(long microsec)
Definition: signal.c:53
bool track_cost_delay_timing
Definition: vacuum.c:80
static double compute_parallel_delay(void)
Definition: vacuum.c:2556
#define PARALLEL_VACUUM_DELAY_REPORT_INTERVAL_NS
Definition: vacuum.c:68
int64 parallel_vacuum_worker_delay_ns
Definition: vacuum.c:93
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:85
static void pgstat_report_wait_end(void)
Definition: wait_event.h:101

References AmAutoVacuumWorkerProcess, Assert(), AutoVacuumUpdateCostLimit(), CHECK_FOR_INTERRUPTS, compute_parallel_delay(), ConfigReloadPending, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_GET_NANOSEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, InterruptPending, IsParallelWorker, IsUnderPostmaster, PARALLEL_VACUUM_DELAY_REPORT_INTERVAL_NS, parallel_vacuum_worker_delay_ns, pg_usleep(), PGC_SIGHUP, pgstat_progress_incr_param(), pgstat_progress_parallel_incr_param(), pgstat_report_wait_end(), pgstat_report_wait_start(), PostmasterIsAlive, ProcessConfigFile(), PROGRESS_ANALYZE_DELAY_TIME, PROGRESS_VACUUM_DELAY_TIME, track_cost_delay_timing, vacuum_cost_delay, vacuum_cost_limit, VacuumCostActive, VacuumCostBalance, VacuumSharedCostBalance, and VacuumUpdateCosts().

Referenced by acquire_sample_rows(), blbulkdelete(), blvacuumcleanup(), btvacuumpage(), btvacuumscan(), compute_array_stats(), compute_distinct_stats(), compute_index_stats(), compute_range_stats(), compute_scalar_stats(), compute_trivial_stats(), compute_tsvector_stats(), file_acquire_sample_rows(), ginbulkdelete(), ginInsertCleanup(), ginvacuumcleanup(), gistvacuumpage(), gistvacuumscan(), hashbucketcleanup(), lazy_scan_heap(), lazy_vacuum_heap_rel(), spgprocesspending(), and spgvacuumscan().

◆ vacuum_get_cutoffs()

bool vacuum_get_cutoffs ( Relation  rel,
const VacuumParams params,
struct VacuumCutoffs cutoffs 
)

Definition at line 1104 of file vacuum.c.

1106{
1107 int freeze_min_age,
1108 multixact_freeze_min_age,
1109 freeze_table_age,
1110 multixact_freeze_table_age,
1111 effective_multixact_freeze_max_age;
1112 TransactionId nextXID,
1113 safeOldestXmin,
1114 aggressiveXIDCutoff;
1115 MultiXactId nextMXID,
1116 safeOldestMxact,
1117 aggressiveMXIDCutoff;
1118
1119 /* Use mutable copies of freeze age parameters */
1120 freeze_min_age = params->freeze_min_age;
1121 multixact_freeze_min_age = params->multixact_freeze_min_age;
1122 freeze_table_age = params->freeze_table_age;
1123 multixact_freeze_table_age = params->multixact_freeze_table_age;
1124
1125 /* Set pg_class fields in cutoffs */
1126 cutoffs->relfrozenxid = rel->rd_rel->relfrozenxid;
1127 cutoffs->relminmxid = rel->rd_rel->relminmxid;
1128
1129 /*
1130 * Acquire OldestXmin.
1131 *
1132 * We can always ignore processes running lazy vacuum. This is because we
1133 * use these values only for deciding which tuples we must keep in the
1134 * tables. Since lazy vacuum doesn't write its XID anywhere (usually no
1135 * XID assigned), it's safe to ignore it. In theory it could be
1136 * problematic to ignore lazy vacuums in a full vacuum, but keep in mind
1137 * that only one vacuum process can be working on a particular table at
1138 * any time, and that each vacuum is always an independent transaction.
1139 */
1141
1143
1144 /* Acquire OldestMxact */
1145 cutoffs->OldestMxact = GetOldestMultiXactId();
1147
1148 /* Acquire next XID/next MXID values used to apply age-based settings */
1149 nextXID = ReadNextTransactionId();
1150 nextMXID = ReadNextMultiXactId();
1151
1152 /*
1153 * Also compute the multixact age for which freezing is urgent. This is
1154 * normally autovacuum_multixact_freeze_max_age, but may be less if we are
1155 * short of multixact member space.
1156 */
1157 effective_multixact_freeze_max_age = MultiXactMemberFreezeThreshold();
1158
1159 /*
1160 * Almost ready to set freeze output parameters; check if OldestXmin or
1161 * OldestMxact are held back to an unsafe degree before we start on that
1162 */
1163 safeOldestXmin = nextXID - autovacuum_freeze_max_age;
1164 if (!TransactionIdIsNormal(safeOldestXmin))
1165 safeOldestXmin = FirstNormalTransactionId;
1166 safeOldestMxact = nextMXID - effective_multixact_freeze_max_age;
1167 if (safeOldestMxact < FirstMultiXactId)
1168 safeOldestMxact = FirstMultiXactId;
1169 if (TransactionIdPrecedes(cutoffs->OldestXmin, safeOldestXmin))
1171 (errmsg("cutoff for removing and freezing tuples is far in the past"),
1172 errhint("Close open transactions soon to avoid wraparound problems.\n"
1173 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1174 if (MultiXactIdPrecedes(cutoffs->OldestMxact, safeOldestMxact))
1176 (errmsg("cutoff for freezing multixacts is far in the past"),
1177 errhint("Close open transactions soon to avoid wraparound problems.\n"
1178 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1179
1180 /*
1181 * Determine the minimum freeze age to use: as specified by the caller, or
1182 * vacuum_freeze_min_age, but in any case not more than half
1183 * autovacuum_freeze_max_age, so that autovacuums to prevent XID
1184 * wraparound won't occur too frequently.
1185 */
1186 if (freeze_min_age < 0)
1187 freeze_min_age = vacuum_freeze_min_age;
1188 freeze_min_age = Min(freeze_min_age, autovacuum_freeze_max_age / 2);
1189 Assert(freeze_min_age >= 0);
1190
1191 /* Compute FreezeLimit, being careful to generate a normal XID */
1192 cutoffs->FreezeLimit = nextXID - freeze_min_age;
1193 if (!TransactionIdIsNormal(cutoffs->FreezeLimit))
1195 /* FreezeLimit must always be <= OldestXmin */
1196 if (TransactionIdPrecedes(cutoffs->OldestXmin, cutoffs->FreezeLimit))
1197 cutoffs->FreezeLimit = cutoffs->OldestXmin;
1198
1199 /*
1200 * Determine the minimum multixact freeze age to use: as specified by
1201 * caller, or vacuum_multixact_freeze_min_age, but in any case not more
1202 * than half effective_multixact_freeze_max_age, so that autovacuums to
1203 * prevent MultiXact wraparound won't occur too frequently.
1204 */
1205 if (multixact_freeze_min_age < 0)
1206 multixact_freeze_min_age = vacuum_multixact_freeze_min_age;
1207 multixact_freeze_min_age = Min(multixact_freeze_min_age,
1208 effective_multixact_freeze_max_age / 2);
1209 Assert(multixact_freeze_min_age >= 0);
1210
1211 /* Compute MultiXactCutoff, being careful to generate a valid value */
1212 cutoffs->MultiXactCutoff = nextMXID - multixact_freeze_min_age;
1213 if (cutoffs->MultiXactCutoff < FirstMultiXactId)
1215 /* MultiXactCutoff must always be <= OldestMxact */
1216 if (MultiXactIdPrecedes(cutoffs->OldestMxact, cutoffs->MultiXactCutoff))
1217 cutoffs->MultiXactCutoff = cutoffs->OldestMxact;
1218
1219 /*
1220 * Finally, figure out if caller needs to do an aggressive VACUUM or not.
1221 *
1222 * Determine the table freeze age to use: as specified by the caller, or
1223 * the value of the vacuum_freeze_table_age GUC, but in any case not more
1224 * than autovacuum_freeze_max_age * 0.95, so that if you have e.g nightly
1225 * VACUUM schedule, the nightly VACUUM gets a chance to freeze XIDs before
1226 * anti-wraparound autovacuum is launched.
1227 */
1228 if (freeze_table_age < 0)
1229 freeze_table_age = vacuum_freeze_table_age;
1230 freeze_table_age = Min(freeze_table_age, autovacuum_freeze_max_age * 0.95);
1231 Assert(freeze_table_age >= 0);
1232 aggressiveXIDCutoff = nextXID - freeze_table_age;
1233 if (!TransactionIdIsNormal(aggressiveXIDCutoff))
1234 aggressiveXIDCutoff = FirstNormalTransactionId;
1236 aggressiveXIDCutoff))
1237 return true;
1238
1239 /*
1240 * Similar to the above, determine the table freeze age to use for
1241 * multixacts: as specified by the caller, or the value of the
1242 * vacuum_multixact_freeze_table_age GUC, but in any case not more than
1243 * effective_multixact_freeze_max_age * 0.95, so that if you have e.g.
1244 * nightly VACUUM schedule, the nightly VACUUM gets a chance to freeze
1245 * multixacts before anti-wraparound autovacuum is launched.
1246 */
1247 if (multixact_freeze_table_age < 0)
1248 multixact_freeze_table_age = vacuum_multixact_freeze_table_age;
1249 multixact_freeze_table_age =
1250 Min(multixact_freeze_table_age,
1251 effective_multixact_freeze_max_age * 0.95);
1252 Assert(multixact_freeze_table_age >= 0);
1253 aggressiveMXIDCutoff = nextMXID - multixact_freeze_table_age;
1254 if (aggressiveMXIDCutoff < FirstMultiXactId)
1255 aggressiveMXIDCutoff = FirstMultiXactId;
1257 aggressiveMXIDCutoff))
1258 return true;
1259
1260 /* Non-aggressive VACUUM */
1261 return false;
1262}
int autovacuum_freeze_max_age
Definition: autovacuum.c:130
#define Min(x, y)
Definition: c.h:975
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3331
int MultiXactMemberFreezeThreshold(void)
Definition: multixact.c:2978
#define FirstMultiXactId
Definition: multixact.h:25
TransactionId FreezeLimit
Definition: vacuum.h:284
TransactionId OldestXmin
Definition: vacuum.h:274
TransactionId relfrozenxid
Definition: vacuum.h:258
MultiXactId relminmxid
Definition: vacuum.h:259
MultiXactId MultiXactCutoff
Definition: vacuum.h:285
MultiXactId OldestMxact
Definition: vacuum.h:275
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:299
#define FirstNormalTransactionId
Definition: transam.h:34
int vacuum_freeze_min_age
Definition: vacuum.c:73
int vacuum_multixact_freeze_table_age
Definition: vacuum.c:76
int vacuum_freeze_table_age
Definition: vacuum.c:74
int vacuum_multixact_freeze_min_age
Definition: vacuum.c:75

References Assert(), autovacuum_freeze_max_age, ereport, errhint(), errmsg(), FirstMultiXactId, FirstNormalTransactionId, VacuumParams::freeze_min_age, VacuumParams::freeze_table_age, VacuumCutoffs::FreezeLimit, GetOldestMultiXactId(), GetOldestNonRemovableTransactionId(), Min, VacuumParams::multixact_freeze_min_age, VacuumParams::multixact_freeze_table_age, VacuumCutoffs::MultiXactCutoff, MultiXactIdIsValid, MultiXactIdPrecedes(), MultiXactIdPrecedesOrEquals(), MultiXactMemberFreezeThreshold(), VacuumCutoffs::OldestMxact, VacuumCutoffs::OldestXmin, RelationData::rd_rel, ReadNextMultiXactId(), ReadNextTransactionId(), VacuumCutoffs::relfrozenxid, VacuumCutoffs::relminmxid, TransactionIdIsNormal, TransactionIdPrecedes(), TransactionIdPrecedesOrEquals(), vacuum_freeze_min_age, vacuum_freeze_table_age, vacuum_multixact_freeze_min_age, vacuum_multixact_freeze_table_age, and WARNING.

Referenced by copy_table_data(), and heap_vacuum_rel().

◆ vacuum_is_permitted_for_relation()

bool vacuum_is_permitted_for_relation ( Oid  relid,
Form_pg_class  reltuple,
bits32  options 
)

Definition at line 723 of file vacuum.c.

725{
726 char *relname;
727
729
730 /*----------
731 * A role has privileges to vacuum or analyze the relation if any of the
732 * following are true:
733 * - the role owns the current database and the relation is not shared
734 * - the role has the MAINTAIN privilege on the relation
735 *----------
736 */
737 if ((object_ownercheck(DatabaseRelationId, MyDatabaseId, GetUserId()) &&
738 !reltuple->relisshared) ||
740 return true;
741
742 relname = NameStr(reltuple->relname);
743
744 if ((options & VACOPT_VACUUM) != 0)
745 {
747 (errmsg("permission denied to vacuum \"%s\", skipping it",
748 relname)));
749
750 /*
751 * For VACUUM ANALYZE, both logs could show up, but just generate
752 * information for VACUUM as that would be the first one to be
753 * processed.
754 */
755 return false;
756 }
757
758 if ((options & VACOPT_ANALYZE) != 0)
760 (errmsg("permission denied to analyze \"%s\", skipping it",
761 relname)));
762
763 return false;
764}
@ ACLCHECK_OK
Definition: acl.h:183
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4075
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4024
Oid GetUserId(void)
Definition: miscinit.c:520
#define ACL_MAINTAIN
Definition: parsenodes.h:90
NameData relname
Definition: pg_class.h:38

References ACL_MAINTAIN, ACLCHECK_OK, Assert(), ereport, errmsg(), GetUserId(), MyDatabaseId, NameStr, object_ownercheck(), pg_class_aclcheck(), relname, VACOPT_ANALYZE, VACOPT_VACUUM, and WARNING.

Referenced by analyze_rel(), expand_vacuum_rel(), get_all_vacuum_rels(), and vacuum_rel().

◆ vacuum_open_relation()

Relation vacuum_open_relation ( Oid  relid,
RangeVar relation,
bits32  options,
bool  verbose,
LOCKMODE  lmode 
)

Definition at line 775 of file vacuum.c.

777{
778 Relation rel;
779 bool rel_lock = true;
780 int elevel;
781
783
784 /*
785 * Open the relation and get the appropriate lock on it.
786 *
787 * There's a race condition here: the relation may have gone away since
788 * the last time we saw it. If so, we don't need to vacuum or analyze it.
789 *
790 * If we've been asked not to wait for the relation lock, acquire it first
791 * in non-blocking mode, before calling try_relation_open().
792 */
794 rel = try_relation_open(relid, lmode);
795 else if (ConditionalLockRelationOid(relid, lmode))
796 rel = try_relation_open(relid, NoLock);
797 else
798 {
799 rel = NULL;
800 rel_lock = false;
801 }
802
803 /* if relation is opened, leave */
804 if (rel)
805 return rel;
806
807 /*
808 * Relation could not be opened, hence generate if possible a log
809 * informing on the situation.
810 *
811 * If the RangeVar is not defined, we do not have enough information to
812 * provide a meaningful log statement. Chances are that the caller has
813 * intentionally not provided this information so that this logging is
814 * skipped, anyway.
815 */
816 if (relation == NULL)
817 return NULL;
818
819 /*
820 * Determine the log level.
821 *
822 * For manual VACUUM or ANALYZE, we emit a WARNING to match the log
823 * statements in the permission checks; otherwise, only log if the caller
824 * so requested.
825 */
827 elevel = WARNING;
828 else if (verbose)
829 elevel = LOG;
830 else
831 return NULL;
832
833 if ((options & VACOPT_VACUUM) != 0)
834 {
835 if (!rel_lock)
836 ereport(elevel,
837 (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
838 errmsg("skipping vacuum of \"%s\" --- lock not available",
839 relation->relname)));
840 else
841 ereport(elevel,
843 errmsg("skipping vacuum of \"%s\" --- relation no longer exists",
844 relation->relname)));
845
846 /*
847 * For VACUUM ANALYZE, both logs could show up, but just generate
848 * information for VACUUM as that would be the first one to be
849 * processed.
850 */
851 return NULL;
852 }
853
854 if ((options & VACOPT_ANALYZE) != 0)
855 {
856 if (!rel_lock)
857 ereport(elevel,
858 (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
859 errmsg("skipping analyze of \"%s\" --- lock not available",
860 relation->relname)));
861 else
862 ereport(elevel,
864 errmsg("skipping analyze of \"%s\" --- relation no longer exists",
865 relation->relname)));
866 }
867
868 return NULL;
869}
#define LOG
Definition: elog.h:31
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:151
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:79
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:88

References AmAutoVacuumWorkerProcess, Assert(), ConditionalLockRelationOid(), ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), LOG, NoLock, RangeVar::relname, try_relation_open(), VACOPT_ANALYZE, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, verbose, and WARNING.

Referenced by analyze_rel(), and vacuum_rel().

◆ vacuum_rel()

static bool vacuum_rel ( Oid  relid,
RangeVar relation,
VacuumParams params,
BufferAccessStrategy  bstrategy 
)
static

Definition at line 2000 of file vacuum.c.

2002{
2003 LOCKMODE lmode;
2004 Relation rel;
2005 LockRelId lockrelid;
2006 Oid priv_relid;
2007 Oid toast_relid;
2008 Oid save_userid;
2009 int save_sec_context;
2010 int save_nestlevel;
2011
2012 Assert(params != NULL);
2013
2014 /* Begin a transaction for vacuuming this relation */
2016
2017 if (!(params->options & VACOPT_FULL))
2018 {
2019 /*
2020 * In lazy vacuum, we can set the PROC_IN_VACUUM flag, which lets
2021 * other concurrent VACUUMs know that they can ignore this one while
2022 * determining their OldestXmin. (The reason we don't set it during a
2023 * full VACUUM is exactly that we may have to run user-defined
2024 * functions for functional indexes, and we want to make sure that if
2025 * they use the snapshot set above, any tuples it requires can't get
2026 * removed from other tables. An index function that depends on the
2027 * contents of other tables is arguably broken, but we won't break it
2028 * here by violating transaction semantics.)
2029 *
2030 * We also set the VACUUM_FOR_WRAPAROUND flag, which is passed down by
2031 * autovacuum; it's used to avoid canceling a vacuum that was invoked
2032 * in an emergency.
2033 *
2034 * Note: these flags remain set until CommitTransaction or
2035 * AbortTransaction. We don't want to clear them until we reset
2036 * MyProc->xid/xmin, otherwise GetOldestNonRemovableTransactionId()
2037 * might appear to go backwards, which is probably Not Good. (We also
2038 * set PROC_IN_VACUUM *before* taking our own snapshot, so that our
2039 * xmin doesn't become visible ahead of setting the flag.)
2040 */
2041 LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
2043 if (params->is_wraparound)
2046 LWLockRelease(ProcArrayLock);
2047 }
2048
2049 /*
2050 * Need to acquire a snapshot to prevent pg_subtrans from being truncated,
2051 * cutoff xids in local memory wrapping around, and to have updated xmin
2052 * horizons.
2053 */
2055
2056 /*
2057 * Check for user-requested abort. Note we want this to be inside a
2058 * transaction, so xact.c doesn't issue useless WARNING.
2059 */
2061
2062 /*
2063 * Determine the type of lock we want --- hard exclusive lock for a FULL
2064 * vacuum, but just ShareUpdateExclusiveLock for concurrent vacuum. Either
2065 * way, we can be sure that no other backend is vacuuming the same table.
2066 */
2067 lmode = (params->options & VACOPT_FULL) ?
2069
2070 /* open the relation and get the appropriate lock on it */
2071 rel = vacuum_open_relation(relid, relation, params->options,
2072 params->log_min_duration >= 0, lmode);
2073
2074 /* leave if relation could not be opened or locked */
2075 if (!rel)
2076 {
2079 return false;
2080 }
2081
2082 /*
2083 * When recursing to a TOAST table, check privileges on the parent. NB:
2084 * This is only safe to do because we hold a session lock on the main
2085 * relation that prevents concurrent deletion.
2086 */
2087 if (OidIsValid(params->toast_parent))
2088 priv_relid = params->toast_parent;
2089 else
2090 priv_relid = RelationGetRelid(rel);
2091
2092 /*
2093 * Check if relation needs to be skipped based on privileges. This check
2094 * happens also when building the relation list to vacuum for a manual
2095 * operation, and needs to be done additionally here as VACUUM could
2096 * happen across multiple transactions where privileges could have changed
2097 * in-between. Make sure to only generate logs for VACUUM in this case.
2098 */
2099 if (!vacuum_is_permitted_for_relation(priv_relid,
2100 rel->rd_rel,
2101 params->options & ~VACOPT_ANALYZE))
2102 {
2103 relation_close(rel, lmode);
2106 return false;
2107 }
2108
2109 /*
2110 * Check that it's of a vacuumable relkind.
2111 */
2112 if (rel->rd_rel->relkind != RELKIND_RELATION &&
2113 rel->rd_rel->relkind != RELKIND_MATVIEW &&
2114 rel->rd_rel->relkind != RELKIND_TOASTVALUE &&
2115 rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2116 {
2118 (errmsg("skipping \"%s\" --- cannot vacuum non-tables or special system tables",
2120 relation_close(rel, lmode);
2123 return false;
2124 }
2125
2126 /*
2127 * Silently ignore tables that are temp tables of other backends ---
2128 * trying to vacuum these will lead to great unhappiness, since their
2129 * contents are probably not up-to-date on disk. (We don't throw a
2130 * warning here; it would just lead to chatter during a database-wide
2131 * VACUUM.)
2132 */
2133 if (RELATION_IS_OTHER_TEMP(rel))
2134 {
2135 relation_close(rel, lmode);
2138 return false;
2139 }
2140
2141 /*
2142 * Silently ignore partitioned tables as there is no work to be done. The
2143 * useful work is on their child partitions, which have been queued up for
2144 * us separately.
2145 */
2146 if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2147 {
2148 relation_close(rel, lmode);
2151 /* It's OK to proceed with ANALYZE on this table */
2152 return true;
2153 }
2154
2155 /*
2156 * Get a session-level lock too. This will protect our access to the
2157 * relation across multiple transactions, so that we can vacuum the
2158 * relation's TOAST table (if any) secure in the knowledge that no one is
2159 * deleting the parent relation.
2160 *
2161 * NOTE: this cannot block, even if someone else is waiting for access,
2162 * because the lock manager knows that both lock requests are from the
2163 * same process.
2164 */
2165 lockrelid = rel->rd_lockInfo.lockRelId;
2166 LockRelationIdForSession(&lockrelid, lmode);
2167
2168 /*
2169 * Set index_cleanup option based on index_cleanup reloption if it wasn't
2170 * specified in VACUUM command, or when running in an autovacuum worker
2171 */
2173 {
2174 StdRdOptIndexCleanup vacuum_index_cleanup;
2175
2176 if (rel->rd_options == NULL)
2177 vacuum_index_cleanup = STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO;
2178 else
2179 vacuum_index_cleanup =
2180 ((StdRdOptions *) rel->rd_options)->vacuum_index_cleanup;
2181
2182 if (vacuum_index_cleanup == STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO)
2184 else if (vacuum_index_cleanup == STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON)
2186 else
2187 {
2188 Assert(vacuum_index_cleanup ==
2191 }
2192 }
2193
2194 /*
2195 * Check if the vacuum_max_eager_freeze_failure_rate table storage
2196 * parameter was specified. This overrides the GUC value.
2197 */
2198 if (rel->rd_options != NULL &&
2199 ((StdRdOptions *) rel->rd_options)->vacuum_max_eager_freeze_failure_rate >= 0)
2201 ((StdRdOptions *) rel->rd_options)->vacuum_max_eager_freeze_failure_rate;
2202
2203 /*
2204 * Set truncate option based on truncate reloption or GUC if it wasn't
2205 * specified in VACUUM command, or when running in an autovacuum worker
2206 */
2207 if (params->truncate == VACOPTVALUE_UNSPECIFIED)
2208 {
2210
2211 if (opts && opts->vacuum_truncate_set)
2212 {
2213 if (opts->vacuum_truncate)
2214 params->truncate = VACOPTVALUE_ENABLED;
2215 else
2217 }
2218 else if (vacuum_truncate)
2219 params->truncate = VACOPTVALUE_ENABLED;
2220 else
2222 }
2223
2224 /*
2225 * Remember the relation's TOAST relation for later, if the caller asked
2226 * us to process it. In VACUUM FULL, though, the toast table is
2227 * automatically rebuilt by cluster_rel so we shouldn't recurse to it,
2228 * unless PROCESS_MAIN is disabled.
2229 */
2230 if ((params->options & VACOPT_PROCESS_TOAST) != 0 &&
2231 ((params->options & VACOPT_FULL) == 0 ||
2232 (params->options & VACOPT_PROCESS_MAIN) == 0))
2233 toast_relid = rel->rd_rel->reltoastrelid;
2234 else
2235 toast_relid = InvalidOid;
2236
2237 /*
2238 * Switch to the table owner's userid, so that any index functions are run
2239 * as that user. Also lock down security-restricted operations and
2240 * arrange to make GUC variable changes local to this command. (This is
2241 * unnecessary, but harmless, for lazy VACUUM.)
2242 */
2243 GetUserIdAndSecContext(&save_userid, &save_sec_context);
2244 SetUserIdAndSecContext(rel->rd_rel->relowner,
2245 save_sec_context | SECURITY_RESTRICTED_OPERATION);
2246 save_nestlevel = NewGUCNestLevel();
2248
2249 /*
2250 * If PROCESS_MAIN is set (the default), it's time to vacuum the main
2251 * relation. Otherwise, we can skip this part. If processing the TOAST
2252 * table is required (e.g., PROCESS_TOAST is set), we force PROCESS_MAIN
2253 * to be set when we recurse to the TOAST table.
2254 */
2255 if (params->options & VACOPT_PROCESS_MAIN)
2256 {
2257 /*
2258 * Do the actual work --- either FULL or "lazy" vacuum
2259 */
2260 if (params->options & VACOPT_FULL)
2261 {
2262 ClusterParams cluster_params = {0};
2263
2264 if ((params->options & VACOPT_VERBOSE) != 0)
2265 cluster_params.options |= CLUOPT_VERBOSE;
2266
2267 /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */
2268 cluster_rel(rel, InvalidOid, &cluster_params);
2269 /* cluster_rel closes the relation, but keeps lock */
2270
2271 rel = NULL;
2272 }
2273 else
2274 table_relation_vacuum(rel, params, bstrategy);
2275 }
2276
2277 /* Roll back any GUC changes executed by index functions */
2278 AtEOXact_GUC(false, save_nestlevel);
2279
2280 /* Restore userid and security context */
2281 SetUserIdAndSecContext(save_userid, save_sec_context);
2282
2283 /* all done with this class, but hold lock until commit */
2284 if (rel)
2285 relation_close(rel, NoLock);
2286
2287 /*
2288 * Complete the transaction and free all temporary memory used.
2289 */
2292
2293 /*
2294 * If the relation has a secondary toast rel, vacuum that too while we
2295 * still hold the session lock on the main table. Note however that
2296 * "analyze" will not get done on the toast table. This is good, because
2297 * the toaster always uses hardcoded index access and statistics are
2298 * totally unimportant for toast relations.
2299 */
2300 if (toast_relid != InvalidOid)
2301 {
2302 VacuumParams toast_vacuum_params;
2303
2304 /*
2305 * Force VACOPT_PROCESS_MAIN so vacuum_rel() processes it. Likewise,
2306 * set toast_parent so that the privilege checks are done on the main
2307 * relation. NB: This is only safe to do because we hold a session
2308 * lock on the main relation that prevents concurrent deletion.
2309 */
2310 memcpy(&toast_vacuum_params, params, sizeof(VacuumParams));
2311 toast_vacuum_params.options |= VACOPT_PROCESS_MAIN;
2312 toast_vacuum_params.toast_parent = relid;
2313
2314 vacuum_rel(toast_relid, NULL, &toast_vacuum_params, bstrategy);
2315 }
2316
2317 /*
2318 * Now release the session-level lock on the main table.
2319 */
2320 UnlockRelationIdForSession(&lockrelid, lmode);
2321
2322 /* Report that we really did it. */
2323 return true;
2324}
void cluster_rel(Relation OldHeap, Oid indexOid, ClusterParams *params)
Definition: cluster.c:311
#define CLUOPT_VERBOSE
Definition: cluster.h:23
int NewGUCNestLevel(void)
Definition: guc.c:2235
void RestrictSearchPath(void)
Definition: guc.c:2246
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2262
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:391
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:404
int LOCKMODE
Definition: lockdefs.h:26
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define SECURITY_RESTRICTED_OPERATION
Definition: miscadmin.h:319
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:663
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:670
static AmcheckOptions opts
Definition: pg_amcheck.c:112
#define PROC_IN_VACUUM
Definition: proc.h:58
#define PROC_VACUUM_FOR_WRAPAROUND
Definition: proc.h:60
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:669
StdRdOptIndexCleanup
Definition: rel.h:334
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO
Definition: rel.h:335
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF
Definition: rel.h:336
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON
Definition: rel.h:337
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
PGPROC * MyProc
Definition: proc.c:67
PROC_HDR * ProcGlobal
Definition: proc.c:79
bits32 options
Definition: cluster.h:30
LockRelId lockRelId
Definition: rel.h:46
Definition: rel.h:39
uint8 statusFlags
Definition: proc.h:243
int pgxactoff
Definition: proc.h:185
uint8 * statusFlags
Definition: proc.h:387
LockInfoData rd_lockInfo
Definition: rel.h:114
bytea * rd_options
Definition: rel.h:175
static void table_relation_vacuum(Relation rel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:1667
Relation vacuum_open_relation(Oid relid, RangeVar *relation, bits32 options, bool verbose, LOCKMODE lmode)
Definition: vacuum.c:775
bool vacuum_truncate
Definition: vacuum.c:81

References AccessExclusiveLock, Assert(), AtEOXact_GUC(), CHECK_FOR_INTERRUPTS, CLUOPT_VERBOSE, cluster_rel(), CommitTransactionCommand(), ereport, errmsg(), GetTransactionSnapshot(), GetUserIdAndSecContext(), if(), VacuumParams::index_cleanup, InvalidOid, VacuumParams::is_wraparound, LockRelationIdForSession(), LockInfoData::lockRelId, VacuumParams::log_min_duration, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VacuumParams::max_eager_freeze_failure_rate, MyProc, NewGUCNestLevel(), NoLock, OidIsValid, ClusterParams::options, VacuumParams::options, opts, PGPROC::pgxactoff, PopActiveSnapshot(), PROC_IN_VACUUM, PROC_VACUUM_FOR_WRAPAROUND, ProcGlobal, PushActiveSnapshot(), RelationData::rd_lockInfo, RelationData::rd_options, RelationData::rd_rel, relation_close(), RELATION_IS_OTHER_TEMP, RelationGetRelationName, RelationGetRelid, RestrictSearchPath(), SECURITY_RESTRICTED_OPERATION, SetUserIdAndSecContext(), ShareUpdateExclusiveLock, StartTransactionCommand(), PGPROC::statusFlags, PROC_HDR::statusFlags, STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO, STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF, STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON, table_relation_vacuum(), VacuumParams::toast_parent, VacuumParams::truncate, UnlockRelationIdForSession(), VACOPT_ANALYZE, VACOPT_FULL, VACOPT_PROCESS_MAIN, VACOPT_PROCESS_TOAST, VACOPT_VERBOSE, VACOPTVALUE_AUTO, VACOPTVALUE_DISABLED, VACOPTVALUE_ENABLED, VACOPTVALUE_UNSPECIFIED, vacuum_is_permitted_for_relation(), vacuum_open_relation(), vacuum_rel(), vacuum_truncate, and WARNING.

Referenced by vacuum(), and vacuum_rel().

◆ vacuum_xid_failsafe_check()

bool vacuum_xid_failsafe_check ( const struct VacuumCutoffs cutoffs)

Definition at line 1272 of file vacuum.c.

1273{
1274 TransactionId relfrozenxid = cutoffs->relfrozenxid;
1275 MultiXactId relminmxid = cutoffs->relminmxid;
1276 TransactionId xid_skip_limit;
1277 MultiXactId multi_skip_limit;
1278 int skip_index_vacuum;
1279
1280 Assert(TransactionIdIsNormal(relfrozenxid));
1281 Assert(MultiXactIdIsValid(relminmxid));
1282
1283 /*
1284 * Determine the index skipping age to use. In any case no less than
1285 * autovacuum_freeze_max_age * 1.05.
1286 */
1287 skip_index_vacuum = Max(vacuum_failsafe_age, autovacuum_freeze_max_age * 1.05);
1288
1289 xid_skip_limit = ReadNextTransactionId() - skip_index_vacuum;
1290 if (!TransactionIdIsNormal(xid_skip_limit))
1291 xid_skip_limit = FirstNormalTransactionId;
1292
1293 if (TransactionIdPrecedes(relfrozenxid, xid_skip_limit))
1294 {
1295 /* The table's relfrozenxid is too old */
1296 return true;
1297 }
1298
1299 /*
1300 * Similar to above, determine the index skipping age to use for
1301 * multixact. In any case no less than autovacuum_multixact_freeze_max_age *
1302 * 1.05.
1303 */
1304 skip_index_vacuum = Max(vacuum_multixact_failsafe_age,
1306
1307 multi_skip_limit = ReadNextMultiXactId() - skip_index_vacuum;
1308 if (multi_skip_limit < FirstMultiXactId)
1309 multi_skip_limit = FirstMultiXactId;
1310
1311 if (MultiXactIdPrecedes(relminmxid, multi_skip_limit))
1312 {
1313 /* The table's relminmxid is too old */
1314 return true;
1315 }
1316
1317 return false;
1318}
int autovacuum_multixact_freeze_max_age
Definition: autovacuum.c:131
#define Max(x, y)
Definition: c.h:969
int vacuum_multixact_failsafe_age
Definition: vacuum.c:78
int vacuum_failsafe_age
Definition: vacuum.c:77

References Assert(), autovacuum_freeze_max_age, autovacuum_multixact_freeze_max_age, FirstMultiXactId, FirstNormalTransactionId, Max, MultiXactIdIsValid, MultiXactIdPrecedes(), ReadNextMultiXactId(), ReadNextTransactionId(), VacuumCutoffs::relfrozenxid, VacuumCutoffs::relminmxid, TransactionIdIsNormal, TransactionIdPrecedes(), vacuum_failsafe_age, and vacuum_multixact_failsafe_age.

Referenced by lazy_check_wraparound_failsafe().

Variable Documentation

◆ parallel_vacuum_worker_delay_ns

int64 parallel_vacuum_worker_delay_ns = 0

Definition at line 93 of file vacuum.c.

Referenced by parallel_vacuum_main(), and vacuum_delay_point().

◆ track_cost_delay_timing

bool track_cost_delay_timing

Definition at line 80 of file vacuum.c.

Referenced by do_analyze_rel(), heap_vacuum_rel(), parallel_vacuum_main(), and vacuum_delay_point().

◆ vacuum_cost_delay

double vacuum_cost_delay = 0

◆ vacuum_cost_limit

int vacuum_cost_limit = 200

◆ vacuum_failsafe_age

int vacuum_failsafe_age

Definition at line 77 of file vacuum.c.

Referenced by vacuum_xid_failsafe_check().

◆ vacuum_freeze_min_age

int vacuum_freeze_min_age

Definition at line 73 of file vacuum.c.

Referenced by do_autovacuum(), and vacuum_get_cutoffs().

◆ vacuum_freeze_table_age

int vacuum_freeze_table_age

Definition at line 74 of file vacuum.c.

Referenced by do_autovacuum(), and vacuum_get_cutoffs().

◆ vacuum_max_eager_freeze_failure_rate

double vacuum_max_eager_freeze_failure_rate

Definition at line 79 of file vacuum.c.

Referenced by default_reloptions(), ExecVacuum(), and table_recheck_autovac().

◆ vacuum_multixact_failsafe_age

int vacuum_multixact_failsafe_age

Definition at line 78 of file vacuum.c.

Referenced by vacuum_xid_failsafe_check().

◆ vacuum_multixact_freeze_min_age

int vacuum_multixact_freeze_min_age

Definition at line 75 of file vacuum.c.

Referenced by do_autovacuum(), and vacuum_get_cutoffs().

◆ vacuum_multixact_freeze_table_age

int vacuum_multixact_freeze_table_age

Definition at line 76 of file vacuum.c.

Referenced by do_autovacuum(), and vacuum_get_cutoffs().

◆ vacuum_truncate

bool vacuum_truncate

Definition at line 81 of file vacuum.c.

Referenced by default_reloptions(), and vacuum_rel().

◆ VacuumActiveNWorkers

◆ VacuumCostBalanceLocal

int VacuumCostBalanceLocal = 0

◆ VacuumFailsafeActive

◆ VacuumSharedCostBalance

pg_atomic_uint32* VacuumSharedCostBalance = NULL