Allow to run pg_repack by non-superuser #431
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The option
--no-superuser-check
allows to by-pass the check if the user is a superuser. That was done for users which run pg_repack on Amazon, where users cannot run it as a superuser.The problem is that the option
--no-superuser-check
works only on the CLI level, skipping the check only by thepg_repack
client. But there are also checks done by the extension functions exported to SQL.The PR removes the check that the user is a superuser from functions
repack_trigger()
andrepack_apply()
. That check is redundant since queries executed by that functions can be executed by a user manually. Moreoverrepack_trigger()
is aSECURITY DEFINER
function, which means that it is executed with superuser privileges (pg_repack
extension can be created only by superuser).The PR changes privilege check in functions
repack_swap()
,repack_drop()
andrepack_index_swap()
. Now that functions can be run by an owner of a table. That check is necessary since_swap
functions swap relfilenodes onpg_class
system catalog table.repack_drop()
acquires ACCESS EXCLUSIVE lock and therefore it also requires privilege check.Additionally I cherry-picked the commit 326b6e1 from the PR #427. Otherwise
pg_repack
will fall with segmentation fault in case of lack of permissions.Relevant issues: