10

I wanted to know if there is a way to determine that PostGis was enabled on a database.

I am trying to replicate my production server with my dev machine and I am not sure if the database on my dev machine had either PostGIS or postgis_topology enabled or both.

I tried looking around for a solution but could not come up with anything.
Any suggestions in this regard would be helpful.

John Moutafis
  • 20,172
  • 8
  • 64
  • 108
MistyD
  • 14,915
  • 32
  • 126
  • 215
  • Possible duplicate of [Using psql how do I list extensions installed in a database?](https://stackoverflow.com/questions/21799956/using-psql-how-do-i-list-extensions-installed-in-a-database) –  Nov 26 '18 at 10:06

2 Answers2

10

Assuming that you have access to your database (either through the terminal or the pgadmin application), try the following:

  1. Connect to your database
  2. Run one (or both in order if you like) of the following queries:

    SELECT PostGIS_version();
    SELECT PostGIS_full_version();
    

if no error occurs, then you have PostGIS enabled for that database.


References:
John Moutafis
  • 20,172
  • 8
  • 64
  • 108
5

I'd just like to add to John Moutafis' response since at this point I can't comment on an answer.

My situation was a bit different because I had created the postgis extension for a different schema, let's call it schema_name:

CREATE EXTENSION postgis SCHEMA schema_name

Just running the accepted answer's query gave me an error stating that "No function matches the given name and argument types". Instead I had to make sure to add the schema name prior to the function call, as depicted below:

SELECT schema_name.PostGIS_version();
SELECT schema_name.PostGIS_full_version();

That ended up working for me.

Alexandre
  • 101
  • 1
  • 6