-
Prepare your RDS instance and authorize access to it (basically make it public).
-
Put your app in maintenance mode:
heroku maintenance:on
-
Save the latest SQL dump of the DB:
psql -h HEROKU_DB_HOST -U HEROKU_DB_USER -d HEROKU_DB_NAME > latest.sql
If that fails (long time no response etc.), an alternate method is pulling to local first:
# Use DATABASE_URL literally heroku pg:pull DATABASE_URL awesome_project_production_local psql -d awesome_project_production_local > latest.sql
-
Upload the latest DB to RDS:
psql -h RDS_DB_HOST -U RDS_DB_USER -d RDS_DB_NAME < latest.sql
-
Remove your Postgres add-on from Heroku after making sure you have a backup, otherwise you will not be able to modify
DATABASE_URL
. -
Set your new
DATABASE_URL
:heroku config:set DATABASE_URL=postgres://RDS_DB_USER:RDS_DB_PASS@RDS_DB_HOST:5432/RDS_DB_NAME?sslmode=require
-
Get your app out of maintenance:
heroku maintenance:off
-
-
Save sicktastic/f258d552baee2e7d3b6a3c98faec8337 to your computer and use it in GitHub Desktop.
Move Heroku Postgres to Amazon AWS RDS
Author
sicktastic
commented
Feb 7, 2020
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
pg_restore --verbose --clean --no-acl --no-owner -h $NAME.$ID.$DATACENTER.rds.amazonaws.com -U $RDS_ROOT_USER -d $DATABASE_NAME /tmp/latest.dump
psql$ create role whiteunicorn1234 with password 'PASTE_P'W'D_HERE' login;
psql$ create database whiteunicorn1234;
psql$ grant all on database whiteunicorn1234 to whiteunicorn1234;
psql$ \q
$ cd your_app
$ mkdir -p config
$ curl https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem > ./config/rds-combined-ca-bundle.pem
$ git add config/rds-combined-ca-bundle.pem
$ git commit -m "Add RDS certificate to app files"
$ git push heroku master
$ heroku addons:destroy heroku-postgresql
$ heroku config:set \
DATABASE_URL="postgres://whiteunicorn1234:$PASSWORD@$NAME.$ID.$DATACENTER.rds.amazonaws.com/whiteunicorn1234?sslca=config/rds-combined-ca-bundle.pem"
$ heroku maintenance:off
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment