Fix PostgreSQL restore permission errors with non-superuser accounts #627
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.
This PR resolves PostgreSQL permission errors that occur when restoring backups with non-superuser database accounts. Users were encountering errors like:
Problem
When using
pg_restore --clean
, the tool attempts to drop existing database objects before recreating them, including system extensions likeplpgsql
. However, non-superuser database accounts don't have permission to drop system extensions, causing restore operations to fail.Solution
Added automatic
--no-owner
flag support toPgDumpBinaryConnector
:no_owner = True
(default) forPgDumpBinaryConnector
--no-owner
flag is now added topg_restore
commands by defaultNO_OWNER: False
in their connector configurationBenefits
Example
Before this change, users had to manually specify:
python manage.py dbrestore --pg-options="--no-owner"
Now it works automatically:
python manage.py dbrestore # Just works with non-superuser accounts
Users who need ownership preservation can configure:
Technical Details
PgDumpBinaryConnector
to includeno_owner = True
by default_restore_dump()
method to add--no-owner
flag when enabledFixes #495.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.