@ -41,6 +41,7 @@
# include "catalog/pg_namespace.h"
# include "catalog/pg_namespace.h"
# include "commands/cluster.h"
# include "commands/cluster.h"
# include "commands/defrem.h"
# include "commands/defrem.h"
# include "commands/tablecmds.h"
# include "commands/vacuum.h"
# include "commands/vacuum.h"
# include "miscadmin.h"
# include "miscadmin.h"
# include "nodes/makefuncs.h"
# include "nodes/makefuncs.h"
@ -91,7 +92,8 @@ static void vac_truncate_clog(TransactionId frozenXID,
MultiXactId minMulti ,
MultiXactId minMulti ,
TransactionId lastSaneFrozenXid ,
TransactionId lastSaneFrozenXid ,
MultiXactId lastSaneMinMulti ) ;
MultiXactId lastSaneMinMulti ) ;
static bool vacuum_rel ( Oid relid , RangeVar * relation , VacuumParams * params ) ;
static bool vacuum_rel ( Oid relid , RangeVar * relation , VacuumParams * params ,
bool skip_privs ) ;
static double compute_parallel_delay ( void ) ;
static double compute_parallel_delay ( void ) ;
static VacOptValue get_vacoptval_from_boolean ( DefElem * def ) ;
static VacOptValue get_vacoptval_from_boolean ( DefElem * def ) ;
static bool vac_tid_reaped ( ItemPointer itemptr , void * state ) ;
static bool vac_tid_reaped ( ItemPointer itemptr , void * state ) ;
@ -501,7 +503,7 @@ vacuum(List *relations, VacuumParams *params,
if ( params - > options & VACOPT_VACUUM )
if ( params - > options & VACOPT_VACUUM )
{
{
if ( ! vacuum_rel ( vrel - > oid , vrel - > relation , params ) )
if ( ! vacuum_rel ( vrel - > oid , vrel - > relation , params , false ) )
continue ;
continue ;
}
}
@ -598,11 +600,13 @@ vacuum_is_permitted_for_relation(Oid relid, Form_pg_class reltuple,
* - the role owns the relation
* - the role owns the relation
* - the role owns the current database and the relation is not shared
* - the role owns the current database and the relation is not shared
* - the role has been granted the MAINTAIN privilege on the relation
* - the role has been granted the MAINTAIN privilege on the relation
* - the role has privileges to vacuum / analyze any of the relation ' s
* partition ancestors
* - - - - - - - - - -
* - - - - - - - - - -
*/
*/
if ( object_ownercheck ( RelationRelationId , reli d, GetUserId ( ) ) | |
if ( ( object_ownercheck ( DatabaseRelationId , MyDatabaseI d, GetUserId ( ) ) & & ! reltuple - > relisshared ) | |
( object_ownercheck ( DatabaseRelationId , MyDatabaseI d, GetUserId ( ) ) & & ! reltuple - > relisshared ) | |
pg_class_aclcheck ( reli d, GetUserId ( ) , ACL_MAINTAIN ) = = ACLCHECK_OK | |
pg_class_aclcheck ( relid , GetUserId ( ) , ACL_MAINTAIN ) = = ACLCHECK_OK )
has_partition_ancestor_privs ( relid , GetUserId ( ) , ACL_MAINTAIN ) )
return true ;
return true ;
relname = NameStr ( reltuple - > relname ) ;
relname = NameStr ( reltuple - > relname ) ;
@ -1828,7 +1832,7 @@ vac_truncate_clog(TransactionId frozenXID,
* At entry and exit , we are not inside a transaction .
* At entry and exit , we are not inside a transaction .
*/
*/
static bool
static bool
vacuum_rel ( Oid relid , RangeVar * relation , VacuumParams * params )
vacuum_rel ( Oid relid , RangeVar * relation , VacuumParams * params , bool skip_privs )
{
{
LOCKMODE lmode ;
LOCKMODE lmode ;
Relation rel ;
Relation rel ;
@ -1915,7 +1919,8 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params)
* happen across multiple transactions where privileges could have changed
* happen across multiple transactions where privileges could have changed
* in - between . Make sure to only generate logs for VACUUM in this case .
* in - between . Make sure to only generate logs for VACUUM in this case .
*/
*/
if ( ! vacuum_is_permitted_for_relation ( RelationGetRelid ( rel ) ,
if ( ! skip_privs & &
! vacuum_is_permitted_for_relation ( RelationGetRelid ( rel ) ,
rel - > rd_rel ,
rel - > rd_rel ,
params - > options & VACOPT_VACUUM ) )
params - > options & VACOPT_VACUUM ) )
{
{
@ -2089,7 +2094,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params)
* totally unimportant for toast relations .
* totally unimportant for toast relations .
*/
*/
if ( toast_relid ! = InvalidOid )
if ( toast_relid ! = InvalidOid )
vacuum_rel ( toast_relid , NULL , params ) ;
vacuum_rel ( toast_relid , NULL , params , true ) ;
/*
/*
* Now release the session - level lock on the main table .
* Now release the session - level lock on the main table .