Zastrix Arundell
Zastrix Arundell

Reputation: 93

Getting pg_restore error 1 when running pg:pull on Heroku

I am trying to copy the database from our staging server onto my local machine and I'm having some issues. This was working 2 months ago flawlessly and when I tried to use it again today I'm getting an issue.

I am using this command:

heroku pg:pull DATABASE_URL my_app_db -a myApp

And at the end of the logs I get this:

pg_dump: reading subscriptions
pg_dump: reading large objects
pg_dump: reading dependency data
pg_dump: saving encoding = UTF8
pg_dump: saving standard_conforming_strings = on
pg_dump: saving search_path = 
pg_dump: saving database definition
pg_restore: [archiver] unsupported version (1.14) in file header
pg_dump: dumping contents of table "public.addresses"
 ▸    pg_restore errored with 1

I've tried updating my postgresql package but they're the same on Heroku and my local machine:

$ psql --version
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)
$ heroku run psql --version -a myApp
Running psql --version on ⬢ myApp... up, run.5796 (Hobby)
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)

I've always dropped the database locally before doing the pull:

$ psql postgres
postgres=# DROP DATABASE my_app_db;
postgres=# \q

Update 1:

Looks like I have a pg_dump and pg_pull version mismatch:

$ pg_dump --version
pg_dump (PostgreSQL) 10.13 (Ubuntu 10.13-1.pgdg18.04+1)
$ heroku run pg_dump --version -a myApp
pg_dump (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)
$ pg_restore --version
pg_restore (PostgreSQL) 10.13 (Ubuntu 10.13-1.pgdg18.04+1)
$ heroku run pg_restore --version -a myApp
pg_restore (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)

What I saw on the internet is that it should be updated by installing the latest postgresql. For some reason two of them aren't updated even with the latest PostgreSQL version.

Solution to resolve the issue:

As clemoun pointed out, I must've had multiple psql versions running. I saw what I have with:

$ pg_lsclusters

Then uninstalled version 10 and 11 with:

$ sudo apt-get remove postgresql-10 postgresql-11

After that dropped the clusters:

$ sudo pg_dropcluster 10 main
$ sudo pg_dropcluster 11 main

And logged out and in.

Upvotes: 1

Views: 1325

Answers (1)

clemoun
clemoun

Reputation: 486

The fact that you have at the same time :

$ psql --version
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)

and

$ pg_restore --version
pg_restore (PostgreSQL) 10.13 (Ubuntu 10.13-1.pgdg18.04+1)

makes me think you have several versions of PostgreSQL installed on your computer.

Try typing :

sudo find /usr -wholename '*/bin/postgres'

and you might find out you have both PostgreSQL versions 10.13 and 12.3 installed. For some reason it's the 10.13 version of pg_restore that runs and Heroku requires that you use a version above 10.3 => Your 12.3 version should do the trick

Try uninstalling version 10.13 of Postgresql, leaving you computer with version 12.3 only. Thus pg_restore will run on version 12.3

Upvotes: 1

Related Questions