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
.