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.
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.
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.
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.
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:
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!!
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: ...
Assuming that you have access to your database (either through the terminal or the pgadmin application), try the following:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With