Question

I am following this tutorial

http://technobytz.com/install-postgis-postgresql-9-3-ubuntu.html

and i created db with this command

createdb test_db -T template_postgis2.1

but i get this error

test_db2=# select postgis_version();
ERROR:  function postgis_version() does not exist
LINE 1: select postgis_version();

This works if use

create extension postgis

i want to know that is that ok or i have error. because i made the template before. Didn't that template automatically make the db as postgis

Était-ce utile?

La solution

According to the official documentation on the topic, you have to create the extension in each new database you create. Why? This has to do with a change in the way a database is PostGIS-enabled in PostgreSQL-9.1+ and PostGIS-2+. Previously, there were a series of scripts that had to be run to load the functions, types, and other features of PostGIS into a database. Consequently, the best practice was to create a template database (template_postgis, etc.), run all the scripts against that template, and create each new PostGIS-enabled database against that template. In newer versions of PostgreSQL (9.1+), you can enabled PostGIS support within a new database by simply executing the command CREATE EXTENSION postgis; as such, you should skip the template step entirely.

So to sum up:

  • CREATE EXTENSION postgis; is the way to go for PostgreSQL-9.1+ and PostGIS-2+
  • Making a template database is the way to go for prior versions of PostgreSQL or PostGIS.

I hope that helps clear it up!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top