Skip to content

Instantly share code, notes, and snippets.

@halilim
Last active February 22, 2021 14:13
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save halilim/b184468772cae6f89ea4 to your computer and use it in GitHub Desktop.
Save halilim/b184468772cae6f89ea4 to your computer and use it in GitHub Desktop.
Move Heroku Postgres to Amazon AWS RDS
  1. Prepare your RDS instance and authorize access to it (basically make it public).

  2. Put your app in maintenance mode:

    heroku maintenance:on
  3. 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
  4. Upload the latest DB to RDS:

    psql -h RDS_DB_HOST -U RDS_DB_USER -d RDS_DB_NAME < latest.sql
  5. Remove your Postgres add-on from Heroku after making sure you have a backup, otherwise you will not be able to modify DATABASE_URL.

  6. 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
  7. Get your app out of maintenance:

     heroku maintenance:off
Resources
  1. Amazon RDS on Heroku
@jaypinho
Copy link

This was very helpful -- thank you!

@sicktastic
Copy link

Sicktastic. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment