Skip to content

Instantly share code, notes, and snippets.

@SQLadmin
Last active November 21, 2021 17:23
Show Gist options
  • Save SQLadmin/dcf5a613a883e8c821b6ee5337d4a5f8 to your computer and use it in GitHub Desktop.
Save SQLadmin/dcf5a613a883e8c821b6ee5337d4a5f8 to your computer and use it in GitHub Desktop.
Migrate Postgresql users to another server and RDS
-- 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