#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
+#include "utils/hsearch.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "utils/builtins.h"
+#include "utils/hsearch.h"
#include "utils/tuplestore.h"
PG_MODULE_MAGIC_EXT(
/* non-export function prototypes */
static void lazy_scan_heap(LVRelState *vacrel);
static void heap_vacuum_eager_scan_setup(LVRelState *vacrel,
- const VacuumParams params);
+ const VacuumParams *params);
static BlockNumber heap_vac_scan_next_block(ReadStream *stream,
void *callback_private_data,
void *per_buffer_data);
* vacuum options or for relfrozenxid/relminmxid advancement.
*/
static void
-heap_vacuum_eager_scan_setup(LVRelState *vacrel, const VacuumParams params)
+heap_vacuum_eager_scan_setup(LVRelState *vacrel, const VacuumParams *params)
{
uint32 randseed;
BlockNumber allvisible;
vacrel->eager_scan_remaining_successes = 0;
/* If eager scanning is explicitly disabled, just return. */
- if (params.max_eager_freeze_failure_rate == 0)
+ if (params->max_eager_freeze_failure_rate == 0)
return;
/*
vacrel->next_eager_scan_region_start = randseed % EAGER_SCAN_REGION_SIZE;
- Assert(params.max_eager_freeze_failure_rate > 0 &&
- params.max_eager_freeze_failure_rate <= 1);
+ Assert(params->max_eager_freeze_failure_rate > 0 &&
+ params->max_eager_freeze_failure_rate <= 1);
vacrel->eager_scan_max_fails_per_region =
- params.max_eager_freeze_failure_rate *
+ params->max_eager_freeze_failure_rate *
EAGER_SCAN_REGION_SIZE;
/*
* and locked the relation.
*/
void
-heap_vacuum_rel(Relation rel, const VacuumParams params,
+heap_vacuum_rel(Relation rel, const VacuumParams *params,
BufferAccessStrategy bstrategy)
{
LVRelState *vacrel;
char **indnames = NULL;
Size dead_items_max_bytes = 0;
- verbose = (params.options & VACOPT_VERBOSE) != 0;
+ verbose = (params->options & VACOPT_VERBOSE) != 0;
instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
- params.log_vacuum_min_duration >= 0));
+ params->log_vacuum_min_duration >= 0));
if (instrument)
{
pg_rusage_init(&ru0);
RelationGetRelid(rel));
if (AmAutoVacuumWorkerProcess())
pgstat_progress_update_param(PROGRESS_VACUUM_STARTED_BY,
- params.is_wraparound
+ params->is_wraparound
? PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM_WRAPAROUND
: PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM);
else
* The truncate param allows user to avoid attempting relation truncation,
* though it can't force truncation to happen.
*/
- Assert(params.index_cleanup != VACOPTVALUE_UNSPECIFIED);
- Assert(params.truncate != VACOPTVALUE_UNSPECIFIED &&
- params.truncate != VACOPTVALUE_AUTO);
+ Assert(params->index_cleanup != VACOPTVALUE_UNSPECIFIED);
+ Assert(params->truncate != VACOPTVALUE_UNSPECIFIED &&
+ params->truncate != VACOPTVALUE_AUTO);
/*
* While VacuumFailSafeActive is reset to false before calling this, we
vacrel->consider_bypass_optimization = true;
vacrel->do_index_vacuuming = true;
vacrel->do_index_cleanup = true;
- vacrel->do_rel_truncate = (params.truncate != VACOPTVALUE_DISABLED);
- if (params.index_cleanup == VACOPTVALUE_DISABLED)
+ vacrel->do_rel_truncate = (params->truncate != VACOPTVALUE_DISABLED);
+ if (params->index_cleanup == VACOPTVALUE_DISABLED)
{
/* Force disable index vacuuming up-front */
vacrel->do_index_vacuuming = false;
vacrel->do_index_cleanup = false;
}
- else if (params.index_cleanup == VACOPTVALUE_ENABLED)
+ else if (params->index_cleanup == VACOPTVALUE_ENABLED)
{
/* Force index vacuuming. Note that failsafe can still bypass. */
vacrel->consider_bypass_optimization = false;
else
{
/* Default/auto, make all decisions dynamically */
- Assert(params.index_cleanup == VACOPTVALUE_AUTO);
+ Assert(params->index_cleanup == VACOPTVALUE_AUTO);
}
/* Initialize page counters explicitly (be tidy) */
*/
vacrel->skippedallvis = false;
skipwithvm = true;
- if (params.options & VACOPT_DISABLE_PAGE_SKIPPING)
+ if (params->options & VACOPT_DISABLE_PAGE_SKIPPING)
{
/*
* Force aggressive mode, and disable skipping blocks using the
* is already dangerously old.)
*/
lazy_check_wraparound_failsafe(vacrel);
- dead_items_alloc(vacrel, params.nworkers);
+ dead_items_alloc(vacrel, params->nworkers);
/*
* Call lazy_scan_heap to perform all required heap pruning, index
{
TimestampTz endtime = GetCurrentTimestamp();
- if (verbose || params.log_vacuum_min_duration == 0 ||
+ if (verbose || params->log_vacuum_min_duration == 0 ||
TimestampDifferenceExceeds(starttime, endtime,
- params.log_vacuum_min_duration))
+ params->log_vacuum_min_duration))
{
long secs_dur;
int usecs_dur;
* Aggressiveness already reported earlier, in dedicated
* VACUUM VERBOSE ereport
*/
- Assert(!params.is_wraparound);
+ Assert(!params->is_wraparound);
msgfmt = _("finished vacuuming \"%s.%s.%s\": index scans: %d\n");
}
- else if (params.is_wraparound)
+ else if (params->is_wraparound)
{
/*
* While it's possible for a VACUUM to be both is_wraparound
*/
#include "postgres.h"
+#include "access/genam.h"
#include "access/heapam.h"
#include "access/toast_compression.h"
#include "access/xact.h"
static void do_analyze_rel(Relation onerel,
- const VacuumParams params, List *va_cols,
+ const VacuumParams *params, List *va_cols,
AcquireSampleRowsFunc acquirefunc, BlockNumber relpages,
bool inh, bool in_outer_xact, int elevel);
static void compute_index_stats(Relation onerel, double totalrows,
*/
void
analyze_rel(Oid relid, RangeVar *relation,
- const VacuumParams params, List *va_cols, bool in_outer_xact,
+ const VacuumParams *params, List *va_cols, bool in_outer_xact,
BufferAccessStrategy bstrategy)
{
Relation onerel;
BlockNumber relpages = 0;
/* Select logging level */
- if (params.options & VACOPT_VERBOSE)
+ if (params->options & VACOPT_VERBOSE)
elevel = INFO;
else
elevel = DEBUG2;
*
* Make sure to generate only logs for ANALYZE in this case.
*/
- onerel = vacuum_open_relation(relid, relation, params.options & ~(VACOPT_VACUUM),
- params.log_analyze_min_duration >= 0,
+ onerel = vacuum_open_relation(relid, relation, params->options & ~(VACOPT_VACUUM),
+ params->log_analyze_min_duration >= 0,
ShareUpdateExclusiveLock);
/* leave if relation could not be opened or locked */
*/
if (!vacuum_is_permitted_for_relation(RelationGetRelid(onerel),
onerel->rd_rel,
- params.options & ~VACOPT_VACUUM))
+ params->options & ~VACOPT_VACUUM))
{
relation_close(onerel, ShareUpdateExclusiveLock);
return;
else
{
/* No need for a WARNING if we already complained during VACUUM */
- if (!(params.options & VACOPT_VACUUM))
+ if (!(params->options & VACOPT_VACUUM))
ereport(WARNING,
(errmsg("skipping \"%s\" --- cannot analyze non-tables or special system tables",
RelationGetRelationName(onerel))));
* appropriate acquirefunc for each child table.
*/
static void
-do_analyze_rel(Relation onerel, const VacuumParams params,
+do_analyze_rel(Relation onerel, const VacuumParams *params,
List *va_cols, AcquireSampleRowsFunc acquirefunc,
BlockNumber relpages, bool inh, bool in_outer_xact,
int elevel)
PgStat_Counter startreadtime = 0;
PgStat_Counter startwritetime = 0;
- verbose = (params.options & VACOPT_VERBOSE) != 0;
+ verbose = (params->options & VACOPT_VERBOSE) != 0;
instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
- params.log_analyze_min_duration >= 0));
+ params->log_analyze_min_duration >= 0));
if (inh)
ereport(elevel,
(errmsg("analyzing \"%s.%s\" inheritance tree",
* amvacuumcleanup() when called in ANALYZE-only mode. The only exception
* among core index AMs is GIN/ginvacuumcleanup().
*/
- if (!(params.options & VACOPT_VACUUM))
+ if (!(params->options & VACOPT_VACUUM))
{
for (ind = 0; ind < nindexes; ind++)
{
{
TimestampTz endtime = GetCurrentTimestamp();
- if (verbose || params.log_analyze_min_duration == 0 ||
+ if (verbose || params->log_analyze_min_duration == 0 ||
TimestampDifferenceExceeds(starttime, endtime,
- params.log_analyze_min_duration))
+ params->log_analyze_min_duration))
{
long delay_in_ms;
WalUsage walusage;
* not to be aggressive about this.
*/
memset(¶ms, 0, sizeof(VacuumParams));
- vacuum_get_cutoffs(OldHeap, params, &cutoffs);
+ vacuum_get_cutoffs(OldHeap, ¶ms, &cutoffs);
/*
* FreezeXid will become the table's new relfrozenxid, and that mustn't go
vac_params.options |= VACOPT_ANALYZE;
if (params->options & CLUOPT_VERBOSE)
vac_params.options |= VACOPT_VERBOSE;
- analyze_rel(tableOid, NULL, vac_params,
+ analyze_rel(tableOid, NULL, &vac_params,
stmt->relation->va_cols, true, NULL);
PopActiveSnapshot();
CommandCounterIncrement();
*/
#include "postgres.h"
+#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/table.h"
}
/* Now go through the common routine */
- vacuum(vacstmt->rels, params, bstrategy, vac_context, isTopLevel);
+ vacuum(vacstmt->rels, ¶ms, bstrategy, vac_context, isTopLevel);
/* Finally, clean up the vacuum memory context */
MemoryContextDelete(vac_context);
* memory context that will not disappear at transaction commit.
*/
void
-vacuum(List *relations, const VacuumParams params, BufferAccessStrategy bstrategy,
+vacuum(List *relations, const VacuumParams *params, BufferAccessStrategy bstrategy,
MemoryContext vac_context, bool isTopLevel)
{
static bool in_vacuum = false;
volatile bool in_outer_xact,
use_own_xacts;
- stmttype = (params.options & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE";
+ stmttype = (params->options & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE";
/*
* We cannot run VACUUM inside a user transaction block; if we were inside
*
* ANALYZE (without VACUUM) can run either way.
*/
- if (params.options & VACOPT_VACUUM)
+ if (params->options & VACOPT_VACUUM)
{
PreventInTransactionBlock(isTopLevel, stmttype);
in_outer_xact = false;
* Build list of relation(s) to process, putting any new data in
* vac_context for safekeeping.
*/
- if (params.options & VACOPT_ONLY_DATABASE_STATS)
+ if (params->options & VACOPT_ONLY_DATABASE_STATS)
{
/* We don't process any tables in this case */
Assert(relations == NIL);
List *sublist;
MemoryContext old_context;
- sublist = expand_vacuum_rel(vrel, vac_context, params.options);
+ sublist = expand_vacuum_rel(vrel, vac_context, params->options);
old_context = MemoryContextSwitchTo(vac_context);
newrels = list_concat(newrels, sublist);
MemoryContextSwitchTo(old_context);
relations = newrels;
}
else
- relations = get_all_vacuum_rels(vac_context, params.options);
+ relations = get_all_vacuum_rels(vac_context, params->options);
/*
* Decide whether we need to start/commit our own transactions.
* transaction block, and also in an autovacuum worker, use own
* transactions so we can release locks sooner.
*/
- if (params.options & VACOPT_VACUUM)
+ if (params->options & VACOPT_VACUUM)
use_own_xacts = true;
else
{
- Assert(params.options & VACOPT_ANALYZE);
+ Assert(params->options & VACOPT_ANALYZE);
if (AmAutoVacuumWorkerProcess())
use_own_xacts = true;
else if (in_outer_xact)
{
VacuumRelation *vrel = lfirst_node(VacuumRelation, cur);
- if (params.options & VACOPT_VACUUM)
+ if (params->options & VACOPT_VACUUM)
{
- if (!vacuum_rel(vrel->oid, vrel->relation, params, bstrategy))
+ if (!vacuum_rel(vrel->oid, vrel->relation, *params, bstrategy))
continue;
}
- if (params.options & VACOPT_ANALYZE)
+ if (params->options & VACOPT_ANALYZE)
{
/*
* If using separate xacts, start one for analyze. Otherwise,
StartTransactionCommand();
}
- if ((params.options & VACOPT_VACUUM) &&
- !(params.options & VACOPT_SKIP_DATABASE_STATS))
+ if ((params->options & VACOPT_VACUUM) &&
+ !(params->options & VACOPT_SKIP_DATABASE_STATS))
{
/*
* Update pg_database.datfrozenxid, and truncate pg_xact if possible.
* minimum).
*/
bool
-vacuum_get_cutoffs(Relation rel, const VacuumParams params,
+vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
struct VacuumCutoffs *cutoffs)
{
int freeze_min_age,
aggressiveMXIDCutoff;
/* Use mutable copies of freeze age parameters */
- freeze_min_age = params.freeze_min_age;
- multixact_freeze_min_age = params.multixact_freeze_min_age;
- freeze_table_age = params.freeze_table_age;
- multixact_freeze_table_age = params.multixact_freeze_table_age;
+ freeze_min_age = params->freeze_min_age;
+ multixact_freeze_min_age = params->multixact_freeze_min_age;
+ freeze_table_age = params->freeze_table_age;
+ multixact_freeze_table_age = params->multixact_freeze_table_age;
/* Set pg_class fields in cutoffs */
cutoffs->relfrozenxid = rel->rd_rel->relfrozenxid;
rel = NULL;
}
else
- table_relation_vacuum(rel, params, bstrategy);
+ table_relation_vacuum(rel, ¶ms, bstrategy);
}
/* Roll back any GUC changes executed by index functions */
rel_list = list_make1(rel);
MemoryContextSwitchTo(old_context);
- vacuum(rel_list, tab->at_params, bstrategy, vac_context, true);
+ vacuum(rel_list, &tab->at_params, bstrategy, vac_context, true);
MemoryContextDelete(vac_context);
}
#include "postgres.h"
#include "access/commit_ts.h"
+#include "access/genam.h"
#include "access/tableam.h"
#include "executor/executor.h"
#include "pgstat.h"
#include <sys/stat.h>
#include <unistd.h>
+#include "access/genam.h"
#include "access/commit_ts.h"
#include "access/table.h"
#include "access/tableam.h"
#include "postgres.h"
+#include "access/genam.h"
#include "access/htup_details.h"
#include "access/skey.h"
#include "access/sysattr.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
+#include "utils/hsearch.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "access/skey.h"
#include "access/table.h" /* for backward compatibility */
#include "access/tableam.h"
-#include "commands/vacuum.h"
#include "nodes/lockoptions.h"
#include "nodes/primnodes.h"
#include "storage/bufpage.h"
typedef struct BulkInsertStateData *BulkInsertState;
typedef struct GlobalVisState GlobalVisState;
typedef struct TupleTableSlot TupleTableSlot;
-struct VacuumCutoffs;
+typedef struct VacuumCutoffs VacuumCutoffs;
+typedef struct VacuumParams VacuumParams;
#define MaxLockTupleMode LockTupleExclusive
* HEAPTUPLE_DEAD. Currently only vacuum passes in cutoffs. Vacuum
* calculates them once, at the beginning of vacuuming the relation.
*/
- struct VacuumCutoffs *cutoffs;
+ VacuumCutoffs *cutoffs;
} PruneFreezeParams;
/*
extern void heap_inplace_unlock(Relation relation,
HeapTuple oldtup, Buffer buffer);
extern bool heap_prepare_freeze_tuple(HeapTupleHeader tuple,
- const struct VacuumCutoffs *cutoffs,
+ const VacuumCutoffs *cutoffs,
HeapPageFreeze *pagefrz,
HeapTupleFreeze *frz, bool *totally_frozen);
TransactionId relfrozenxid, TransactionId relminmxid,
TransactionId FreezeLimit, TransactionId MultiXactCutoff);
extern bool heap_tuple_should_freeze(HeapTupleHeader tuple,
- const struct VacuumCutoffs *cutoffs,
+ const VacuumCutoffs *cutoffs,
TransactionId *NoFreezePageRelfrozenXid,
MultiXactId *NoFreezePageRelminMxid);
extern bool heap_tuple_needs_eventual_freeze(HeapTupleHeader tuple);
/* in heap/vacuumlazy.c */
extern void heap_vacuum_rel(Relation rel,
- const VacuumParams params, BufferAccessStrategy bstrategy);
+ const VacuumParams *params, BufferAccessStrategy bstrategy);
#ifdef USE_ASSERT_CHECKING
extern bool heap_page_is_all_visible(Relation rel, Buffer buf,
GlobalVisState *vistest,
#include "access/relscan.h"
#include "access/sdir.h"
#include "access/xact.h"
-#include "commands/vacuum.h"
#include "executor/tuptable.h"
#include "storage/read_stream.h"
#include "utils/rel.h"
typedef struct BulkInsertStateData BulkInsertStateData;
typedef struct IndexInfo IndexInfo;
typedef struct SampleScanState SampleScanState;
+typedef struct ScanKeyData ScanKeyData;
typedef struct ValidateIndexState ValidateIndexState;
+typedef struct VacuumParams VacuumParams;
/*
* Bitmask values for the flags argument to the scan_begin callback.
* integrate with autovacuum's scheduling.
*/
void (*relation_vacuum) (Relation rel,
- const VacuumParams params,
+ const VacuumParams *params,
BufferAccessStrategy bstrategy);
/*
* routine, even if (for ANALYZE) it is part of the same VACUUM command.
*/
static inline void
-table_relation_vacuum(Relation rel, const VacuumParams params,
+table_relation_vacuum(Relation rel, const VacuumParams *params,
BufferAccessStrategy bstrategy)
{
rel->rd_tableam->relation_vacuum(rel, params, bstrategy);
/* in commands/vacuum.c */
extern void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel);
-extern void vacuum(List *relations, const VacuumParams params,
+extern void vacuum(List *relations, const VacuumParams *params,
BufferAccessStrategy bstrategy, MemoryContext vac_context,
bool isTopLevel);
extern void vac_open_indexes(Relation relation, LOCKMODE lockmode,
bool *frozenxid_updated,
bool *minmulti_updated,
bool in_outer_xact);
-extern bool vacuum_get_cutoffs(Relation rel, const VacuumParams params,
+extern bool vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
struct VacuumCutoffs *cutoffs);
extern bool vacuum_xid_failsafe_check(const struct VacuumCutoffs *cutoffs);
extern void vac_update_datfrozenxid(void);
/* in commands/analyze.c */
extern void analyze_rel(Oid relid, RangeVar *relation,
- const VacuumParams params, List *va_cols, bool in_outer_xact,
+ const VacuumParams *params, List *va_cols, bool in_outer_xact,
BufferAccessStrategy bstrategy);
extern bool std_typanalyze(VacAttrStats *stats);
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/guc.h"
+#include "utils/hsearch.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
VacDeadItemsInfo
VacErrPhase
VacOptValue
+VacuumCutoffs
VacuumParams
VacuumRelation
VacuumStmt