R
Railway•2y ago
obedm

pg_restore not working corrupt tar header found

Trying to migrate from heroku postgres over to railway. The guide (https://blog.railway.app/p/postgre-backup) recommends using pg_dump and pg_restore. Once I had my latest.dump file from heroku I tried importing with pg_restore. It fails with pg_restore: error: corrupt tar header found in PGDMP (expected 0, computed 19329) file position 512 Found this StackOverflow answer to a similar problem. It recommended making sure pg_dump and pg_restore have the same version. Upgraded my local pg installation to 14.5 (the version heroku is running) but the error remains. Any help appreciated.
Railway Blog
How to Backup and Restore Your Postgres Database
In this post, we will go over the process of backing up and restoring your Postgres database hosted on Railway.
28 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
obedm
obedm•2y ago
got it from heroku with heroku pg:backups:download
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Faraz
Faraz•2y ago
Any chance y'all can run pg_dump on the heroku db? Ah, looks like that's what Heroku runs internally. Could you share the pg_restore command you ran?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Faraz
Faraz•2y ago
Could you try the command Heroku runs when they restore? pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump Seems like they run a pg_dump with the custom format option.
obedm
obedm•2y ago
Great success! Important to note I had specify -F t. pg_dump successfully connected and got the db
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
obedm
obedm•2y ago
Try following the intructions here https://blog.railway.app/p/postgre-backup and connecting pg_dump directly to heroku
Railway Blog
How to Backup and Restore Your Postgres Database
In this post, we will go over the process of backing up and restoring your Postgres database hosted on Railway.
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Faraz
Faraz•2y ago
Probably using the connection URL.
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Faraz
Faraz•2y ago
Not in this case as you're manually pasting the values. railway run is used when you need to inject the environment variable values.
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Faraz
Faraz•2y ago
Yes.
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
obedm
obedm•2y ago
using arguments directly. I didn't try with the url
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
obedm
obedm•2y ago
It's a 2 step process. Seems heroku uses their own format. First pg_dump then pg_restore pg_dump -h HOST -d $DATABASE -U $USER -p $PORT -W -F t > latest.dump then type the password when prompted. The DATABASE_URL format is postgres://$USER:$PASSWORD@$HOST:$PORT/$DATABASE. Run pg_dump with the heroku credentials
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
obedm
obedm•2y ago
Then pg_restore -U $USER -h $HOST -p $PORT -W -F t -d $DATABASE latest.dump with the railway credentials. fp, it'd would be cool to update the heroku migration article with the fact that heroku uses a weird dump format. Lots of people moving over lately
Faraz
Faraz•2y ago
Agreed. cc @Angelo if you want to take this or I can do it when I wake up! 😄
angelo
angelo•2y ago
I can put it in my to-dos for today!
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
angelo
angelo•2y ago
Would you mind making a new thread in #✋|help - bumping an old thread makes it hard for us to track
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
angelo
angelo•2y ago
Making an exception for you 🙂
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View