1

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)

However, 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

pg_lsclusters yields:

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.

[EDIT 2019-02-10]

The comment by @steeldriver put me on the right track. My Ansible role was installing postgresql-9.6 and 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 postgresql-11.

  • 2
    What packages did you uninstall / replace exactly? AFAIK the psql binary would be part of the client package (e.g. postgresql-client-11) – steeldriver Feb 6 '19 at 13:53
1

The comment here is completely and totally accurate. You can easily confirm this by utilizing the sadly underused Ubuntu Package Search which for 18.04 reports that psql is part of postgresql-client-common

psql is reporting the version of psql installed as expected.

If you want to see the version of a package that you have installed dpkg -l packagename is useful.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.