[GIS] Spatially enabled Postgres database

postgisspatial-databaseUbuntu

I am trying to create a spatially enabled PostGIS database. I am following the PostGIS documentation, http://postgis.net/docs/manual-1.5/ch02.html#id2648455.

In the short version, i executed,

createdb yourdatabase
createlang plpgsql yourdatabase

But I did not execute the last three commands,

psql -d yourdatabase -f postgis.sql
psql -d yourdatabase -f postgis_comments.sql
psql -d yourdatabase -f spatial_ref_sys.sql

Is my database still spatially enabled? If not, then can you tell me where these .sql files are located so I can execute those last commands, since I am getting the following error,

postgis.sql: No such file or directory

I am using Ubuntu 12.04

Best Answer

If you have Ubuntu 12.04, then you should have PostgreSQL 9.1, which makes things awesome for PostGIS 2.0, where you can use use the new EXTENSION framework. To spatially enable a database, use the DDL from a SQL window:

CREATE EXTENSION postgis;

See other details for installing PostGIS 2.0 from source for Ubuntu 12.04 here.


If you are using PostGIS 1.5, you will need the enabler scripts on "mydb", run from the shell:

sudo -u postgres createdb mydb
sudo -u postgres psql -d mydb -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
sudo -u postgres psql -d mydb -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
sudo -u postgres psql -d mydb -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis_comments.sql