I have been working on an Ansible script for defining the standard template of our corporate servers. For some historical reasons, we chose to stick with PostgreSQL 9.6 even though we're using Ubuntu 18.04, which comes with PostgreSQL 11. We intend to catch up with the latest version after a transition phase of some months.
The 18.04 image we use from AWS has PG 11. After uninstalling version 11 and installing 9.6 on our test server, the result of
psql --version is still:
psql (PostgreSQL) 11.1 (Ubuntu 11.1-3.pgdg18.04+1)
apt-cache policy postgresql-11 gives me:
postgresql-11: Installed: (none) Candidate: 11.1-3.pgdg18.04+1 Version table: 11.1-3.pgdg18.04+1 500 500 http://apt.postgresql.org/pub/repos/apt bionic-pgdg/main amd64 Packages
Ver Cluster Port Status Owner Data directory Log file 9.6 main 5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log
I find all that misleading, even in the light of the fact that
psql will talk to the server listening on 5432. I'd rather leave things in a consistent and explicit state, and not run the risk of some compatibility problems in our scripts.
My question is: is it possible to fix the version reported by psql so that it can report a version that is actually present?
I feel like the removal of version 11 left some remnants which appear unwanted to me, despite of the task specifying purge and autoremove.
The comment by @steeldriver put me on the right track. My Ansible role was installing
postgresql-contrib, which didn't make sense because as I understood it, without the specification of
9.6 as the version,
postgresql-contrib would stand for its current most up-to-date package, which is
postgresql-contrib-11, which in turn has
postgresql-11 as a dependency.
I ended up with versions 9.6 and 11, and erroneously thought that the Amazon image had postgresql-11 in it. I was wrong.
When I removed
postgresql-11 (with autoremove) the uninstallation still left behind the
/var/lib/postgresql/11/bin folder, where a
psql binary remained. The wrapper that launches PostgreSQL binaries enumerates the versions in
/var/lib/postgresql and for each, checks whether the
psql binary is on the filesystem. If it is, then the most recent version is used.
With the comments and answers, I now understand that this is certainly because the package to remove was a flavor of
postgresql-client-common and not just