39

I've got PostgreSQL and pgAdmin installed, but I want to add a PostGIS server so I could work on a Geographic Informations System project.

I'm following this tutorial, which assumes PostGIS is set up. In the previous page of the tutorial, it instructs you to download their software package which includes PostgreSQL and pgAdmin. I already have those installed, so I would like to just add PostGIS but I don't see any way to do so.

Any ideas?

pgAdmin screenshot

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
  • 4
    Install it from StackBulder, which you probably have if you installed PostgreSQL from EnterpriseDB – Mike T Jul 27 '14 at 21:12

4 Answers4

56

Connect to the database using a superuser account (most often the user named postgres but in more recent versions the id of the user who installed the application.) Then issue the following SQL commands to enable PostGIS functionality.

 CREATE EXTENSION postgis;
 CREATE EXTENSION postgis_topology;

You can do this from within pgAdmin or via psql -U [superuser] [database] from a command line.

Alternately for the command adverse; as a superuser; from within pgAdmin right click on your database's Extensions and select New Extension. Then in the drop down associated with Name select the postgis* extensions needed.

jwd630
  • 4,529
  • 1
  • 20
  • 22
  • 2
    pgadmin shows this error when executing these commands: ERROR: could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory SQL state: 58P01 – Tigerware May 19 '21 at 15:16
46

Before adding PostGIS extension to Postgres. You first need to install PostGIS on Ubuntu 14.04

Add PPA from terminal

$ sudo add-apt-repository ppa:ubuntugis/ppa
$ sudo apt-get update

Install PostGIS with apt-get

$ sudo apt-get install postgis postgresql-10-postgis-2.5

After successful installation open psql

$ sudo -u postgres psql

List all databases

postgres=# \l

Connect to specific database

postgres=# \c DATABASE_NAME

Run the following to add PostGIS extension to Postgres

CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;

Exit from psql

postgres=# \q

Thank you

Enkum
  • 635
  • 8
  • 22
aashish
  • 2,453
  • 1
  • 21
  • 19
  • This also might help if you can add it to your answer https://stackoverflow.com/questions/61157620/create-extension-postgis-fails – Enkum Dec 07 '20 at 09:29
5

You don't install it to pgAdmin, it is an extension to Postgres itself. Once it is installed, you add it to a particular database, and its functions, nearly 1000, a few views and the spatial_ref_sys table, will appear in pgAdmin in that db. You can also install it to the template1 db, and then it will be automatically included in any other database that you subsequently create. You can get a binary install from http://postgis.net/install/

John Powell
  • 12,253
  • 6
  • 59
  • 67
2

For PGAdmin installation of extensions:

  1. Right click on the database name listed under the server cascade list, you will see an option "Create Script" - click on it.

  2. This opens up a script with some information on creation/alteration of the DB. Clear this script and then paste the following lines:

    CREATE EXTENSION postgis;

  3. Look at the icons at the top - you will see a RUN icon/button - looks like a "play" icon. Click on it.

  4. Look at the Log output, it should have successfully run the command and installed the extension.

Firsake
  • 71
  • 5