Last active
November 21, 2021 17:23
-
-
Save SQLadmin/dcf5a613a883e8c821b6ee5337d4a5f8 to your computer and use it in GitHub Desktop.
Migrate Postgresql users to another server and RDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Export the users | |
pg_dumpall -g > users.sql | |
-- Importing to another PostgresSQL | |
awk '/CREATE/' users.sql > migrate.sql | |
-- Import to RDS; It won't support super user and replication roles. But we can grant minimal superuser with rds_superuser | |
psql -h localserver -d postgres -t -c"select 'grant rds_superuser to '||rolname ||';' from pg_roles where rolsuper='t';" -P "footer=off" >> migrate.sql | |
sed -i -e's/NOSUPERUSER//g; s/SUPERUSER//g; s/NOREPLICATION//g; s//REPLICATION/g' migrate.sql | |
psql -h rds-endpoint -U adminuser -d postgres < migrate.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment