Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 22, 2025

This PR adds support for PostgreSQL databases that have row-level security (RLS) policies enabled by introducing a new ENABLE_ROW_SECURITY setting for PostgreSQL connectors.

Problem

When attempting to backup PostgreSQL databases with row-level security policies, pg_dump fails with:

pg_dump: error: query failed: ERROR: query would be affected by row-level security policy for table_
HINT: To disable the policy for the table's owner, use ALTER TABLE NO FORCE ROW LEVEL SECURITY

This occurs because pg_dump by 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_SECURITY setting (default: False) that adds the --enable-row-security flag to pg_dump commands when enabled. This flag tells pg_dump to dump data even when row-level security policies are active.

Changes

  • Added enable_row_security attribute to both PgDumpConnector and PgDumpBinaryConnector classes
  • Modified _create_dump() methods to include --enable-row-security flag when the setting is enabled
  • Added comprehensive test coverage for both connector classes
  • Updated documentation with setting description and usage example
  • Added changelog entries for the new feature

Usage

DBBACKUP_CONNECTORS = {
    'default': {
        'ENABLE_ROW_SECURITY': True
    }
}

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.

Copilot AI and others added 2 commits August 22, 2025 08:25
Co-authored-by: Archmonger <16909269+Archmonger@users.noreply.github.com>
Co-authored-by: Archmonger <16909269+Archmonger@users.noreply.github.com>
Copilot AI changed the title [WIP] pg_dump error: Query would be affected by row-level security policy Add ENABLE_ROW_SECURITY setting for PostgreSQL connectors to support row-level security policies Aug 22, 2025
Copilot AI requested a review from Archmonger August 22, 2025 08:27
Copilot finished work on behalf of Archmonger August 22, 2025 08:28
@Archmonger Archmonger requested a review from Copilot August 22, 2025 08:29
Copy link
Contributor

Copilot AI left a 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_security attribute to PostgreSQL connector classes with default value False
  • Modified dump creation methods to include --enable-row-security flag 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

@Archmonger Archmonger marked this pull request as ready for review August 22, 2025 08:37
@Archmonger Archmonger merged commit af665e7 into master Aug 22, 2025
57 checks passed
@Archmonger Archmonger deleted the copilot/fix-496 branch August 22, 2025 08:43
Archmonger added a commit that referenced this pull request Aug 23, 2025
…support row-level security policies (#624)"

This reverts commit af665e7.
@Archmonger Archmonger mentioned this pull request Aug 23, 2025
4 tasks
Archmonger added a commit that referenced this pull request Aug 23, 2025
This reverts commit af665e7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pg_dump error: Query would be affected by row-level security policy

2 participants