Postgresql 13.9 pg_dump 12.12 server version mismatch - postgresql

While taking the backup of the postgressql database I am getting below issue
pg_dump -Fc -h localhost -U postgres -d <user> -f <filename>`
pg_dump: error: server version: 13.9; pg_dump version: 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)
pg_dump: error: aborting because of server version mismatch
Can anyone help me with this issue and help us to take the appropriate backup?

Related

How to get remote pg_dump version?

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

Using pg_dump and psql ,pg_restore not working for migration Postgres from 9.6.11 to 9.6.18

Source db is Postgres RDS 9.6.11 version
Target db is Postgres RDS 9.6.18 version
I am trying to migrate the data from source to target db using postgres native tools.
But Its not working for me..
pg_dump --host qatest.us-east-1.rds.amazonaws.com -c -Fc -U username -d username >qadump_original_fc.sql
pg_restore -U postgres -d postgres -Fc -h qatest.us-east-1.rds.amazonaws.com qadump_original_fc.sql
pg_restore: [archiver] did not find magic string in file header
pg_restore -U postgres -d postgres -h qatest.us-east-1.rds.amazonaws.com qadump_original_fc.sql
pg_restore: [archiver] input file does not appear to be a valid archive
Using psql to import throwing multiple errors like Invalid large objects,syntax error etc,.
I have tried with and without -Fc in pg_dump for pg_restore and psql, but no luck.

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.
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

How do I solve a pg_dump: aborting because of server version mismatch?

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

pg_dump: aborting because of server version mismatch

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