According to the PostGIS documentation, only
Some packaged distributions of PostGIS ... load the PostGIS functions into a template database called template_postgis.
So, not every distribution comes with template_postgis
.
As said in existing answers, in PostGIS 2.x, it is easy to create or customize the template yourself by creating a regular database named template_postgis
as superuser, and then creating the required and optional extensions (such as pgRouting). Per PostGIS documentation:
sudo su postgres
createdb template_postgis
psql -d template_postgis -c "CREATE EXTENSION postgis;"
psql -d template_postgis -c "CREATE EXTENSION postgis_topology;"
-- if you built with sfcgal support --
psql -d template_postgis -c "CREATE EXTENSION postgis_sfcgal;"
In addition, you can mark this newly created database as a template database by setting the datistemplate
flag in the system table pg_database
to ture
.
psql -d template_postgis -c "UPDATE pg_database SET datistemplate = 'true' WHERE datname = 'template_postgis';"
This will, e.g., prevent the template database from being accidentally dropped or altered by other users or yourself. (You will need to set the flag to false if you want to make changes to the template.)
Then you can create spatial database based on whatever you put into the template:
createdb -T template_postgis my_spatial_db