-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
dbrestore fails on PostgreSQL when the db user hasn't superuser permissions #213
Comments
Hello @patrickhallen |
@ZuluPro @patrickhallen |
As I've already mentioned in the issue, there are two possible workaround. At the moment, I'm running dbrestore as the postgres user: Add the following to your settings.py:
Then run dbrestore as the system user postgres, which will automatically run psql as the postgres superuser.
Of course if you are using this database settings, you also need to run the dbbackup command as the postgres user or else the authentication to the Postgres server won't work. The postgres user requires read permissions of your Django project. The alternative is to simply make your Django DB user a Postgres superuser: |
Thanks Patrickhallen , I am using a cloud db service similar to AWS Database which won't provide superuser for us. So I think it's better that django-dbbackup can use pg_dump and pg_restore. |
yes, pg_dump and pg_restore looks like the best option. Too many problems with psql |
One option is to allow more optional pg_dump options to be set. In that case, we can specify --no-owner or -O to be able to be restored by any user. |
@georgema1982 : You can aleady add options to commands: http://django-dbbackup.readthedocs.io/en/stable/databases.html#dump-suffix-and-restore-prefix |
I have the very same problem and I would really appreciate a way to handle that which does not try to delete fundamental database things like plpgsql, but only access the tables. |
Fix issue with restore: jazzband/django-dbbackup#213 (comment)
@ZuluPro if the intended behavior is to allow dump_suffix to add additional parameters to the dump commands it does not seem to work as intended.
We need the command: DBBACKUP_CONNECTORS = {
'default': {
# 'dump_suffix': '--no-owner', # Does not work because it comes after command
'dump_cmd': 'pg_dump --no-owner'
}
} If you wanted dump_suffix additions (eg. in postgresql ) to work : cmd += ' {}'.format(self.settings['NAME'])
cmd = '{} {} {}'.format(self.dump_prefix, cmd, self.dump_suffix) would change for pg_dump and mysqldump commands to: cmd += ' {}'.format(self.dump_suffix)
cmd += ' {}'.format(self.settings['NAME'])
cmd = '{} {}'.format(self.dump_prefix, cmd) However, adding the option --no-owner does not work to solve this issue.From the issue at: https://stackoverflow.com/q/13410631/3166424 Trying the solution at: https://stackoverflow.com/a/46689304/3166424 'dump_suffix': r'| grep -v -E "(CREATE\ EXTENSION\ IF\ NOT\ EXISTS' +
r'\ plpgsql|COMMENT\ ON\ EXTENSION\ plpgsql)"', Does not work, because the Luckily, I am on a private server and so I followed the solution here: https://stackoverflow.com/a/15452741/3166424 |
@patrickhallen pg_restore has now been implemented (albeit it's not yet the default, it will be in the next release). Is there anything else one should know about this with regards to permissions for pg_restore? |
Hi,
on my system (Debian Jessie, Postgre 9.4, Django 1.10, Python 3.4) dbrestore fails with
ERROR: must be owner of extension plpgsql
. This is after applying the changes in #212 to get an error message at all.There are two obvious ways to fix this, both of which I don't particular like. One can either give the Django db user superuser permission or one can run the dbrestore command as the postgres superuser. To run dbrestore as the postgres user I have to give this user the permission to execute manage.py. Both of these options reduce the isolation between the user under which the Django application runs and the postgres user.
Another possible fix could be related to #190. The usage of the pg_restore command instead of pgsql gives a more fine-grained control over what to restore so one could limit the restore to the parts where the Django db user has the appropriate permissions for.
The text was updated successfully, but these errors were encountered: