-
-
Couldn't load subscription status.
- Fork 222
Add ENABLE_ROW_SECURITY setting for PostgreSQL connectors to support row-level security policies #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Archmonger <16909269+Archmonger@users.noreply.github.com>
Co-authored-by: Archmonger <16909269+Archmonger@users.noreply.github.com>
pg_dump error: Query would be affected by row-level security policyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for PostgreSQL databases with row-level security (RLS) policies by introducing a new ENABLE_ROW_SECURITY setting for PostgreSQL connectors. The setting allows pg_dump to bypass RLS policies during backup operations.
Key changes:
- Added
enable_row_securityattribute to PostgreSQL connector classes with default valueFalse - Modified dump creation methods to include
--enable-row-securityflag when enabled - Added comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dbbackup/db/postgresql.py | Added enable_row_security attribute and flag logic to both PgDumpConnector and PgDumpBinaryConnector classes |
| tests/test_connectors/test_postgresql.py | Added test methods to verify the --enable-row-security flag is correctly included/excluded based on setting |
| docs/src/databases.md | Updated documentation with new setting description and usage example |
| CHANGELOG.md | Added changelog entries for the new feature and bug fix |
8f08d4d to
1b395cf
Compare
This PR adds support for PostgreSQL databases that have row-level security (RLS) policies enabled by introducing a new
ENABLE_ROW_SECURITYsetting for PostgreSQL connectors.Problem
When attempting to backup PostgreSQL databases with row-level security policies,
pg_dumpfails with:This occurs because
pg_dumpby default respects row-level security policies, which can prevent it from dumping all data in tables that have RLS enabled.Solution
Added a new
ENABLE_ROW_SECURITYsetting (default:False) that adds the--enable-row-securityflag topg_dumpcommands when enabled. This flag tellspg_dumpto dump data even when row-level security policies are active.Changes
enable_row_securityattribute to bothPgDumpConnectorandPgDumpBinaryConnectorclasses_create_dump()methods to include--enable-row-securityflag when the setting is enabledUsage
Backward Compatibility
This change is fully backward compatible. The default value is
False, so existing configurations will continue to work exactly as before. Users only need to opt-in to the new behavior when they have databases with row-level security policies.Fixes #496.
💡 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.