How do I solve a "server version mismatch" with pg_dump when I need BOTH PostgreSQL servers installed?

TL;DR: if both PostgreSQL instances are managed by the Ubuntu packages (as they should), just use the --cluster option to select the PostgreSQL instance to backup, and it will automatically choose the corresponding version of pg_dump:

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

or

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

main is just a default value, run pg_lsclusters to see your actual names in the Cluster column.

How it works: as installed by the Ubuntu packages, /usr/bin/pg_dump is actually a soft-link to /usr/share/postgresql-common/pg_wrapper, whose purpose is precisely to select the correct instance and run the corresponding binary. --cluster does not exist in the stock PostgreSQL commands, it's a Debian/Ubuntu addition that is meant to address this multiple versions/multiple paths problem.

This is the same for psql, createdb, createuser, etc. about 18 postgres commands in /usr/bin are actually managed by pg_wrapper.

See man pg_wrapper for more.


You can use:

sudo find / -name pg_dump

to find your versions of pg_dump in my case: /usr/pgsql-9.6/bin/pg_dump

so next we can do:

sudo ln -sfn /usr/pgsql-9.6/bin/pg_dump /usr/bin/pg_dump

in order to update to the one we need

Tags:

Postgresql