sudo -u postgres pg_restore --host=localhost -l test.backup
By specifying the host ironically we force it to ignore local configs and use the newest version of pg_restore which seems to work fine restoring to a PG 10 cluster.
–
–
–
–
–
ubuntu guys: most likely your pg_restore
is outdated. Just use postgres doc and install newest version of postgres:
Create the file /etc/apt/sources.list.d/pgdg.list
and add a line for the repository: deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main
where ubuntu versions are:
20.04 - focal
18.04 - bionic
16.04 - xenial
Add keys: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update && sudo apt-get upgrade
It worked for me!
So my experience here was somewhat similar to OP, but not completely.
I had versions 9.4, 9.5, 11, and 12 installed, and all the pg_* tools pointed to the 9.4 version. I tried to pg_restore a dump create by version 12 on a different host, which didn't work because this host used the 9.4 tools, which were incompatible (same error as OP posted).
So, here was my debugging flow:
which pg_restore
/usr/bin/pg_restore
ls -l /usr/bin/pg_restore
/usr/bin/pg_restore -> ../share/postgresql-common/pg_wrapper
vim /usr/share/postgresql-common/pg_wrapper
Read about how it determines version. Just read through the first 20 or so lines
Apparantly, there is a --cluster
option, which is helpful in resolving the version. So I simply added --cluster 12/main
to my pg_restore
call, and everything works as expected again
Here's another twist, but please note first that this is a windows case.
If it's just linux for you, don't read further.
All advice given here did not help me, eventually the cause IMC was simpler and had to do with the use of pgAdmin. Because of the repetitive nag for newer versions, my habit is to install pgAdmin separately (not using stackbuilder).
(AT LEAST) in that case, pgAdmin has its own cache of utility programs and will use these unless you tell it differently. My pg instances are still version 11(.6), but the latest pgAdmin will probably have V12 utilities. Which may quite well cause a version discrepancy.
This crept up on me after doing a number of succesful transfers from my main machine to a laptop. So, in pgAdmin do (menu)File->preferences->Paths and set Binary Paths corresponding to your postgres installation, IMC C:\Program Files\PostgreSQL\11\bin.
That did the job.
This error is caused by a version mismatch between the version of pg_dump used to create the backup file and the version of pg_restore used to attempt the restore.
Updating my PostgreSQL solved the problem
–
On my case (on Mac, Postgres managed by Homebrew) the solution was to check the pg_dump version used to create the dump file and install that version of postgresql.
Apparently with Brew you can't install pg_restore separately from postgresql (not sure, didn't really dig into it), so I needed to install postgresql@12 and link it. That did it.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.