PostGIS Error – Running Create Extension PostGIS Gives ERROR Could Not Open Extension Control File?

centospostgis-2.0postgresql

I have installed PostgreSQL 9.x and PostGIS 1.5/2.0 several times and have never had this problem.

I just got a new CentOS 6.3 server up and running and and I have Postgres 9.3 functioning as expected. I have run

yum install postgis2_93

and I can see the files in

/usr/pgsql-9.3/share/contrib/

however, when I run

CREATE EXTENSION postgis;

I receive

ERROR:  could not open extension control file "/usr/pgsql-9.3/share/extension/postgis.control": No such file or directory

the tutorials (#1, #2) I have used don't show any steps between installing PostGIS and creating the extension.

What am I missing?

Best Answer

I just had the same problem on Ubuntu Server 14.04. I installed the postgis extension from the official Ubuntu repositories using apt-get install postgis.

Then, find /usr -name postgis.control didn't return any results.

The reason was extension/postgis.control wasn't installed because postgis-scripts wasn't.

$ aptitude search postgis
i   libpostgis-java                                  - Geographic objects support for PostgreSQL -- JDBC support 
i   postgis                                          - Geographic objects support for PostgreSQL                 
p   postgis:i386                                     - Geographic objects support for PostgreSQL                 
i   postgis-doc                                      - Geographic objects support for PostgreSQL -- documentation
i   postgresql-9.3-postgis-2.1                       - Geographic objects support for PostgreSQL 9.3             
p   postgresql-9.3-postgis-2.1:i386                  - Geographic objects support for PostgreSQL 9.3             
i   postgresql-9.3-postgis-2.1-scripts               - PostGIS for PostgreSQL 9.3 -- scripts -- dummy package    
i   postgresql-9.3-postgis-scripts                   - Geographic objects support for PostgreSQL 9.3 -- scripts 

The solution is to install it.

On debian-like distros:

apt-get install postgis*

The aptitude package manager will automatically determine the correct package versions to install. The postgis-doc will be installed too.

EDIT

Like some people noticed in comments, the postgis* is not required because it installs some packages not strictly required to just get it to work.

The required packages are postgis and postgresql-9.x-postgis-scripts meta packages. They select the correct real version for your system. So the commands to install the required packages are

 $ sudo apt-get install postgis postgresql-9.3-postgis-scripts

for postgresql-9.3. Ubuntu 16.04 runs postgresql-9.5 so the command becomes:

 $ sudo apt-get install postgis postgresql-9.5-postgis-scripts

You can check the success of the operation by running the following command:

find /usr -name postgis.control

On my server, it now returns:

/usr/share/postgresql/9.3/extension/postgis.control

You can now enable the extension on any database on your postgres server:

  • connect to your db with superuser (postgres by default)
  • run CREATE EXTENSION postgis;

Your public schema now contains all postgis objects and functions.