Skip to content
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

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

Open
pfiaux opened this issue Apr 27, 2021 · 0 comments
Open

Comments

@pfiaux
Copy link

pfiaux commented Apr 27, 2021

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).

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

No branches or pull requests

1 participant