Skip to content

Make more pg_dump/pg_restore flags available for migrations across databases #387

Closed

Description

@pfiaux

Feature Request

Make more pg_dump/pg_restore flags available to facilitate operations across databases.

Problem definition

When running dbbackup on one server and dbrestore on another server, especially when a separate database (i.e. migration) is used as well doesn't work. The default pg_dump/pg_restore settings include many operations that are database specific options and not relevant to django, for instance:

  • The table owner will likely be different
    • The --no-owner flag solves this problem
  • The database can have ACLs, roles, grants which are not related to django but to the operations of that database
    • The --no-privileges flag solves this problem

Without these flags the errors can be cryptic and hard to understand when a command on a random table or fails.

Temporary solution

I was able to solve the first 2 points above using the suggestion from #213 (comment)

Using the following in settings.py:

DBBACKUP_CONNECTOR_MAPPING = {
    'django.db.backends.postgresql': 'dbbackup.db.postgresql.PgDumpBinaryConnector',
}
DBBACKUP_CONNECTORS = {
    'default': {
        # 'dump_suffix': '--no-owner', # Does not work because it comes after command
        'dump_cmd': 'pg_dump --no-owner --no-privileges',
        'restore_cmd': 'pg_restore --no-owner --no-privileges',
    }
}

Allowed me to export and import with out running into owner or ACL issues.

Possible improvements

One improvements would be to make these flags available or a way to insert arguments into the dump and restore commands (as mentioned in the issue link the suffix happens too late) would make it cleaner and improve the documentation.

Another improvement might be to consider the no owner and perhaps also the no privileges as default options, it's not ideal because it might be a breaking changes in some cases but from my understanding they're not critical or needed for a standard django installation so they might be safer defaults (especially if there's a documented way to turn them off).

Activity

  1. Repository owner locked and limited conversation to collaborators on Jun 15, 2025
  2. converted this issue into a discussion #584 on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions