PostgreSQL Source Code
git master
|
#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/index.h"
#include "catalog/pg_database.h"
#include "catalog/pg_inherits.h"
#include "catalog/pg_namespace.h"
#include "commands/cluster.h"
#include "commands/defrem.h"
#include "commands/tablecmds.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 "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/memutils.h"
#include "utils/pg_rusage.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Go to the source code of this file.
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 |
static MemoryContext | vac_context = NULL |
static BufferAccessStrategy | vac_strategy |
pg_atomic_uint32 * | VacuumSharedCostBalance = NULL |
pg_atomic_uint32 * | VacuumActiveNWorkers = NULL |
int | VacuumCostBalanceLocal = 0 |
|
static |
Definition at line 2282 of file vacuum.c.
References Assert(), pg_atomic_add_fetch_u32(), pg_atomic_read_u32(), pg_atomic_sub_fetch_u32(), VacuumActiveNWorkers, VacuumCostBalance, VacuumCostBalanceLocal, VacuumCostDelay, VacuumCostLimit, and VacuumSharedCostBalance.
Referenced by vacuum_delay_point().
void ExecVacuum | ( | ParseState * | pstate, |
VacuumStmt * | vacstmt, | ||
bool | isTopLevel | ||
) |
Definition at line 110 of file vacuum.c.
References analyze(), DefElem::arg, Assert(), defGetBoolean(), defGetInt32(), defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, VacuumParams::freeze_min_age, VacuumParams::freeze_table_age, get_vacoptval_from_boolean(), VacuumParams::index_cleanup, VacuumStmt::is_vacuumcmd, VacuumParams::is_wraparound, lfirst, lfirst_node, DefElem::location, VacuumParams::log_min_duration, MAX_PARALLEL_WORKER_LIMIT, VacuumParams::multixact_freeze_min_age, VacuumParams::multixact_freeze_table_age, NIL, VacuumParams::nworkers, VacuumParams::options, VacuumStmt::options, parser_errposition(), pg_strcasecmp(), VacuumStmt::rels, 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(), and verbose.
Referenced by standard_ProcessUtility().
|
static |
Definition at line 763 of file vacuum.c.
References AccessShareLock, Assert(), elog(), ereport, errcode(), errmsg(), ERROR, find_all_inheritors(), GETSTRUCT, HeapTupleIsValid, IsAutoVacuumWorkerProcess(), lappend(), lfirst_oid, makeVacuumRelation(), MemoryContextSwitchTo(), NIL, NoLock, ObjectIdGetDatum(), VacuumRelation::oid, OidIsValid, RangeVarGetRelidExtended(), VacuumRelation::relation, ReleaseSysCache(), RangeVar::relname, RELOID, RVR_SKIP_LOCKED, SearchSysCache1(), UnlockRelationOid(), VacuumRelation::va_cols, vac_context, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, vacuum_is_permitted_for_relation(), and WARNING.
Referenced by vacuum().
|
static |
Definition at line 902 of file vacuum.c.
References AccessShareLock, ForwardScanDirection, GETSTRUCT, heap_getnext(), lappend(), makeVacuumRelation(), MemoryContextSwitchTo(), NIL, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), vac_context, and vacuum_is_permitted_for_relation().
Referenced by vacuum().
|
static |
Definition at line 2326 of file vacuum.c.
References defGetBoolean(), VACOPTVALUE_DISABLED, and VACOPTVALUE_ENABLED.
Referenced by ExecVacuum().
IndexBulkDeleteResult* vac_bulkdel_one_index | ( | IndexVacuumInfo * | ivinfo, |
IndexBulkDeleteResult * | istat, | ||
VacDeadItems * | dead_items | ||
) |
Definition at line 2337 of file vacuum.c.
References ereport, errmsg(), IndexVacuumInfo::index, index_bulk_delete(), IndexVacuumInfo::message_level, VacDeadItems::num_items, RelationGetRelationName, and vac_tid_reaped().
Referenced by lazy_vacuum_one_index(), and parallel_vacuum_process_one_index().
IndexBulkDeleteResult* vac_cleanup_one_index | ( | IndexVacuumInfo * | ivinfo, |
IndexBulkDeleteResult * | istat | ||
) |
Definition at line 2358 of file vacuum.c.
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().
Definition at line 2190 of file vacuum.c.
References index_close(), and pfree().
Referenced by do_analyze_rel(), heap_vacuum_rel(), and parallel_vacuum_main().
|
static |
Definition at line 2432 of file vacuum.c.
References ItemPointerGetBlockNumber(), and ItemPointerGetOffsetNumber().
Referenced by vac_tid_reaped().
double vac_estimate_reltuples | ( | Relation | relation, |
BlockNumber | total_pages, | ||
BlockNumber | scanned_pages, | ||
double | scanned_tuples | ||
) |
Definition at line 1213 of file vacuum.c.
References RelationData::rd_rel.
Referenced by lazy_scan_heap(), and statapprox_heap().
Size vac_max_items_to_alloc_size | ( | int | max_items | ) |
Definition at line 2383 of file vacuum.c.
References Assert(), MaxAllocSize, and MAXDEADITEMS.
Referenced by dead_items_alloc(), and parallel_vacuum_init().
Definition at line 2147 of file vacuum.c.
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().
|
static |
Definition at line 2398 of file vacuum.c.
References itemptr_encode(), VacDeadItems::items, VacDeadItems::num_items, res, and vac_cmp_itemptr().
Referenced by vac_bulkdel_one_index().
|
static |
Definition at line 1690 of file vacuum.c.
References AccessShareLock, AdvanceOldestCommitTsXid(), Assert(), datfrozenxid, datminmxid, ereport, errdetail(), errmsg(), FormData_pg_database, ForwardScanDirection, GETSTRUCT, heap_getnext(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MultiXactIdIsValid, MultiXactIdPrecedes(), MyDatabaseId, ReadNextTransactionId(), SetMultiXactIdLimit(), SetTransactionIdLimit(), table_beginscan_catalog(), table_close(), table_endscan(), table_open(), TransactionIdIsNormal, TransactionIdPrecedes(), TruncateCLOG(), TruncateCommitTs(), TruncateMultiXact(), and WARNING.
Referenced by vac_update_datfrozenxid().
void vac_update_datfrozenxid | ( | void | ) |
Definition at line 1476 of file vacuum.c.
References AccessShareLock, Assert(), BTEqualStrategyNumber, elog(), ERROR, ExclusiveLock, ForceTransactionIdLimitUpdate(), GetOldestMultiXactId(), GetOldestNonRemovableTransactionId(), GETSTRUCT, heap_copytuple(), heap_freetuple(), heap_inplace_update(), HeapTupleIsValid, InvalidOid, sort-test::key, LockDatabaseFrozenIds(), MultiXactIdIsValid, MultiXactIdPrecedes(), MyDatabaseId, ObjectIdGetDatum(), ReadNextMultiXactId(), ReadNextTransactionId(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), and vac_truncate_clog().
Referenced by do_autovacuum(), and vacuum().
void vac_update_relstats | ( | Relation | relation, |
BlockNumber | num_pages, | ||
double | num_tuples, | ||
BlockNumber | num_all_visible_pages, | ||
bool | hasindex, | ||
TransactionId | frozenxid, | ||
MultiXactId | minmulti, | ||
bool * | frozenxid_updated, | ||
bool * | minmulti_updated, | ||
bool | in_outer_xact | ||
) |
Definition at line 1309 of file vacuum.c.
References elog(), ereport, errcode(), ERRCODE_DATA_CORRUPTED, errmsg_internal(), ERROR, GETSTRUCT, heap_inplace_update(), HeapTupleIsValid, MultiXactIdIsValid, MultiXactIdPrecedes(), ObjectIdGetDatum(), RelationData::rd_rules, ReadNextMultiXactId(), ReadNextTransactionId(), RelationGetRelationName, RelationGetRelid, RELOID, RowExclusiveLock, SearchSysCacheCopy1, table_close(), table_open(), TransactionIdIsNormal, TransactionIdPrecedes(), RelationData::trigdesc, and WARNING.
Referenced by do_analyze_rel(), heap_vacuum_rel(), and update_relstats_all_indexes().
void vacuum | ( | List * | relations, |
VacuumParams * | params, | ||
BufferAccessStrategy | bstrategy, | ||
bool | isTopLevel | ||
) |
Definition at line 311 of file vacuum.c.
References ActiveSnapshotSet(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, analyze_rel(), Assert(), BAS_VACUUM, CommandCounterIncrement(), CommitTransactionCommand(), cur, ereport, errcode(), errmsg(), ERROR, expand_vacuum_rel(), get_all_vacuum_rels(), GetAccessStrategy(), GetTransactionSnapshot(), IsAutoVacuumWorkerProcess(), IsInTransactionBlock(), lfirst_node, list_concat(), list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), NIL, VacuumRelation::oid, VacuumParams::options, PG_END_TRY, PG_FINALLY, PG_TRY, PopActiveSnapshot(), PortalContext, PreventInTransactionBlock(), PushActiveSnapshot(), VacuumRelation::relation, StartTransactionCommand(), VacuumRelation::va_cols, vac_context, vac_strategy, vac_update_datfrozenxid(), VACOPT_ANALYZE, VACOPT_DISABLE_PAGE_SKIPPING, VACOPT_FULL, VACOPT_ONLY_DATABASE_STATS, VACOPT_PROCESS_MAIN, VACOPT_PROCESS_TOAST, VACOPT_SKIP_DATABASE_STATS, VACOPT_VACUUM, VACOPT_VERBOSE, vacuum_rel(), VacuumActiveNWorkers, VacuumCostActive, VacuumCostBalance, VacuumCostBalanceLocal, VacuumCostDelay, VacuumPageDirty, VacuumPageHit, VacuumPageMiss, and VacuumSharedCostBalance.
Referenced by autovacuum_do_vac_analyze(), ExecVacuum(), parallel_vacuum_index_is_parallel_safe(), and parallel_vacuum_process_all_indexes().
void vacuum_delay_point | ( | void | ) |
Definition at line 2211 of file vacuum.c.
References AutoVacuumUpdateDelay(), CHECK_FOR_INTERRUPTS, compute_parallel_delay(), exit(), InterruptPending, IsUnderPostmaster, pg_usleep(), pgstat_report_wait_end(), pgstat_report_wait_start(), PostmasterIsAlive, VacuumCostActive, VacuumCostBalance, VacuumCostDelay, VacuumCostLimit, VacuumSharedCostBalance, and WAIT_EVENT_VACUUM_DELAY.
Referenced by acquire_sample_rows(), blbulkdelete(), blvacuumcleanup(), btvacuumpage(), 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(), hashbucketcleanup(), lazy_scan_heap(), lazy_scan_skip(), lazy_vacuum_heap_rel(), spgprocesspending(), and spgvacuumpage().
bool vacuum_get_cutoffs | ( | Relation | rel, |
const VacuumParams * | params, | ||
struct VacuumCutoffs * | cutoffs | ||
) |
Definition at line 964 of file vacuum.c.
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, OldSnapshotThresholdActive(), RelationData::rd_rel, ReadNextMultiXactId(), ReadNextTransactionId(), VacuumCutoffs::relfrozenxid, VacuumCutoffs::relminmxid, SetOldSnapshotThresholdTimestamp(), TransactionIdIsNormal, TransactionIdLimitedForOldSnapshots(), 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().
bool vacuum_is_permitted_for_relation | ( | Oid | relid, |
Form_pg_class | reltuple, | ||
bits32 | options | ||
) |
Definition at line 595 of file vacuum.c.
References ACL_MAINTAIN, ACLCHECK_OK, Assert(), ereport, errmsg(), GetUserId(), has_partition_ancestor_privs(), 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().
Relation vacuum_open_relation | ( | Oid | relid, |
RangeVar * | relation, | ||
bits32 | options, | ||
bool | verbose, | ||
LOCKMODE | lmode | ||
) |
Definition at line 651 of file vacuum.c.
References Assert(), ConditionalLockRelationOid(), ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), IsAutoVacuumWorkerProcess(), LOG, NoLock, RangeVar::relname, try_relation_open(), VACOPT_ANALYZE, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, verbose, and WARNING.
Referenced by analyze_rel(), and vacuum_rel().
|
static |
Definition at line 1841 of file vacuum.c.
References AccessExclusiveLock, Assert(), AtEOXact_GUC(), CHECK_FOR_INTERRUPTS, CLUOPT_VERBOSE, cluster_rel(), CommitTransactionCommand(), ereport, errmsg(), GetTransactionSnapshot(), GetUserIdAndSecContext(), VacuumParams::index_cleanup, InvalidOid, VacuumParams::is_wraparound, LockRelationIdForSession(), LockInfoData::lockRelId, VacuumParams::log_min_duration, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProc, NewGUCNestLevel(), NoLock, ClusterParams::options, VacuumParams::options, 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, 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::truncate, UnlockRelationIdForSession(), vac_strategy, VACOPT_FULL, VACOPT_PROCESS_MAIN, VACOPT_PROCESS_TOAST, VACOPT_VACUUM, VACOPT_VERBOSE, VACOPTVALUE_AUTO, VACOPTVALUE_DISABLED, VACOPTVALUE_ENABLED, VACOPTVALUE_UNSPECIFIED, vacuum_is_permitted_for_relation(), vacuum_open_relation(), and WARNING.
Referenced by vacuum().
bool vacuum_xid_failsafe_check | ( | const struct VacuumCutoffs * | cutoffs | ) |
Definition at line 1151 of file vacuum.c.
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().
|
static |
Definition at line 77 of file vacuum.c.
Referenced by expand_vacuum_rel(), get_all_vacuum_rels(), and vacuum().
|
static |
Definition at line 78 of file vacuum.c.
Referenced by vacuum(), and vacuum_rel().
int vacuum_failsafe_age |
Definition at line 72 of file vacuum.c.
Referenced by vacuum_xid_failsafe_check().
int vacuum_freeze_min_age |
Definition at line 68 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
int vacuum_freeze_table_age |
Definition at line 69 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
int vacuum_multixact_failsafe_age |
Definition at line 73 of file vacuum.c.
Referenced by vacuum_xid_failsafe_check().
int vacuum_multixact_freeze_min_age |
Definition at line 70 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
int vacuum_multixact_freeze_table_age |
Definition at line 71 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
pg_atomic_uint32* VacuumActiveNWorkers = NULL |
Definition at line 86 of file vacuum.c.
Referenced by compute_parallel_delay(), parallel_vacuum_main(), parallel_vacuum_process_all_indexes(), parallel_vacuum_process_safe_indexes(), parallel_vacuum_process_unsafe_indexes(), and vacuum().
int VacuumCostBalanceLocal = 0 |
Definition at line 87 of file vacuum.c.
Referenced by compute_parallel_delay(), parallel_vacuum_main(), parallel_vacuum_process_all_indexes(), and vacuum().
pg_atomic_uint32* VacuumSharedCostBalance = NULL |
Definition at line 85 of file vacuum.c.
Referenced by compute_parallel_delay(), parallel_vacuum_main(), parallel_vacuum_process_all_indexes(), vacuum(), and vacuum_delay_point().