WARNING: this is only checking if postgres CLIENT is installed (which can be installed WITHOUT installing the server)
psql --version;
AI suggested this:
pg_isready
/var/run/postgresql:5432 - accepting connections
possibly a ubuntu only way is to use absolute path to the binary:
/usr/lib/postgresql/14/bin/postgres --version
postgres (PostgreSQL) 14.13 (Ubuntu 14.13-1.pgdg22.04+1)
/usr/lib/postgresql/12/bin/postgres --version
postgres (PostgreSQL) 12.20 (Ubuntu 12.20-1.pgdg22.04+1)
but it is very bewildering that this is so tricky and that this use case was not documented by postgres developers?
during install a soft link should be put from under /usr/lib/postgresql/14/bin/postgres to /usr/bin
that points to the (lastest?) postgres binary installed, so a simple postgres --version would work and show if postgres SERVER is installed.