PostGIS needs to be installed per database. Existing databases are not altered automatically. Run the install script as follows.
In PostgreSQL 8.4 you may also need to create the language plpgsql. For 9.0+ it is the default procedural language and installed automatically. In your database:
createlang plpgsql yourdatabase
Can't do harm. If plpgsql is already installed it will just yield an error telling you so.
Go to the install dir. In Debian Squeeze the contrib packages lie here (may be different in Ubuntu). In a shell:
cd /usr/share/postgresql/8.4/contrib/postgis-1.5
Then execute (as postgres user or you have to provide username / pw):
psql -d yourdatabase -f postgis.sql
psql -d yourdatabase -f spatial_ref_sys.sql
You may also want to install the comments to your shiny new functions (optional). In Debian Squeeze the install file lies in the /contrib main directory:
cd /usr/share/postgresql/8.4/contrib
psql -d yourdatabase -f postgis_comments.sql
If you want PostGIS to be installed with every new database in the cluster by default, install it to your template1
database also. Read more about that in the manual.
Sources for PostGIS installation (on Ubuntu):
http://postgis.net/docs/manual-2.1/postgis_installation.html
http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
PostgreSQL 9.1+
With PostgreSQL 9.1 or newer you can use the more convenient CREATE EXTENSION
:
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
Your distribution is probably shipping the extension ready for installation. If not, consider the chapter "Building PostGIS Extensions and Deploying them" in the PostGIS manual.