Besides the use mentioned above, this patch allows one to dump Globals from their AWS RDS Postgres Database and have a complete backup as a part of their Disaster Recovery (DR) solution. This earlier required an inelegant hack (detailed here in another post of mine) that wasn't very convenient for a regular user.
For those interested, RDS Postgres (by design) doesn't allow you to read pg_authid, which was earlier necessary for pg_dumpall to work. With this patch checked-in, pg_dumpall now uses a workaround (pg_roles) to read the same data (except passwords) and generate the same SQL Script.
With that mentioned, let's get our hands dirty and see a working solution:
# Take RDS Postgres Dump
# We store the pgdb database in pgdb.sql and globals in pgdb_globals.sql
pg_dumpall --globals-only --no-role-passwords \
-U rdssuperuser -h rdsinstance \
2>stderr.txt > pgdb_globals.sql
pg_dump -U rdssuperuser -h rdsinstance pgdb 2>stderr.txt > pgdb.sql
psql -U postgres -c "CREATE DATABASE pgdb;"
# rdsadmin database (even if empty) is required for the next script
psql -U postgres -c "CREATE DATABASE rdsadmin;"
psql -U postgres pgdb < pgdb_globals.sql
psql -U postgres pgdb < pgdb.sql
Big thanks to Simon for ironing out a few issues, Stephen, David & Robert for their (critical) reviews.
13 comments:
Thank you so much for this. It took me until midnight to find it on Google but it worked perfectly :) Had a 9.6 database in RDS that I needed to move to 10 in order to get improved Row Level Security performance.
One thing that was worth doing was adding -v ON_ERROR_STOP=1 to the psql import command.
Thanks Tim... and I agree that ON_ERROR_STOP helps the client to stop early (on error) which makes triaging issues so much easier.
Hey, maybe I'm not following, how can I get that patched version? cuz we're having the exact same issue.
Hi Naim,
If you're okay with the fact that Postgres v10 isn't production ready yet, you could download the Beta binaries and use that:
https://www.enterprisedb.com/products-services-training/pgdevdownload
Further, since Postgres is open source you could always compile Postgres v10 branch yourself from source.
While restoring i am facing error.
ERROR: must be superuser to alter superusers
ERROR: must be superuser to set grantor
Users are created but they are not getting an appropriate permissions. I also removed all the system created roles like rds_replication, rds_superuser, etc. from the pg_dumpall script.
I'm using Aurora postgres 9.6
This example might work fine for dumping RDS and restoring locally, but it doesn't work for dumping RDS and restoring to RDS.
You just hit the same problem with the fact you're not really a superuser that you did when dumping.
Got the same errors as reported by Qutub, in addition to a bunch of more errors like "Invalid Command \N".
The spelling of the option may have changed since you posted this article.
I got an error when I tried the option:
--no-role-password
I changed the spelling to:
--no-role-passwords
and the command worked.
Post a Comment