Restore database - postgresql

I want to restore a database in PostgreSQL but it can't. I have replaced pg_restore in bin folder but it's still not working. The message is :
pg_restore: [archiver] unsupported version (1.12) in file header

I solved this by upgrading postgresql from 8.X to 9.2.4. If you're using brew on Mac OS-X, use -
brew upgrade postgresql
Once this is done, just make sure your new postgres installation is at the top of your path. It'll look something like (depending on the version installation path) -
export PATH=/usr/local/Cellar/postgresql/9.2.4/bin:$PATH

This occurs when the archive was created with a version newer than the pg_restore you are using can support. The best way to fix this is to install a newer version of pg_restore. Note that this limitation has more recently gone away. I can use pg_restore from 9.1 against a 9.2 custom dump file for example.

Related

Getting "[archiver] unsupported version (1.12) in file header" when running pg_restore

i have backup for pgrestore sql database 9.5 and i need restore it on 8.4 v but this error.
any idea to slove it
enter image description here
I guess you were too sloven in your upgrading if you ask a question about these versions...
Anyway, pg_restore will flat out refuse to restore a dump created with a later version of pg_dump, and pg_dump will refuse to dump a database that has a more recent versions than itself. In short, you cannot downgrade with pg_restore, because downgrading is not supported in PostgreSQL.
Your only option is to create a plain format dump and restore it with psql. That will probably cause errors, and you will have to manually modify the dump file until it restores correctly.

Postgres pg_dump version mismatch... even though versions are the same

I'm trying to dump a Postgres db from Amazon RDS, which I recently updated to 10.1. To do so, I download pg_dump 10.1 from enterprisedb.com (http://get.enterprisedb.com/postgresql/postgresql-10.1-1-linux-x64-binaries.tar.gz) but when I try to use it, I get the following error:
pg_dump: server version: 10.1; pg_dump version: 10.1
pg_dump: aborting because of server version mismatch
This worked fine before, when RDS had version 9.6 and I used pg_dump 9.6 (downloaded from the same location).
I tried newer versions of pg_dump (10.2 and 10.3) but get the same error (which makes sense, because those newer versions actually don't match the RDS version).
I also checked that no other pg_dump is installed on my server (Ubuntu 15.04 - I know I should update... waiting for 18.04), found one and deleted it, but get the same error.
What could be the problem here?
First of all, pg_dump works perfectly with older version of the server. In such cases you will see lines like these:
-- Dumped from database version 9.6.6
-- Dumped by pg_dump version 10.1
Also, pg_dump version, say, 10.0 should work with server version 10.1 and higher in 10.* branch – so minor version should not be the issue. See this comment in pg_dump's source code: https://github.com/postgres/postgres/blob/REL_10_STABLE/src/bin/pg_dump/pg_dump.c#L668
/*
* We allow the server to be back to 8.0, and up to any minor release of
* our own major version. (See also version check in pg_dumpall.c.)
*/
In your case, the issue can be caused by one of these aspects:
you downloaded not official pg_dump, you took it from one of Postgres companies, it can be modified somehow (notice addition "-1" in URL, so you use their version of pg_dump labeled as "10.1-1");
you're working with modified (by AWS engineers) Postgres server;
recently, versioning schema has been changed in the Postgres project, from 3-number versions to 2 numbers. This means, that some bugs in version detecting functions might be present since the changes are relatively new.
Anyway, the error message you provided saying that 10.1 and 10.1 do not match – this is is not normal at all. There is a definitely a bug, but it's not obvious where.
I would try the following steps.
1) Use official (community supported) pg_dump. On Ubuntu, you need just install "postgresql-client-10" using official packages:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-10
2) If the previous step doesn't help, try contacting AWS support, asking them to double-check this issue.
3) Finally, try to reproduce the problem with vanilla Postgres installed on your Ubuntu machine and if it persists, it definitely needs to be reported as a bug https://www.postgresql.org/docs/10/static/bug-reporting.html
try check for permissions - whats the path

Getting "[archiver] unsupported version (1.13) in file header" when running pg_restore

