25

I originally installed postgres 9.2 on Ubuntu and later upgraded to 9.3 according to the instructions here: http://www.postgresql.org/download/linux/ubuntu/ (using the postgres apt repository).

However, pg_dump, which is an alias for /usr/share/postgresql-common/pg_wrapper, did not get upgraded.

pg_dump: server version: 9.3.4; pg_dump version: 9.2.8 pg_dump: aborting because of server version mismatch 

How do I upgrade this? I have tried to figure out which packages require update, but I'm not really even sure that that's the correct thing to do.

1

8 Answers 8

14

Turns out that installing the 9.3 client does not auto uninstall the 9.2 client, and if they're both on the machine like this, then that's what you get. The answer is to remove the postgresql-client-9.2 (or whatever the appropriate old version is in your case).

2
  • 4
    For upgrading client: Add the postgresql repo like this postgresql.org/download/linux/ubuntu Then run apt-cache search postgresql-client-9and pick whichever suits your needs. Commented Feb 20, 2015 at 14:54
  • 2
    You might want to also know that upgrading pg_dump first requires apt-get --only-upgrade install postgresql-client after which you have to uninstall the previous client version: apt-get --purge remove postgresql-client-9.2, for example. Commented Jan 27, 2016 at 6:05
10

If you need to have several versions of postgresql client same time you may use

pg_dump --cluster 9.2/main [other pg_dump options] 

for old cluster and

pg_dump --cluster 9.3/main [other pg_dump options] 

for new

View accepted answer on askubuntu for details: https://askubuntu.com/a/647341/1044581

9

I managed to fix my issues by uninstalling the postgresql client

sudo apt-get remove postgresql-client-common 

And then re-installing

 sudo apt-get install postgresql-client-11 
4
  • 1
    E: Unable to locate package postgresql-client-11 ... is there some way to update the postgres index Commented Aug 8, 2019 at 23:36
  • I believe that you might need to update your apt indexes, as I don't know if postgresql package is part of the default index set. try googling 'install postgresql 11 on ubuntu' for more details. Commented Aug 9, 2019 at 7:36
  • Here is an explicit link to installing postgresql 11 client tools: computingforgeeks.com/install-postgresql-11-on-ubuntu-linux Commented Jul 5, 2020 at 9:16
  • 3
    You might need to add a repository for the latest prostgres versions: postgresql.org/download/linux/ubuntu Commented Dec 16, 2021 at 10:26
6

you may want to check output of the command

dpkg -l | grep postgres

to see which versions are installed and active pg_dump is usually part of postgresql-client-common package.

(And edit your question, It is not clear how did you upgrade from version 9.3 to 9.3 ... )

5

tl:dr; no need to uninstall old clusters. Instead, put the following in ~/.postgresqlrc

<version> <clustername> <defaultdb>,

e.g., 9.6 main *


It's not necessary to uninstall old clusters. I looked in /usr/share/postgresql-common/pg_wrapper, which has these lines:

# for psql we always want the latest version, as this is backwards compatible # to every major version that that we support if ($cmdname eq 'pg_wrapper') { error "pg_wrapper should not be called directly, but through a symlink"; } elsif ($cmdname =~ /^(psql|pg_archivecleanup|pg_isready)$/) { $cmd = get_program_path ($cmdname, get_newest_version); } else { $cmd = get_program_path ($cmdname, $version); } 

In other words, commands like psql will always be run with the latest installed version installed on your machine, but commands like pg_dump will not.

At the top of pg_wrapper is a hint:

# Call a PostgreSQL client program with the version, cluster and default # database specified in ~/.postgresqlrc or # /etc/postgresql-common/user_clusters. 

man postgresqlrc tells us that ~/.postgresqlrc should be formatted thusly:

<version> <cluster name> <default database

pg_lsclusters gave me the following output:

Ver Cluster Port Status Owner Data directory Log file 9.5 main 5432 online postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log 9.6 main 5433 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log 

Which meant that my ~/.postgresqlrc should look like this:

9.6 main *

Which gives me the desired version when I run pg_dump -V.

2
  • 1
    Very useful debug info. I noticed after installing the main binary with apt install postgresql-15 (instead of postgresql-client-15), the pg_lsclusters entry highlighted in green instead of red. It didn't change the default version for pg_dump, but put me on track to understanding what was happening. Commented Jun 17, 2023 at 5:27
  • Swapping the port numbers in the Postgresql config changed the default version I got when running pg_dump. Whichever version used port 5432 is the one that becomes the default. (As in, sudo vi /etc/postgresql/15/main/postgresql.conf, update the port entry, and do the same for whatever other version is installed). Commented Jun 17, 2023 at 5:30
3

I was also facing same issue. First, I removed old pgdump versions. Mostly it is part of postres-client. So, remove them by using

apt-get remove postgresql-client-common

Install the version as per your requirement, by executing following commands. I am using ubuntu 16.04. Replace, "xenial" by your ubuntu version, in the first command. Command to check ubuntu version-
cat /etc/os-release

$ echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-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
$ apt-cache search postgresql | grep postgresql-client
$ apt-get install postgresql-client-9.5

2

To use a specific version of pg_dump

/usr/lib/postgresql/13/bin/pg_dump 

You can also run find / -name 'pg_dump' to find available paths

result of command

0

Ejecuta find / -name 'pg_dump' Resultado /usr/bin/pg_dump /usr/pgsql-9.4/bin/pg_dump

su - postgres Prueba /usr/bin/pg_dump database > database52.sql /usr/pgsql-9.4/bin/pg_dump database > database52.sql

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.