@@ -115,7 +115,7 @@ static void vac_truncate_clog(TransactionId frozenXID,
115
115
TransactionId lastSaneFrozenXid ,
116
116
MultiXactId lastSaneMinMulti );
117
117
static bool vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params ,
118
- bool skip_privs , BufferAccessStrategy bstrategy );
118
+ BufferAccessStrategy bstrategy );
119
119
static double compute_parallel_delay (void );
120
120
static VacOptValue get_vacoptval_from_boolean (DefElem * def );
121
121
static bool vac_tid_reaped (ItemPointer itemptr , void * state );
@@ -620,8 +620,7 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
620
620
621
621
if (params -> options & VACOPT_VACUUM )
622
622
{
623
- if (!vacuum_rel (vrel -> oid , vrel -> relation , params , false,
624
- bstrategy ))
623
+ if (!vacuum_rel (vrel -> oid , vrel -> relation , params , bstrategy ))
625
624
continue ;
626
625
}
627
626
@@ -712,6 +711,13 @@ vacuum_is_permitted_for_relation(Oid relid, Form_pg_class reltuple,
712
711
713
712
Assert ((options & (VACOPT_VACUUM | VACOPT_ANALYZE )) != 0 );
714
713
714
+ /*
715
+ * Privilege checks are bypassed in some cases (e.g., when recursing to a
716
+ * relation's TOAST table).
717
+ */
718
+ if (options & VACOPT_SKIP_PRIVS )
719
+ return true;
720
+
715
721
/*----------
716
722
* A role has privileges to vacuum or analyze the relation if any of the
717
723
* following are true:
@@ -1953,7 +1959,7 @@ vac_truncate_clog(TransactionId frozenXID,
1953
1959
*/
1954
1960
static bool
1955
1961
vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params ,
1956
- bool skip_privs , BufferAccessStrategy bstrategy )
1962
+ BufferAccessStrategy bstrategy )
1957
1963
{
1958
1964
LOCKMODE lmode ;
1959
1965
Relation rel ;
@@ -2040,10 +2046,9 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params,
2040
2046
* happen across multiple transactions where privileges could have changed
2041
2047
* in-between. Make sure to only generate logs for VACUUM in this case.
2042
2048
*/
2043
- if (!skip_privs &&
2044
- !vacuum_is_permitted_for_relation (RelationGetRelid (rel ),
2049
+ if (!vacuum_is_permitted_for_relation (RelationGetRelid (rel ),
2045
2050
rel -> rd_rel ,
2046
- params -> options & VACOPT_VACUUM ))
2051
+ params -> options & ~ VACOPT_ANALYZE ))
2047
2052
{
2048
2053
relation_close (rel , lmode );
2049
2054
PopActiveSnapshot ();
@@ -2229,11 +2234,16 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params,
2229
2234
{
2230
2235
VacuumParams toast_vacuum_params ;
2231
2236
2232
- /* force VACOPT_PROCESS_MAIN so vacuum_rel() processes it */
2237
+ /*
2238
+ * Force VACOPT_PROCESS_MAIN so vacuum_rel() processes it. Likewise,
2239
+ * set VACOPT_SKIP_PRIVS since privileges on the main relation are
2240
+ * sufficient to process it.
2241
+ */
2233
2242
memcpy (& toast_vacuum_params , params , sizeof (VacuumParams ));
2234
2243
toast_vacuum_params .options |= VACOPT_PROCESS_MAIN ;
2244
+ toast_vacuum_params .options |= VACOPT_SKIP_PRIVS ;
2235
2245
2236
- vacuum_rel (toast_relid , NULL , & toast_vacuum_params , true, bstrategy );
2246
+ vacuum_rel (toast_relid , NULL , & toast_vacuum_params , bstrategy );
2237
2247
}
2238
2248
2239
2249
/*
0 commit comments