I'm having trouble starting postgres as you can see below:
$ pg_ctl -D /usr/local/var/postgres start
server starting
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.1, which is not compatible with this version 9.3.0.
Anyone know how to make the versions compatible?
You have two choices:
Run 9.1 version, dump your database and restore it using 9.3
http://www.postgresql.org/docs/9.3/static/pgupgrade.html
Related
I'm using a Linux server, I want to upgrade postgresql from the version 9 to 11. I have created a dump of my database. Then I have installed postgresql 11, now I want to import the dump to postgresql 11, I run the command
pg_restore -h localhost -d dbLitstUsers -U postgres .dataBasebackup but get the error
pg_restore: [archiver] unsupported version (1.14) in file header
How can I fix this error ?
You must have used a pg_dump from v12 or higher. That generates a custom dump in a format (1.14) which is not compatible with older pg_restore. Retake the dump with the pg_dump coming with the version you want to restore to.
My default Postgres (installed via brew) is at v14, and I can't start it because the files are at version 12:
DETAIL: The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 14.0.
I can't upgrade the files:
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
Error: Failure while executing; `/usr/local/opt/postgresql/bin/initdb --lc-collate=C --lc-ctype=C --lc-messages=C --lc-monetary=C --lc-numeric=C --lc-time=C -E\ UTF8 /usr/local/var/postgres` exited with 1.
There is also this error when I do brew services:
postgresql error /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist
I have version #12 installed but when I open it I can't see the databases in my default install.
What is the best path forward to resolve this?
On your postgres 12 set the folder where the data you need (or a copy of this folder) as the working folder for postgres 12. Do pgdump on this version and then pg_restore on postgres 14.
Use the next link to identify the working folder:
Where does PostgreSQL store the database?
I have a postgres 12 database in use on heroku with postgres 11 installed on my macOS workstation. When I try to restore the file provided to me by Heroku, I get
$ pg_restore --verbose --no-owner -h localhost -d myapp_development latest-heroku.dump
pg_restore: [archiver] unsupported version (1.14) in file header
According to Heroku's documentation, they make it sound like the only option is that if a Heroku user wants to access their data locally, they must be running postgres 12? That seems silly.
Digging into the Postgres docs on this topic, they say:
pg_dump can also dump from PostgreSQL servers older than its own version. (Currently, servers back to version 8.0 are supported.)
Which certainly sounds like it should be possible to specify a target version of pg_restore to be used by pg_dump? But nowhere on the internet does there seem to be an example of this in action. Including the postgres docs themselves, which offer no clues about the syntax that would be used to target the "dump versions back to version 8.0".
Has anyone ever managed to use the pg_restore installed with postgres 11 to import a dump from the pg_dump installed with postgres 12?
The best answer to this that I figured out was to upgrade via brew upgrade libpq. This upgrades psql, pg_dump and pg_restore to the latest version (to link them I had to use brew link --force libpq). Once that upgrade was in place, I was able to dump from the postgres 12 databases on heroku, and import into my postgres 11 database locally. I thought I might need to dump to raw SQL for that to work, but thankfully the pg-12 based pg_restore was able to import into my postgres 11 database without issue.
pg_restore will refuse to handle a dump with a later version than itself - basically, if it encounters a file "from the future", it cannot know how to handle it.
So if you dump a database with pg_dump from v12, pg_restore from v11 cannot handle it.
The solution, as you have found out, is to upgrade the v11 installation.
I have installed postgresql 9.2 and 9.6 in centos 7 and created separate service for them. How do I run both versions in same server? They are using the same port.
When I try to start the 9.2 server its working fine, but when I stop the 9.2 server and start 9.6, I get a warning that postgres client version is 9.2. i have installed 9.6 client but psql is by default taking the older version. How do we resolve this?
Will we be able to restore postgresql 9.2 backup in postgresql 9.6? Will there be any data structure level change required to restore 9.2 backup in 9.6? I am completely new to postgresql.
I have installed postgresql 9.2 and 9.6 in a vm.will normal backup and restore work in this scenario.
Ad 1:
That will work just fine if you change the port.
Normally all you have to do is to change the port setting in the postgresql.conf configuration file of the database instance and restart.
Ad 2:
You cannot take a dump taken with 9.2 and restore it into 9.6.
Or rather: you can, but there is a good chance that the import will fail or some things will not be restored correctly.
What you have to do is take a dump of the 9.2 database using pg_dump from the 9.6 installation.
9.6 is aware of the differences to 9.2 and is able to create a dump that can be loaded into 9.6, while 9.2 cannot know what “will be” different in 9.6.
I exported a postgresql database from an external server, and attempted to import it into my local server but got this error:
unrecognized configuration parameter "idle_in_transaction_session_timeout"
Does this kind of error mean that the two servers are using different versions of postgresql? I looked into that, and the external server is running:
version
PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
and my server is running:
version
PostgreSQL 9.5.5 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609, 64-bit
Pretty much the same thing. Is there a site where you can see all of the valid config parameters for each version? And is there a way to sync up two databases like this, so incompatibilities like this get patched up automatically?
According to Postgresql 9.6 Release Notes the idle_in_transaction_session_timeout parameter was introduced in version 9.6.
E.2.3.1.10. Server Configuration
Allow sessions to be terminated automatically if they are in
idle-in-transaction state for too long (Vik Fearing)
This behavior is controlled by the new configuration parameter
idle_in_transaction_session_timeout. It can be useful to prevent
forgotten transactions from holding locks or preventing vacuum cleanup
for too long.
Since you are using version 9.5 on the server, the parameter is not recognized.
It's possible that you used version 9.6 of the Postgresql client to export data from the the source 9.5 server and the parameter was introduced in the dump file. If this was the case I would recommend using a 9.5 client version to export and import the data.
The accepted answer is the way to go, but if for some reason you can not upgrade version, here is a workaround.
Export using plain text. You probably want to use compression too. pg_dump -F c -Z 9 dbname > file.zip
Before import, we need to remove the offending parameter. To do that we can use zcat and grep. zcat file.zip | grep -vw "idle_in_transaction_session_timeout" | psql -d newdb
Note that there are drawbacks using psql instead of pg_import. For instance, one can not use the -j to import concurrently.