@@ -115,7 +115,7 @@ static void vac_truncate_clog(TransactionId frozenXID,
115115 TransactionId lastSaneFrozenXid ,
116116 MultiXactId lastSaneMinMulti );
117117static bool vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params ,
118- bool skip_privs , BufferAccessStrategy bstrategy );
118+ BufferAccessStrategy bstrategy );
119119static double compute_parallel_delay (void );
120120static VacOptValue get_vacoptval_from_boolean (DefElem * def );
121121static bool vac_tid_reaped (ItemPointer itemptr , void * state );
@@ -620,8 +620,7 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
620620
621621 if (params -> options & VACOPT_VACUUM )
622622 {
623- if (!vacuum_rel (vrel -> oid , vrel -> relation , params , false,
624- bstrategy ))
623+ if (!vacuum_rel (vrel -> oid , vrel -> relation , params , bstrategy ))
625624 continue ;
626625 }
627626
@@ -712,6 +711,13 @@ vacuum_is_permitted_for_relation(Oid relid, Form_pg_class reltuple,
712711
713712 Assert ((options & (VACOPT_VACUUM | VACOPT_ANALYZE )) != 0 );
714713
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+
715721 /*----------
716722 * A role has privileges to vacuum or analyze the relation if any of the
717723 * following are true:
@@ -1953,7 +1959,7 @@ vac_truncate_clog(TransactionId frozenXID,
19531959 */
19541960static bool
19551961vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params ,
1956- bool skip_privs , BufferAccessStrategy bstrategy )
1962+ BufferAccessStrategy bstrategy )
19571963{
19581964 LOCKMODE lmode ;
19591965 Relation rel ;
@@ -2040,10 +2046,9 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params,
20402046 * happen across multiple transactions where privileges could have changed
20412047 * in-between. Make sure to only generate logs for VACUUM in this case.
20422048 */
2043- if (!skip_privs &&
2044- !vacuum_is_permitted_for_relation (RelationGetRelid (rel ),
2049+ if (!vacuum_is_permitted_for_relation (RelationGetRelid (rel ),
20452050 rel -> rd_rel ,
2046- params -> options & VACOPT_VACUUM ))
2051+ params -> options & ~ VACOPT_ANALYZE ))
20472052 {
20482053 relation_close (rel , lmode );
20492054 PopActiveSnapshot ();
@@ -2229,11 +2234,16 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params,
22292234 {
22302235 VacuumParams toast_vacuum_params ;
22312236
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+ */
22332242 memcpy (& toast_vacuum_params , params , sizeof (VacuumParams ));
22342243 toast_vacuum_params .options |= VACOPT_PROCESS_MAIN ;
2244+ toast_vacuum_params .options |= VACOPT_SKIP_PRIVS ;
22352245
2236- vacuum_rel (toast_relid , NULL , & toast_vacuum_params , true, bstrategy );
2246+ vacuum_rel (toast_relid , NULL , & toast_vacuum_params , bstrategy );
22372247 }
22382248
22392249 /*
0 commit comments