3

hello i was trying to install postgis to one of my database with the following command

CREATE EXTENSION postgis;

but it returned an error of

ERROR:

could not open extension control file "/Library/PostgreSQL/13/share/postgresql/extension/postgis.control": No such file or directory

how do i install postgis without it giving an error?

UPDATE: I have tried it on the default databases postgres.app gives you which is your desktop username(mine is aarushsharma), i tried to do

CREATE EXTENSION postgis;

and it worked so i think it is a problem to do with my specific postgres user

aarush_s
  • 91
  • 1
  • 1
  • 7
  • How did you install Postgres? Have you downloaded/installed the PostGIS package? Are you running the `CREATE EXTENSION postgis` as a superuser? – Adrian Klaver Feb 28 '21 at 16:42
  • i installed it through the postgres app. I don't know how to get the POSTGIS package. yes i am running it as postgres which has all the superuser permissions – aarush_s Feb 28 '21 at 16:46
  • Postgres app does not really tell me anything. What OS are you on, where did you get Postgres from? – Adrian Klaver Feb 28 '21 at 16:51
  • @AdrianKlaver i am on macOS and i downloaded postgres from here https://postgresapp.com/#:~:text=Postgres.app%20is%20a%20full-featured%20PostgreSQL%20installation%20packaged%20as,user%20interface%20and%20a%20convenient%20menu%20bar%20item. – aarush_s Feb 28 '21 at 19:15
  • In `psql` what does `\dx` show? Does "/Library/PostgreSQL/13/share/postgresql/extension/postgis.control" exist? Do you have more then one installation of Postgres on this machine? – Adrian Klaver Feb 28 '21 at 19:39
  • @eshirvana, Postgres.app includes PostGIS, so downloading it is not necessary. – Adrian Klaver Feb 28 '21 at 19:41
  • @AdrianKlaver i did \dx and this is what it gave List of installed extensions Name | Version | Schema | Description -----------+---------+------------+----------------------------------------- adminpack | 2.1 | pg_catalog | administrative functions for PostgreSQL plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (2 rows) – aarush_s Feb 28 '21 at 22:53
  • The presence of `adminpack` leads me to believe you are working with an install from here [EDB](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads) not the `Postgres.app` – Adrian Klaver Mar 01 '21 at 00:59
  • @AdrianKlaver i did also install pgadmin before but then i deleted it maybe that has something to do with the adminpack – aarush_s Mar 01 '21 at 13:21

3 Answers3

2

first you need to download and install Postgis if you haven't , follow this.

if you are on Linux , you have to install 2 packages ,postgis and postgresql-13-postgis-3

only PostGIS 3,0 and above works with Postgresql 13 :

commands on Debian based distros ( I installed from PostgreSQL repository) :

sudo apt install postgis postgresql-13-postgis-3

on mac you can install it via brew by running this command in terminal:

brew install postgis

if you don't have brew installed then install it first :

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If you have installed using postgressApp, Open the Terminal and enter the following two commands: actually first follow step 3 from Installing Postgres.app documentation:

sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

then :

psql -d DATABASE_NAME -f /Applications/Postgres.app/Contents/Versions/[Postgresqlversion]/share/postgresql/contrib/postgis-[PostGisVersion]/postgis.sql

psql -d DATABASE_NAME -f /Applications/Postgres.app/Contents/Versions/[Postgresqlversion]/share/postgresql/contrib/postgis-[PostGisVersion]/spatial_ref_sys.sql

then you should be able to enable the extension :

CREATE EXTENSION postgis;
eshirvana
  • 23,227
  • 3
  • 22
  • 38
  • hi i am on mac so is there a different command for mac – aarush_s Feb 28 '21 at 19:15
  • @aarush_s see my updated answer , added instruction for Mac OS , hopefully that solve the issue – eshirvana Feb 28 '21 at 19:45
  • it gives an error when i do psql -d fudo -f /Applications/Postgres.app/Contents/Versions/13.2/share/postgresql/contrib/postgis-3.1.1/postgis.sql -U postgres of psql: error: /Applications/Postgres.app/Contents/Versions/13.2/share/postgresql/contrib/postgis-3.1.1/postgis.sql: No such file or directory – aarush_s Feb 28 '21 at 22:51
  • hmm... can you find any part of that path in you file manager (dolphin)? or have you other installation of postgresql from other method? If yes I suggest remove them and reinstall – eshirvana Feb 28 '21 at 23:16
  • i did install pgadmin does that clash with postgres? – aarush_s Mar 01 '21 at 09:09
  • Probably not , I don’t think that is a problem – eshirvana Mar 01 '21 at 14:34
  • i have just also tried on my other laptop which runs on ubuntu 20.04 and it still gives the same error but instead of 13 it says 12 – aarush_s Mar 05 '21 at 16:56
  • then run the same command but instead of 13 put 12 : `sudo apt install postgis postgresql-12-postgis-3` – eshirvana Mar 05 '21 at 17:13
2

I had the same error on Windows + Postgres 14.

On Windows you have to launch "Application Stack Builder" and add extension Postgis as said here : http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_tut01

then you should be able to create the extension.

Alexandre Hamon
  • 1,162
  • 12
  • 13
0

This worked for me with Ubuntu/Debian and PostgreSQL14

apt install postgis
apt install postgresql-14-postgis-scripts
CREATE EXTENSION postgis;
qwerty
  • 1,451
  • 13
  • 10