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 "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 "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"
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 |
double | vacuum_cost_delay = 0 |
int | vacuum_cost_limit = 200 |
bool | VacuumFailsafeActive = false |
pg_atomic_uint32 * | VacuumSharedCostBalance = NULL |
pg_atomic_uint32 * | VacuumActiveNWorkers = NULL |
int | VacuumCostBalanceLocal = 0 |
bool check_vacuum_buffer_usage_limit | ( | int * | newval, |
void ** | extra, | ||
GucSource | source | ||
) |
Definition at line 124 of file vacuum.c.
References GUC_check_errdetail, MAX_BAS_VAC_RING_SIZE_KB, MIN_BAS_VAC_RING_SIZE_KB, and newval.
|
static |
Definition at line 2461 of file vacuum.c.
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().
void ExecVacuum | ( | ParseState * | pstate, |
VacuumStmt * | vacstmt, | ||
bool | isTopLevel | ||
) |
Definition at line 147 of file vacuum.c.
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, 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(), VacuumBufferUsageLimit, and verbose.
Referenced by standard_ProcessUtility().
|
static |
Definition at line 867 of file vacuum.c.
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().
|
static |
Definition at line 1022 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_permitted_for_relation().
Referenced by vacuum().
|
static |
Definition at line 2505 of file vacuum.c.
References defGetBoolean(), VACOPTVALUE_DISABLED, and VACOPTVALUE_ENABLED.
Referenced by ExecVacuum().
IndexBulkDeleteResult* vac_bulkdel_one_index | ( | IndexVacuumInfo * | ivinfo, |
IndexBulkDeleteResult * | istat, | ||
TidStore * | dead_items, | ||
VacDeadItemsInfo * | dead_items_info | ||
) |
Definition at line 2516 of file vacuum.c.
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().
IndexBulkDeleteResult* vac_cleanup_one_index | ( | IndexVacuumInfo * | ivinfo, |
IndexBulkDeleteResult * | istat | ||
) |
Definition at line 2537 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 2341 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 1314 of file vacuum.c.
References RelationData::rd_rel.
Referenced by lazy_scan_heap(), and statapprox_heap().
Definition at line 2298 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 2563 of file vacuum.c.
References TidStoreIsMember().
Referenced by vac_bulkdel_one_index().
|
static |
Definition at line 1805 of file vacuum.c.
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().
void vac_update_datfrozenxid | ( | void | ) |
Definition at line 1586 of file vacuum.c.
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().
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 1410 of file vacuum.c.
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().
void vacuum | ( | List * | relations, |
VacuumParams * | params, | ||
BufferAccessStrategy | bstrategy, | ||
MemoryContext | vac_context, | ||
bool | isTopLevel | ||
) |
Definition at line 478 of file vacuum.c.
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().
void vacuum_delay_point | ( | void | ) |
Definition at line 2362 of file vacuum.c.
References AmAutoVacuumWorkerProcess, AutoVacuumUpdateCostLimit(), CHECK_FOR_INTERRUPTS, compute_parallel_delay(), ConfigReloadPending, exit(), InterruptPending, IsUnderPostmaster, pg_usleep(), PGC_SIGHUP, pgstat_report_wait_end(), pgstat_report_wait_start(), PostmasterIsAlive, ProcessConfigFile(), vacuum_cost_delay, vacuum_cost_limit, VacuumCostActive, VacuumCostBalance, VacuumSharedCostBalance, and VacuumUpdateCosts().
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_rel(), spgprocesspending(), and spgvacuumpage().
bool vacuum_get_cutoffs | ( | Relation | rel, |
const VacuumParams * | params, | ||
struct VacuumCutoffs * | cutoffs | ||
) |
Definition at line 1084 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, 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().
bool vacuum_is_permitted_for_relation | ( | Oid | relid, |
Form_pg_class | reltuple, | ||
bits32 | options | ||
) |
Definition at line 703 of file vacuum.c.
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().
Relation vacuum_open_relation | ( | Oid | relid, |
RangeVar * | relation, | ||
bits32 | options, | ||
bool | verbose, | ||
LOCKMODE | lmode | ||
) |
Definition at line 755 of file vacuum.c.
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().
|
static |
Definition at line 1974 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, OidIsValid, 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, 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(), and WARNING.
Referenced by vacuum().
bool vacuum_xid_failsafe_check | ( | const struct VacuumCutoffs * | cutoffs | ) |
Definition at line 1252 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().
double vacuum_cost_delay = 0 |
Definition at line 79 of file vacuum.c.
Referenced by compute_parallel_delay(), default_reloptions(), vacuum_delay_point(), and VacuumUpdateCosts().
int vacuum_cost_limit = 200 |
Definition at line 80 of file vacuum.c.
Referenced by AutoVacuumUpdateCostLimit(), compute_parallel_delay(), default_reloptions(), vacuum_delay_point(), and VacuumUpdateCosts().
int vacuum_failsafe_age |
Definition at line 70 of file vacuum.c.
Referenced by vacuum_xid_failsafe_check().
int vacuum_freeze_min_age |
Definition at line 66 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
int vacuum_freeze_table_age |
Definition at line 67 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
int vacuum_multixact_failsafe_age |
Definition at line 71 of file vacuum.c.
Referenced by vacuum_xid_failsafe_check().
int vacuum_multixact_freeze_min_age |
Definition at line 68 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
int vacuum_multixact_freeze_table_age |
Definition at line 69 of file vacuum.c.
Referenced by do_autovacuum(), and vacuum_get_cutoffs().
pg_atomic_uint32* VacuumActiveNWorkers = NULL |
Definition at line 102 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 103 of file vacuum.c.
Referenced by compute_parallel_delay(), parallel_vacuum_main(), parallel_vacuum_process_all_indexes(), and vacuum().
bool VacuumFailsafeActive = false |
Definition at line 95 of file vacuum.c.
Referenced by heap_vacuum_rel(), lazy_check_wraparound_failsafe(), lazy_vacuum(), lazy_vacuum_all_indexes(), should_attempt_truncation(), vacuum(), and VacuumUpdateCosts().
pg_atomic_uint32* VacuumSharedCostBalance = NULL |
Definition at line 101 of file vacuum.c.
Referenced by compute_parallel_delay(), parallel_vacuum_main(), parallel_vacuum_process_all_indexes(), vacuum(), and vacuum_delay_point().