53

ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/postgis.control": No such file or directory

Is what I get when I try to CREATE EXTENSION postgis; can anybody tell me why is it so and what can I do to fix it?

Xeen
  • 6,955
  • 16
  • 60
  • 111
  • Did you download (and build) the PostGIS extension? It is not included by default in a Postgres installation. –  Sep 09 '13 at 10:23
  • 1
    I installed it using `apt-get install postgis` – Xeen Sep 09 '13 at 10:25
  • Hey Xeen, what is your final solutions.. please update i have same issue...do all below things but not solve still. – harsh4u Jul 23 '14 at 08:15

15 Answers15

27

The following will get you a working postgis install on Ubuntu 12.04 (Note: also tested on 13.10)

echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/postgis.list
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-9.3-postgis-2.1 postgresql-client-9.3
sudo -u postgres psql -c 'create extension postgis;'

Based on the docs at https://wiki.postgresql.org/wiki/Apt

dwurf
  • 12,393
  • 6
  • 30
  • 42
  • postgres 9.1 is still installed, try removing it – dwurf Dec 29 '13 at 04:16
  • 1
    Does neither work with 9.1 nor 9.3 when doing sudo -u postgres psql -c 'create extension postgis;' : FEHLER: konnte nicht auf Datei »$libdir/postgis-2.1« zugreifen: Datei oder Verzeichnis nicht gefunden – Timo Jul 09 '14 at 10:13
  • Thanks buddy i solve same issue after remove 9.1 and install 9.3 – harsh4u Jul 23 '14 at 09:25
  • What about for Windows? – CodyBugstein Sep 10 '14 at 14:27
  • @imray I suggest you [ask a new question](http://stackoverflow.com/questions/ask) for help on Windows. Don't forget to search first :) – dwurf Sep 11 '14 at 01:05
26

You need to install postgresql-9.1-postgis-scripts. In Ubuntu or Debian, you need to run the following command as root:

apt-get install postgresql-9.1-postgis-scripts

This adds the files needed to create the postgis extensions.

Arman H
  • 5,488
  • 10
  • 51
  • 76
Roldan Vargas
  • 361
  • 3
  • 3
  • 1
    I already had this installed, but I can't find the specific control files that my postgres is complaining about. Maybe the database I'm importing is coming from a different version of postgis or something. – James T Snell Jan 07 '15 at 21:40
  • This still works on Ubuntu, substituting `postgresql-9.3-postgis-scripts` for the package. – adc Jan 11 '19 at 02:51
  • 1
    `apt-get install postgresql-XYZ-postgis-scripts` worked for me, where `XYZ` is the major version of PostgreSQL – JPG Apr 14 '21 at 13:04
  • This resolved the issue for me on Ubuntu 20.04! – Ryan Russell Sep 28 '21 at 20:18
11

Installing this package did the trick for me on my Linux Mint 16 box:

# install hstore postgresql extension.
sudo apt-get install postgresql-contrib
Alireza
  • 2,641
  • 17
  • 18
  • I already had this installed, so it's not necessarily the right answer. Still, good to have it posted. +1 – James T Snell Jan 07 '15 at 21:42
  • +1 for this answer as well. It's way to enable extensions. Found solution [here](http://learn.linksprite.com/pcduino/linux-applications/postgresql-error-could-not-open-extension-control-file-usrsharepostgresql9-3extensiontablefunc-control-no-such-file-or-directory/). – zloynemec Dec 07 '15 at 19:50
  • Linux Mint 18 Sarah - installing postgres-contrib-9.4 did the trick – Christian Jensen Aug 03 '16 at 21:16
  • This fixed it for me on a Debian 7 (Wheezy) installation, did not need "postgresql-9.1-postgis" at all. – MarkM Sep 17 '16 at 12:09
5

Daniel Vérité is close to the truth, but not enough. The package missing is postgresql-9.1-postgis-2.0:

sudo apt-get install postgresql-9.1-postgis-2.0
Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86
  • 1
    Not sure which version of Ubuntu you're using. For me on 12.04, Daniel's answer worked but I couldn't find the package you listed. – Jordan Jan 12 '14 at 08:58
  • 2
    I used `sudo apt-get install postgresql-9.1-postgis-2.1`. – Zoltán Feb 04 '14 at 22:31
4

Presumably the postgis version you installed is 1.5.x which doesn't come as an extension, but as a couple of SQL scripts that need to be manually applied to create the necessary SQL objects.

Also the postgis package is not enough, it contains only stuff that doesn't depend on PG version, you need postgresql-9.1-postgis (dpkg -L package-name is handy to check out the files provided by any particular package).

Once the installation paths are known, the official install documentation should be good enough to set up the template database.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
4

Just resolved it. You have to uninstall postgis-1.5. You installed it instaed of PostGIS 2.0. As soon as you will install postgis-2.0 you will see corrected libraries in extension directory. Before installing you should to add a correct repository (see http://docs.pgrouting.org/2.0/en/doc/src/installation/index.html#ubuntu-debian). Use ppa:ubuntugis/ubuntugis-unstable for PostGIS 2.0. Try one of

apt-get remove postgis
apt-get remove postgresql-9.1-postgis
apt-get install postgresql-9.1-postgis

I couldn't remove and install because of dependencies error. After a few attmpts, I just removed postgresql-9.1-postgis and apt-get offer me upgrade it to 2.0.

Shaun McDonald
  • 6,436
  • 2
  • 25
  • 23
3

I had the same problem on my Window 8.1 setup.

I solved it by simply using Application StackBuilder which comes with Postgres and installing PostGIS again (despite not having uninstalled it)

Works fine now!

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
3

In C:\Program Files\PostgreSQL\9.4 I found uninstall-postgis-bundle-pg94x64-2.1.5-2.exe. Running that fixed my problem, which was caused by a reinstall of PostgreSQL without first uninstalling, and without installing PostGIS the second time around. That's what happens when you more than one person installing stuff..

julian
  • 31
  • 1
2

Make sure that you have installed this

sudo apt-get install postgresql-9.3-postgis

I was facing same issue due to missing this package.

vitthal-gaikwad
  • 1,184
  • 11
  • 13
2

On 14.04, there is postgresql-9.3-postgis-scripts, which contains the postgis.control file.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
2

Try this

apt-get install postgis
Susaj S N
  • 960
  • 1
  • 10
  • 22
0

CentOS needs a different package for this problem. For CentOS 6, if you're using the PGDG yum repository at http://yum.pgdgrpms.org/9.3/redhat/, install the postgresql93-contrib package with the command 'yum install postgresql93-contrib.

Update and edit as necessary for PostgreSQL 9.4.

0

I had my worst nightmare while installing Postgis 2.X on SLES 12 SP1. which doesnt have compatible package in zypper repo

Here is how is resolved it on my Postgres server instance running 9.4.X

Prerequsite packages which i have installed prior to PostGis based on the errors

Proj 4 Download source cold, Build --> make install
install Gdal andjibson by adding zypper repo zypper addrepo http://download.opensuse.org/repositories/Application:Geo/SLE_12_SP1_Backports/Application:Geo.repo
zypper install gdal gdal-devel libjson-c-devel libjson

Installing Postgis

Download postgis source code (http://download.osgeo.org/postgis/source/postgis-2.3.0rc1.tar.gz)

Go to Postgis folder 
./configure --with-pgconfig=/usr/lib/postgresql94/bin/pg_config --with-geosconfig=/usr/local/bin/geos-config 
make 
make install

now if you goto postgress DB and create extension postgis; it will work

Important while configuring you should specify pg-config path and geosconfig path and You SHOULD NOT include "without Raster" as RASTER plays main role in creating the postgis extension

0

this work for me

   SELECT PostGIS_full_version();

To create postgisis run above query in query panel

And for remove postgis from your database run bellow query

   drop extension postgis
Sameer Kazi
  • 17,129
  • 2
  • 34
  • 46
0

if you are using windows system download the postgis.bundle.exe and manually install in C:/(PostgreSQLdirectory/version/ ) and that's all .

Harshal
  • 63
  • 1
  • 10
  • Can you expand and explain? OP asked **why**. – toonarmycaptain Nov 01 '17 at 16:26
  • when you are execute `CREATE EXTENSION postgis;` query, it will search the reference file from `"directory/postgresql/version/extension/postgis.control"` location and it's not available, so you can manually install postgis bundle and later you can execute the `CREATE EXTENSION postgis;`query . P.S. you need to checked postgis option in between installation process – Harshal Nov 02 '17 at 06:56