Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b1a879

Browse filesBrowse files
Move bool parameter for vacuum_rel() to option bits.
ff9618e introduced the skip_privs parameter, which is used to skip privilege checks when recursing to a relation's TOAST table. This parameter should have been added as a flag bit in VacuumParams->options instead. Suggested-by: Michael Paquier Reviewed-by: Michael Paquier, Jeff Davis Discussion: https://postgr.es/m/ZIj4v1CwqlDVJZfB%40paquier.xyz
1 parent 4539262 commit 5b1a879
Copy full SHA for 5b1a879

File tree

3 files changed

+21
-10
lines changed
Filter options

3 files changed

+21
-10
lines changed

‎src/backend/commands/analyze.c

Copy file name to clipboardExpand all lines: src/backend/commands/analyze.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ analyze_rel(Oid relid, RangeVar *relation,
167167
*/
168168
if (!vacuum_is_permitted_for_relation(RelationGetRelid(onerel),
169169
onerel->rd_rel,
170-
params->options & VACOPT_ANALYZE))
170+
params->options & ~VACOPT_VACUUM))
171171
{
172172
relation_close(onerel, ShareUpdateExclusiveLock);
173173
return;

‎src/backend/commands/vacuum.c

Copy file name to clipboardExpand all lines: src/backend/commands/vacuum.c
+19-9Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void vac_truncate_clog(TransactionId frozenXID,
115115
TransactionId lastSaneFrozenXid,
116116
MultiXactId lastSaneMinMulti);
117117
static bool vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params,
118-
bool skip_privs, BufferAccessStrategy bstrategy);
118+
BufferAccessStrategy bstrategy);
119119
static double compute_parallel_delay(void);
120120
static VacOptValue get_vacoptval_from_boolean(DefElem *def);
121121
static 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
*/
19541960
static bool
19551961
vacuum_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
/*

‎src/include/commands/vacuum.h

Copy file name to clipboardExpand all lines: src/include/commands/vacuum.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ typedef struct VacAttrStats
191191
#define VACOPT_DISABLE_PAGE_SKIPPING 0x100 /* don't skip any pages */
192192
#define VACOPT_SKIP_DATABASE_STATS 0x200 /* skip vac_update_datfrozenxid() */
193193
#define VACOPT_ONLY_DATABASE_STATS 0x400 /* only vac_update_datfrozenxid() */
194+
#define VACOPT_SKIP_PRIVS 0x800 /* skip privilege checks */
194195

195196
/*
196197
* Values used by index_cleanup and truncate params.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.