@ -74,8 +74,7 @@ static void vac_truncate_clog(TransactionId frozenXID,
MultiXactId minMulti ,
TransactionId lastSaneFrozenXid ,
MultiXactId lastSaneMinMulti ) ;
static bool vacuum_rel ( Oid relid , RangeVar * relation , int options ,
VacuumParams * params ) ;
static bool vacuum_rel ( Oid relid , RangeVar * relation , VacuumParams * params ) ;
/*
* Primary entry point for manual VACUUM and ANALYZE commands
@ -112,6 +111,9 @@ ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
}
}
/* copy options from parse tree */
params . options = vacstmt - > options ;
/*
* All freeze ages are zero if the FREEZE option is given ; otherwise pass
* them as - 1 which means to use the default values .
@ -138,14 +140,12 @@ ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
params . log_min_duration = - 1 ;
/* Now go through the common routine */
vacuum ( vacstmt - > options , vacstmt - > rels , & params , NULL , isTopLevel ) ;
vacuum ( vacstmt - > rels , & params , NULL , isTopLevel ) ;
}
/*
* Internal entry point for VACUUM and ANALYZE commands .
*
* options is a bitmask of VacuumOption flags , indicating what to do .
*
* relations , if not NIL , is a list of VacuumRelation to process ; otherwise ,
* we process all relevant tables in the database . For each VacuumRelation ,
* if a valid OID is supplied , the table with that OID is what to process ;
@ -163,7 +163,7 @@ ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
* memory context that will not disappear at transaction commit .
*/
void
vacuum ( int options , List * relations , VacuumParams * params ,
vacuum ( List * relations , VacuumParams * params ,
BufferAccessStrategy bstrategy , bool isTopLevel )
{
static bool in_vacuum = false ;
@ -174,7 +174,7 @@ vacuum(int options, List *relations, VacuumParams *params,
Assert ( params ! = NULL ) ;
stmttype = ( 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
@ -184,7 +184,7 @@ vacuum(int options, List *relations, VacuumParams *params,
*
* ANALYZE ( without VACUUM ) can run either way .
*/
if ( options & VACOPT_VACUUM )
if ( params - > options & VACOPT_VACUUM )
{
PreventInTransactionBlock ( isTopLevel , stmttype ) ;
in_outer_xact = false ;
@ -206,8 +206,8 @@ vacuum(int options, List *relations, VacuumParams *params,
/*
* Sanity check DISABLE_PAGE_SKIPPING option .
*/
if ( ( options & VACOPT_FULL ) ! = 0 & &
( options & VACOPT_DISABLE_PAGE_SKIPPING ) ! = 0 )
if ( ( params - > options & VACOPT_FULL ) ! = 0 & &
( params - > options & VACOPT_DISABLE_PAGE_SKIPPING ) ! = 0 )
ereport ( ERROR ,
( errcode ( ERRCODE_FEATURE_NOT_SUPPORTED ) ,
errmsg ( " VACUUM option DISABLE_PAGE_SKIPPING cannot be used with FULL " ) ) ) ;
@ -216,7 +216,7 @@ vacuum(int options, List *relations, VacuumParams *params,
* Send info about dead objects to the statistics collector , unless we are
* in autovacuum - - - autovacuum . c does this for itself .
*/
if ( ( options & VACOPT_VACUUM ) & & ! IsAutoVacuumWorkerProcess ( ) )
if ( ( params - > options & VACOPT_VACUUM ) & & ! IsAutoVacuumWorkerProcess ( ) )
pgstat_vacuum_stat ( ) ;
/*
@ -257,7 +257,7 @@ vacuum(int options, List *relations, VacuumParams *params,
List * sublist ;
MemoryContext old_context ;
sublist = expand_vacuum_rel ( vrel , options ) ;
sublist = expand_vacuum_rel ( vrel , params - > options ) ;
old_context = MemoryContextSwitchTo ( vac_context ) ;
newrels = list_concat ( newrels , sublist ) ;
MemoryContextSwitchTo ( old_context ) ;
@ -265,7 +265,7 @@ vacuum(int options, List *relations, VacuumParams *params,
relations = newrels ;
}
else
relations = get_all_vacuum_rels ( options ) ;
relations = get_all_vacuum_rels ( params - > options ) ;
/*
* Decide whether we need to start / commit our own transactions .
@ -281,11 +281,11 @@ vacuum(int options, List *relations, VacuumParams *params,
* transaction block , and also in an autovacuum worker , use own
* transactions so we can release locks sooner .
*/
if ( options & VACOPT_VACUUM )
if ( params - > options & VACOPT_VACUUM )
use_own_xacts = true ;
else
{
Assert ( options & VACOPT_ANALYZE ) ;
Assert ( params - > options & VACOPT_ANALYZE ) ;
if ( IsAutoVacuumWorkerProcess ( ) )
use_own_xacts = true ;
else if ( in_outer_xact )
@ -335,13 +335,13 @@ vacuum(int options, List *relations, VacuumParams *params,
{
VacuumRelation * vrel = lfirst_node ( VacuumRelation , cur ) ;
if ( options & VACOPT_VACUUM )
if ( params - > options & VACOPT_VACUUM )
{
if ( ! vacuum_rel ( vrel - > oid , vrel - > relation , options , params ) )
if ( ! vacuum_rel ( vrel - > oid , vrel - > relation , params ) )
continue ;
}
if ( options & VACOPT_ANALYZE )
if ( params - > options & VACOPT_ANALYZE )
{
/*
* If using separate xacts , start one for analyze . Otherwise ,
@ -354,7 +354,7 @@ vacuum(int options, List *relations, VacuumParams *params,
PushActiveSnapshot ( GetTransactionSnapshot ( ) ) ;
}
analyze_rel ( vrel - > oid , vrel - > relation , options , params ,
analyze_rel ( vrel - > oid , vrel - > relation , params ,
vrel - > va_cols , in_outer_xact , vac_strategy ) ;
if ( use_own_xacts )
@ -390,7 +390,7 @@ vacuum(int options, List *relations, VacuumParams *params,
StartTransactionCommand ( ) ;
}
if ( ( options & VACOPT_VACUUM ) & & ! IsAutoVacuumWorkerProcess ( ) )
if ( ( params - > options & VACOPT_VACUUM ) & & ! IsAutoVacuumWorkerProcess ( ) )
{
/*
* Update pg_database . datfrozenxid , and truncate pg_xact if possible .
@ -490,14 +490,13 @@ vacuum_is_relation_owner(Oid relid, Form_pg_class reltuple, int options)
* or locked , a log is emitted if possible .
*/
Relation
vacuum_open_relation ( Oid relid , RangeVar * relation , VacuumParams * param s,
int options , LOCKMODE lmode )
vacuum_open_relation ( Oid relid , RangeVar * relation , int option s,
bool verbose , LOCKMODE lmode )
{
Relation onerel ;
bool rel_lock = true ;
int elevel ;
Assert ( params ! = NULL ) ;
Assert ( ( options & ( VACOPT_VACUUM | VACOPT_ANALYZE ) ) ! = 0 ) ;
/*
@ -538,13 +537,12 @@ vacuum_open_relation(Oid relid, RangeVar *relation, VacuumParams *params,
/*
* Determine the log level .
*
* For autovacuum logs , we emit a LOG if log_autovacuum_min_duration is
* not disabled . For manual VACUUM or ANALYZE , we emit a WARNING to match
* the log statements in the permission checks .
* For manual VACUUM or ANALYZE , we emit a WARNING to match the log statements
* in the permission checks ; otherwise , only log if the caller so requested .
*/
if ( ! IsAutoVacuumWorkerProcess ( ) )
elevel = WARNING ;
else if ( params - > log_min_duration > = 0 )
else if ( verbose )
elevel = LOG ;
else
return NULL ;
@ -1521,7 +1519,7 @@ vac_truncate_clog(TransactionId frozenXID,
* At entry and exit , we are not inside a transaction .
*/
static bool
vacuum_rel ( Oid relid , RangeVar * relation , int options , VacuumParams * params )
vacuum_rel ( Oid relid , RangeVar * relation , VacuumParams * params )
{
LOCKMODE lmode ;
Relation onerel ;
@ -1542,7 +1540,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
*/
PushActiveSnapshot ( GetTransactionSnapshot ( ) ) ;
if ( ! ( options & VACOPT_FULL ) )
if ( ! ( params - > options & VACOPT_FULL ) )
{
/*
* In lazy vacuum , we can set the PROC_IN_VACUUM flag , which lets
@ -1582,10 +1580,12 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
* vacuum , but just ShareUpdateExclusiveLock for concurrent vacuum . Either
* way , we can be sure that no other backend is vacuuming the same table .
*/
lmode = ( options & VACOPT_FULL ) ? AccessExclusiveLock : ShareUpdateExclusiveLock ;
lmode = ( params - > options & VACOPT_FULL ) ?
AccessExclusiveLock : ShareUpdateExclusiveLock ;
/* open the relation and get the appropriate lock on it */
onerel = vacuum_open_relation ( relid , relation , params , options , lmode ) ;
onerel = vacuum_open_relation ( relid , relation , params - > options ,
params - > log_min_duration > = 0 , lmode ) ;
/* leave if relation could not be opened or locked */
if ( ! onerel )
@ -1605,7 +1605,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
*/
if ( ! vacuum_is_relation_owner ( RelationGetRelid ( onerel ) ,
onerel - > rd_rel ,
options & VACOPT_VACUUM ) )
params - > options & VACOPT_VACUUM ) )
{
relation_close ( onerel , lmode ) ;
PopActiveSnapshot ( ) ;
@ -1677,7 +1677,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
* us to process it . In VACUUM FULL , though , the toast table is
* automatically rebuilt by cluster_rel so we shouldn ' t recurse to it .
*/
if ( ! ( options & VACOPT_SKIPTOAST ) & & ! ( options & VACOPT_FULL ) )
if ( ! ( params - > options & VACOPT_SKIPTOAST ) & & ! ( params - > options & VACOPT_FULL ) )
toast_relid = onerel - > rd_rel - > reltoastrelid ;
else
toast_relid = InvalidOid ;
@ -1696,7 +1696,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
/*
* Do the actual work - - - either FULL or " lazy " vacuum
*/
if ( options & VACOPT_FULL )
if ( params - > options & VACOPT_FULL )
{
int cluster_options = 0 ;
@ -1704,14 +1704,14 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
relation_close ( onerel , NoLock ) ;
onerel = NULL ;
if ( ( options & VACOPT_VERBOSE ) ! = 0 )
if ( ( params - > options & VACOPT_VERBOSE ) ! = 0 )
cluster_options | = CLUOPT_VERBOSE ;
/* VACUUM FULL is now a variant of CLUSTER; see cluster.c */
cluster_rel ( relid , InvalidOid , cluster_options ) ;
}
else
heap_vacuum_rel ( onerel , options , params , vac_strategy ) ;
heap_vacuum_rel ( onerel , params , vac_strategy ) ;
/* Roll back any GUC changes executed by index functions */
AtEOXact_GUC ( false , save_nestlevel ) ;
@ -1737,7 +1737,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
* totally unimportant for toast relations .
*/
if ( toast_relid ! = InvalidOid )
vacuum_rel ( toast_relid , NULL , options , params ) ;
vacuum_rel ( toast_relid , NULL , params ) ;
/*
* Now release the session - level lock on the master table .