I just upgraded to postgres 10.2 on mac os which matches 10.2 on heroku. I'm trying to download a copy of the database and restore it locally. Before the upgrade the restore would work fine.
I run
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d database_name backup.dump
but I am getting this error:
pg_restore: [archiver] unsupported version (1.13) in file header
The database appears to be working OK. It's a rails app and I upgraded the pg gems. I can run rake db:create and db:migrate just fine.
You need to upgrade your local postgres to get the last security patch from the 2018-03-01, like Heroku did the 1st march. You need one of the last releases 10.3, 9.6.8, 9.5.12, 9.4.17, and 9.3.22.
The security patch can be found here https://www.postgresql.org/about/news/1834/.
It seems the patch modified pg_dump, that's probably why we can't use pg_restore anymore without that patch for the dump of Heroku (with the patch applied).
I ran into this same issue today, I don't know if something changed on Heroku's side, because locally I'm running 9.6 but my database on Heroku is 9.4, so it didn't seem to be about the version point difference (it was working until today.)
If you're using the Postgres.app (https://postgresapp.com/) on a Mac make sure you're running v2.1.3 (as of this writing that is the newest version). When you upgrade the Postgres.app you get the newest patch release of Postgres, (which is likely causing the mismatch you're currently experiencing - Heroku has upgraded for the latest security patch, and your local machine may not have it).
I had to upgrade Postgres.app from 2.1.0 to 2.1.3 and it solved the problem.
First time I've had this issue, here's how I restored the Heroku Database to my Local:
$ rails db:drop
$ heroku pg:pull DATABASE_URL <insert local DB name> --app <app-name>
Since yesterday (03/01/2018) we also had problems restoring a backup from Heroku running on PostgreSQL 9.5:
pg_restore: [archiver] unsupported version (1.13) in file header
Upgrading our PostgreSQL version from 9.5.11 to 9.5.12 fixed the issue.
For those who are trying to upgrade postgresql in Ubuntu without success (like Johan's commented above), try using the PostgreSQL apt repository, as stated in the official PostgreSQL download instructions: https://www.postgresql.org/download/linux/ubuntu/
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
The fix for me involved both updating my Postgres.app and updating my local homebrew PostgreSQL.
Update my Postgres.app via Canuk's answer:
Open Postgres.app > Check for updates...
Update my local homebrew PostgreSQL via gerry3's comment on the accepted answer:
brew upgrade postgresql brew postgresql-upgrade-database
Had this problem on Windows using pgAdmin 3.
Upgrading from pgAdmin 3 to pgAdmin 4 solved the problem for me.
If you are using a third-party tool, such as PgAdmin, to restore the
provided dump file, the restore may not succeed even with the
installed Postgres version being up to date. This is due to
third-party tools often bundling their own versions of the pg_restore
binary, that may not be up to date.
https://help.heroku.com/YNH1ZJUS/why-am-i-getting-pg_restore-archiver-unsupported-version-1-13-in-file-header-error-with-pg_restore
I don't recommend upgrading your DB to a new major version locally (do apply security patches) just to fix this as you want that to match whatever version you have in production.
This fixed it on Ubuntu 16.04, restoring from a Heroku database.
First, ensure you have the postgresql repo as diego mentioned. Then install the upgraded client.
sudo apt-get update && sudo apt-get install postgresql-client-10
If you are Ubuntu 17.04 or 17.10, note that the PostgreSQL's zesty repo does not have the updated client's you need. You will want to use the xenial Postgres repo instead.
I encountered this problem on pgadmin III and was able to fix it through switching the binaries location:
File menu > Options > Binary Paths, then changed "PG bin path" to postgresql/9.x/bin instead of ProgramFiles/pgadmin. Restore worked fine afterwards.
Here is how I resolved the issue on Ubuntu(16.04 LTS) where pg_restore/pg_dump gave me an older version, from psql
$ pg_restore --version
pg_restore (PostgreSQL) 9.4.8
$ psql --version
psql (PostgreSQL) 9.5.14
The issue is that I have multiple pg versions installed, and pg_restore was pointing to the earlier version
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
9.4 main 5432 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log
9.5 main 5433 online postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
The fix is to create a ~/.postgresqlrc file pointing to the correct version
$ cat ~/.postgresqlrc
9.5 main *
Once this was done, pg_restore points to the correct version, and the command goes through
Details given here: https://serverfault.com/questions/610777/wrong-version-of-pg-dump-on-ubuntu
You're using an old version of pg_restore binary that doesn't support restoring the provided dump file. Please make sure that you use the latest Postgres version, which must be higher than the following release: https://www.postgresql.org/about/news/1834/ (10.3, 9.6.8, 9.5.12, 9.4.17, and 9.3.22).
You can check the pg_restore version you're using by running pg_restore --version.
If you are using a third-party tool, such as PgAdmin, to restore the provided dump file, the restore may not succeed even with the installed Postgres version being up to date. This is due to third-party tools often bundling their own versions of the pg_restore binary, that may not be up to date.
I was encountering the same error. I updated to postgresql 10.3 locally, and that fixed the problem for me.
For Windows:
Open Command Prompt (cmd), then go to location C:\Program Files\PostgreSQL\9.6\bin and run these commands:
pg_restore -U username -d dbname -1 filename.dump
pg_restore -U postgres -d app -1 G:\app09-07-2019.backup
Hope it will help you
I ran in the same issue 10 minutes ago, and found out about this thread from 2005:
https://www.postgresql.org/message-id/1106163722.780395.266900%40z14g2000cwz.googlegroups.com
Basically the guy is saying the dump file is corrupt.

pg_restore error: pg_restore: [archiver] unsupported version (1.13) in file header

im trying to restore a table from a backup file with pg_restore. However i get the error mentioned above. I read everywhere that an upgraded version of postgres is needed. I upgraded mine to 9.6.8-1 and then 10.3-1. Both did not work. Does anybody have a detailed procedure to fix this problem using a windows OS?
Thanks in advance
Solved for me -
I had the same error restoring from PgAdmin4 on a computer with multiple Postgrsql versions installed. It was calling an older pg_restore version. In PgAdmin I changed the binary path in File/Preferences/Binary Path from $DIR/../runtime to C:\Program Files\PostgreSQL\10\bin and that fixed my issue. I suspect your having a similar issue at which you are unknowingly calling an older pg_restore version even though you updated postgresql.

Postgres and unaccent extension default directory

I need to add an extension called unaccent to my postgres database.
Postgres version PostgreSQL version: 9.3rc1
I have a problem to install the extension.
What i did:
sudo apt-get install postgresql-contrib-9.1
I know it's with 9.1 version, but on my test server i did everyting the same with postgres version 9.4, and everything works.
When i run a script on my production server
CREATE EXTENSION unaccent schema pg_catalog;
it throws me an error :
could not open extension control file "/usr/local/pgsql/share/extension/unaccent.control": Directory or file doesn't exist
What is the problem in this case? Extension has been installed into "wrong" (i guess) directory /usr/share/postgresql/9.1/extension instead of usr/local/pgsql/share/extension
Is there any chance to make postgres look into other directory than default for extensions?
Don't use PostgreSQL 9.3rc1. Just don't. That's not a production version.
You have to install the contrib modules from the same source and in the same version as PostgreSQL core. Everything else won't work.
So this is what you should do:
Upgrade PostgreSQL to something more recent, at leat 9.3.14.
Install the contrib modules from the same provider in the same version.