I am trying to find out how to migrate my PostgreSQL database easily from Heroku to Railway. I have tried using heroku pg:backups:capture --app APP_NAME and heroku pg:backups:download with pg_restore and no success.
I had the error
pg_restore: error: corrupt tar header found in PGDMP (expected 0, computed 19471) file position 512
TL;DR:
Details:
If you logged in successfully after running
heroku login,$DATABASE_URLis read from your Heroku environment, so no need to insert the database url by hand.<filename.sql>: specify any filename you like. You will use it later to import the database.<heroku-app-name>: The name of your Heroku (backend) app with the Postgres database.Provision a new PostgreSQL database in your railway project and grab
$PGPASSWORD,$PGHOST,$PGUSER,$PGPORT, and$PGDATABASEfrom the Variables tab.This is what it should look like
Example (with dummy credentials):