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/pg_database.h"
#include "catalog/pg_inherits.h"
#include "catalog/pg_namespace.h"
#include "commands/cluster.h"
#include "commands/defrem.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/proc.h"
#include "storage/procarray.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Go to the source code of this file.
Functions | |
static List * | expand_vacuum_rel (VacuumRelation *vrel, int options) |
static List * | get_all_vacuum_rels (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) |
static double | compute_parallel_delay (void) |
static VacOptTernaryValue | get_vacopt_ternary_value (DefElem *def) |
void | ExecVacuum (ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel) |
void | vacuum (List *relations, VacuumParams *params, BufferAccessStrategy bstrategy, bool isTopLevel) |
bool | vacuum_is_relation_owner (Oid relid, Form_pg_class reltuple, bits32 options) |
Relation | vacuum_open_relation (Oid relid, RangeVar *relation, bits32 options, bool verbose, LOCKMODE lmode) |
void | vacuum_set_xid_limits (Relation rel, int freeze_min_age, int freeze_table_age, int multixact_freeze_min_age, int multixact_freeze_table_age, TransactionId *oldestXmin, TransactionId *freezeLimit, TransactionId *xidFullScanLimit, MultiXactId *multiXactCutoff, MultiXactId *mxactFullScanLimit) |
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, bool hasindex, TransactionId frozenxid, MultiXactId minmulti, 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 (void) |
Variables | |
int | vacuum_freeze_min_age |
int | vacuum_freeze_table_age |
int | vacuum_multixact_freeze_min_age |
int | vacuum_multixact_freeze_table_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 2120 of file vacuum.c.
References Assert, pg_atomic_add_fetch_u32(), pg_atomic_read_u32(), pg_atomic_sub_fetch_u32(), VacuumCostBalance, VacuumCostBalanceLocal, VacuumCostDelay, and VacuumCostLimit.
Referenced by vacuum_delay_point().
void ExecVacuum | ( | ParseState * | pstate, |
VacuumStmt * | vacstmt, | ||
bool | isTopLevel | ||
) |
Definition at line 98 of file vacuum.c.
References analyze(), DefElem::arg, Assert, defGetBoolean(), defGetInt32(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, VacuumParams::freeze_min_age, VacuumParams::freeze_table_age, get_vacopt_ternary_value(), 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(), VacuumStmt::rels, VacuumParams::truncate, VacuumRelation::va_cols, VACOPT_ANALYZE, VACOPT_DISABLE_PAGE_SKIPPING, VACOPT_FREEZE, VACOPT_FULL, VACOPT_PROCESS_TOAST, VACOPT_SKIP_LOCKED, VACOPT_TERNARY_DEFAULT, VACOPT_VACUUM, VACOPT_VERBOSE, vacuum(), and verbose.
Referenced by standard_ProcessUtility().
|
static |
Definition at line 729 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, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, vacuum_is_relation_owner(), and WARNING.
Referenced by vacuum().
|
static |
Definition at line 868 of file vacuum.c.
References AccessShareLock, ForwardScanDirection, GETSTRUCT, heap_getnext(), lappend(), makeVacuumRelation(), MemoryContextSwitchTo(), NIL, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), and vacuum_is_relation_owner().
Referenced by vacuum().
|
static |
Definition at line 2164 of file vacuum.c.
References defGetBoolean(), VACOPT_TERNARY_DISABLED, and VACOPT_TERNARY_ENABLED.
Referenced by ExecVacuum().
Definition at line 2037 of file vacuum.c.
References index_close(), and pfree().
Referenced by do_analyze_rel(), heap_vacuum_rel(), and parallel_vacuum_main().
double vac_estimate_reltuples | ( | Relation | relation, |
BlockNumber | total_pages, | ||
BlockNumber | scanned_pages, | ||
double | scanned_tuples | ||
) |
Definition at line 1151 of file vacuum.c.
References RelationData::rd_rel.
Referenced by lazy_scan_heap(), and statapprox_heap().
Definition at line 1994 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 1575 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 1361 of file vacuum.c.
References AccessShareLock, Assert, BTEqualStrategyNumber, DatabaseOidIndexId, 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 | in_outer_xact | ||
) |
Definition at line 1234 of file vacuum.c.
References elog, ERROR, GETSTRUCT, heap_inplace_update(), HeapTupleIsValid, MultiXactIdIsValid, MultiXactIdPrecedes(), ObjectIdGetDatum, RelationData::rd_rules, ReadNextMultiXactId(), ReadNextTransactionId(), RelationGetRelid, RELOID, RowExclusiveLock, SearchSysCacheCopy1, table_close(), table_open(), TransactionIdIsNormal, TransactionIdPrecedes(), and RelationData::trigdesc.
Referenced by do_analyze_rel(), heap_vacuum_rel(), and update_index_statistics().
void vacuum | ( | List * | relations, |
VacuumParams * | params, | ||
BufferAccessStrategy | bstrategy, | ||
bool | isTopLevel | ||
) |
Definition at line 275 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, pgstat_vacuum_stat(), PopActiveSnapshot(), PortalContext, PreventInTransactionBlock(), PushActiveSnapshot(), VacuumRelation::relation, StartTransactionCommand(), VacuumRelation::va_cols, vac_update_datfrozenxid(), VACOPT_ANALYZE, VACOPT_DISABLE_PAGE_SKIPPING, VACOPT_FULL, VACOPT_PROCESS_TOAST, VACOPT_VACUUM, vacuum_rel(), VacuumCostActive, VacuumCostBalance, VacuumCostBalanceLocal, VacuumCostDelay, VacuumPageDirty, VacuumPageHit, and VacuumPageMiss.
Referenced by autovacuum_do_vac_analyze(), and ExecVacuum().
void vacuum_delay_point | ( | void | ) |
Definition at line 2058 of file vacuum.c.
References AutoVacuumUpdateDelay(), CHECK_FOR_INTERRUPTS, compute_parallel_delay(), InterruptPending, pg_usleep(), pgstat_report_wait_end(), pgstat_report_wait_start(), VacuumCostActive, VacuumCostBalance, VacuumCostDelay, VacuumCostLimit, 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_vacuum_heap(), spgprocesspending(), and spgvacuumpage().
bool vacuum_is_relation_owner | ( | Oid | relid, |
Form_pg_class | reltuple, | ||
bits32 | options | ||
) |
Definition at line 543 of file vacuum.c.
References Assert, ereport, errmsg(), GetUserId(), MyDatabaseId, NameStr, pg_class_ownercheck(), pg_database_ownercheck(), 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 617 of file vacuum.c.
References Assert, ConditionalLockRelationOid(), elevel, ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), IsAutoVacuumWorkerProcess(), LOG, NoLock, RangeVar::relname, try_relation_open(), VACOPT_ANALYZE, VACOPT_SKIP_LOCKED, VACOPT_VACUUM, and WARNING.
Referenced by analyze_rel(), and vacuum_rel().
|
static |
Definition at line 1726 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, table_relation_vacuum(), VacuumParams::truncate, UnlockRelationIdForSession(), VACOPT_FULL, VACOPT_PROCESS_TOAST, VACOPT_TERNARY_DEFAULT, VACOPT_TERNARY_DISABLED, VACOPT_TERNARY_ENABLED, VACOPT_VACUUM, VACOPT_VERBOSE, vacuum_is_relation_owner(), vacuum_open_relation(), and WARNING.
Referenced by vacuum().
void vacuum_set_xid_limits | ( | Relation | rel, |
int | freeze_min_age, | ||
int | freeze_table_age, | ||
int | multixact_freeze_min_age, | ||
int | multixact_freeze_table_age, | ||
TransactionId * | oldestXmin, | ||
TransactionId * | freezeLimit, | ||
TransactionId * | xidFullScanLimit, | ||
MultiXactId * | multiXactCutoff, | ||
MultiXactId * | mxactFullScanLimit | ||
) |
Definition at line 941 of file vacuum.c.
References Assert, autovacuum_freeze_max_age, ereport, errhint(), errmsg(), FirstMultiXactId, FirstNormalTransactionId, GetOldestMultiXactId(), GetOldestNonRemovableTransactionId(), Min, MultiXactIdPrecedes(), MultiXactMemberFreezeThreshold(), OldSnapshotThresholdActive(), ReadNextMultiXactId(), ReadNextTransactionId(), SetOldSnapshotThresholdTimestamp(), TransactionIdIsNormal, TransactionIdLimitedForOldSnapshots(), TransactionIdPrecedes(), 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().
|
static |
|
static |
int vacuum_freeze_min_age |
Definition at line 61 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_set_xid_limits().
int vacuum_freeze_table_age |
Definition at line 62 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_set_xid_limits().
int vacuum_multixact_freeze_min_age |
Definition at line 63 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_set_xid_limits().
int vacuum_multixact_freeze_table_age |
Definition at line 64 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_set_xid_limits().
pg_atomic_uint32* VacuumActiveNWorkers = NULL |
Definition at line 77 of file vacuum.c.
Referenced by lazy_parallel_vacuum_indexes(), parallel_vacuum_index(), parallel_vacuum_main(), and vacuum_indexes_leader().
int VacuumCostBalanceLocal = 0 |
Definition at line 78 of file vacuum.c.
Referenced by compute_parallel_delay(), lazy_parallel_vacuum_indexes(), parallel_vacuum_main(), and vacuum().
pg_atomic_uint32* VacuumSharedCostBalance = NULL |
Definition at line 76 of file vacuum.c.
Referenced by lazy_parallel_vacuum_indexes(), and parallel_vacuum_main().