2

I am aware of this question which talks about using SELECT PostGIS_full_version(); but this requires you have a database on which the postgis extension is installed.

I am using a fabric to write a program to check if postgis (above a particular version) is installed on a server and if not, install it. Is this possible?

Community
  • 1
  • 1
lac
  • 755
  • 10
  • 19

2 Answers2

4

Every Postgres server contains a database called postgres.

You can connect to this database and query the pg_available_extensions or pg_available_extension_versions tables to see which versions of PostGIS are installed on the server.

Nick Barnes
  • 19,816
  • 3
  • 51
  • 63
0

You can connect to the postgres database (created when postgresql is installed) and execute

SELECT extversion
FROM pg_catalog.pg_extension
WHERE extname='postgis'

If you get a result, it will be the postgis version.

Matias Barone
  • 168
  • 1
  • 8
  • `pg_extension` only shows the extensions installed in that particular database. For the `postgres` database, there will generally be nothing in there besides `plpgsql`. – Nick Barnes Jun 11 '16 at 02:58
  • In all installations I can check, there was `postgis extension` in `postgres` database. – Matias Barone Jun 27 '16 at 12:31
  • Someone/something must have created the extension manually; it shouldn't be installed there by default. – Nick Barnes Jun 28 '16 at 03:04