Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if postgis is enabled on a database?

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.

like image 852
MistyD Avatar asked Nov 24 '18 22:11

MistyD


People also ask

How do I know my PostGIS version?

You can find the version installed by issuing a select PostGIS_full_version(); query with psql or another tool. To install the absolute latest version of PostGIS, you can use the following commands.

Does PostGIS come with PostgreSQL?

The latest release version now comes packaged with the PostgreSQL DBMS installs as an optional add-on. As of this writing PostGIS 3.1. 4 is the latest stable release and PostGIS 3.2.

What is PostGIS in PostgreSQL?

PostGIS is an extension to the PostgreSQL database management system developed by the Canadian company Refractions Research Inc. The extension allows to store and manage Geographic Information Systems (GIS) objects in PostgreSQL. It is available on Scaleway Databases.

How do I check if PostGIS is installed or not?

Determining the PostGIS version Your server may also have PostGIS installed. To determine the version installed on your server, log in to PostgreSQL from the command line using the psql program, and then type the following query:

How do I create a PostGIS spatial database?

Enter the following query into the query text field to load the PostGIS spatial extension: Click the Play button in the toolbar (or press F5) to “Execute the query.” Now confirm that PostGIS is installed by running a PostGIS function: You have successfully created a PostGIS spatial database!!

How do I run a PostGIS query in SQL?

Click on the SQL query button indicated below (or go to Tools > Query Tool ). Enter the following query into the query text field to load the PostGIS spatial extension: CREATE EXTENSION postgis; Click the Play button in the toolbar (or press F5) to “Execute the query.”. Now confirm that PostGIS is installed by running a PostGIS function: ...


2 Answers

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:
  • https://postgis.net/docs/PostGIS_Version.html
  • https://postgis.net/docs/PostGIS_Full_Version.html
  • https://ase-research.org/training/PostGIS_2016/install.shtml#post4
like image 101
John Moutafis Avatar answered Oct 16 '22 02:10

John Moutafis


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.

like image 36
Alexandre Avatar answered Oct 16 '22 01:10

Alexandre