When calling pg_dump to backup my database on remote server
pg_dump "postgresql://$DB_USER:$DB_PASS#$DB_HOST:$DB_PORT/$DB_NAME" | gzip > $BACKUP_GZ
I got below error
pg_dump: server version: 11.5 (Debian 11.5-3.pgdg90+1); pg_dump version: 10.14 (Ubuntu 10.14-0ubuntu0.18.04.1)
pg_dump: aborting because of server version mismatch
Currently, I have to try-and-get as coded here to detect when pg_dump failed with the mismatch version and get the remote version there - which is a very tiring process.
So my question is what is fastest way to get that remote pg_dump version on remote server?
Can simply just go for postgres version cause pg_dump/psql shares same version with postgres version
psql "postgresql://$DB_USER:$DB_PASS#$DB_HOST:$DB_PORT" -c 'select version()' -tA
Related
I'm trying to dump a postgres db from a remote client:
pg_dump -Z7 -Fc -h xx.xx.xx.xx -U user dbname > /path/dump/dump.bck
This is the error I received:
pg_dump: server version: 9.4.21; pg_dump version: 9.3.24
pg_dump: aborting because of server version mismatch
The error itself is pretty clear, but unfortunately the remote client where I execute the command is a really old physical file server (ubuntu 14.04) that is impossibile to upgrade.
I have tried to add the postgresql repository in order to install a newer version of pg_dump but the actual os version is not supported anymore.
Is there a way to overcome this problem?
There is no way to overcome the problem except by using a more recent client version. Some options:
install PostgreSQL from source (easier than you think, unless it is Windows)
use a different client machine, e.g. the database server itself
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.
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
While doing database backup using pg_dump utilities I am getting below error.
root#lab1:~# pg_dump -Fc -h localhost -U postgres hrdb -f hrdb.dmp
Password:
pg_dump: server version: 12.0 (Debian 12.0-2.pgdg100+1); pg_dump version: 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)
pg_dump: aborting because of server version mismatch
You seem to have two versions of Postgres installed:
Version 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1), which is pre-packaged with Ubuntu 18.04
Version 12.0 (Debian 12.0-2.pgdg100+1) installed via PGDG Apt repository
You can do any of the following:
Use /usr/lib/postgresql/12/bin/pg_dump by typing out the whole path
Use apt to uninstall postgresql (not postgresql-12)
Ubuntu actually wraps several PG commands into a program called pg_wrapper, so you can actually do the following without having to make any changes: pg_dump -Fc -h localhost -U postgres --cluster=12/localhost:$PGPORT hrdb -f hrdb.dmp
I have a remote postgres DB version 10.8 setup on a linux. I am trying to back it up on windows machine using postgres 9.6.12
pg_dump --host dahost --port 5432 --username "postgres" --no-password --format tar --blobs --verbose --file "path\noury.backup" "highlands_wastewater"
I get these errors
pg_dump: server version: 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1); pg_dump version: 9.6.12
pg_dump: aborting because of server version mismatch
How can I backup this database remotely?
As the error message says, you cannot use an older version of pg_dump with a newer PostgreSQL Version.
The reason behind that is that PostgreSQL 9.6 cannot know how to dump a v10 database properly — there may be new features in the newer version (for example, partitioned tables).
You'll have to install PostgreSQL v10 or later on your Windows machine (exactly v10 if you want to be able to restore the dump to the original database).
Don't use the tar format. The custom format offers more advantages.
I am running ubuntu 14.04. while backing up a database on postgreSQL i am following error:
/usr/bin/pg_dump --host 127.0.0.1 --port 5432 --username "postgres" --no-password --format custom --section pre-data --section data --section post-data --verbose --file "/home/naveen/consumerDB/CONSUMER_DB" "CONSUMER_DB"
pg_dump: server version: 9.4.8; pg_dump version: 9.3.17
pg_dump: aborting because of server version mismatch
Process returned exit code 1.
Can anyone please help. I tried many other stack overflow links but nothing seems to be working.
The error message seems fairly clear. pg_dump for PostgreSQL 9.3 won't dump a PostgreSQL 9.4 database. Maybe you need to run pg_dump from PostgreSQL 9.4?
If you installed both from packages you'll be using pg_wrapper and should use Debian/Ubuntu's update-alternatives to change pg_dump to point to 9.4's pg_dump. Or run it via the direct path to the actual binary.
See also https://help.ubuntu.com/community/PostgreSQL