From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — PostGIS/Installation
Afrikaans Alemannisch aragonés asturianu azərbaycanca Bahasa Indonesia Bahasa Melayu Bân-lâm-gú Basa Jawa Baso Minangkabau bosanski brezhoneg català čeština dansk Deutsch eesti English español Esperanto estremeñu euskara français Frysk Gaeilge Gàidhlig galego Hausa hrvatski Igbo interlingua Interlingue isiXhosa isiZulu íslenska italiano Kiswahili Kreyòl ayisyen kréyòl gwadloupéyen Kurdî latviešu Lëtzebuergesch lietuvių magyar Malagasy Malti Nederlands Nedersaksies norsk bokmål norsk nynorsk occitan Oromoo oʻzbekcha/ўзбекча Plattdüütsch polski português português do Brasil română shqip slovenčina slovenščina Soomaaliga suomi svenska Tiếng Việt Türkçe Vahcuengh vèneto Wolof Yorùbá Zazaki српски / srpski беларуская български қазақша македонски монгол русский тоҷикӣ українська Ελληνικά Հայերեն ქართული नेपाली मराठी हिन्दी অসমীয়া বাংলা ਪੰਜਾਬੀ ગુજરાતી ଓଡ଼ିଆ தமிழ் తెలుగు ಕನ್ನಡ മലയാളം සිංහල ไทย မြန်မာဘာသာ ລາວ ភាសាខ្មែរ ⵜⴰⵎⴰⵣⵉⵖⵜ አማርኛ 한국어 日本語 中文(简体)‎ 吴语 粵語 中文(繁體)‎ ייִדיש עברית اردو العربية پښتو سنڌي فارسی ދިވެހިބަސް

The following instructions describe how to install PostgreSQL and PostGIS on Linux and Windows, create the appropriate spatial databases, and tune database parameters for better performance. Please see the Mapnik page for more information on using Mapnik to render OpenStreetMap data.

In these examples, gisuser is used as the name of the user and gis is used as the name of the database

The main OpenStreetMap Mapnik styles make use of PostgreSQL and PostGIS as part of the rendering pipeline. Creating a database is the same or similar for osmosis and osm2pgsql.

It is recommended to use PostgreSQL >= 9.3. Version 9.0 and older are end of life.

Install PostgreSQL and PostGIS

Ubuntu and Debian

sudo apt-get install postgresql postgresql-contrib postgis
OS X Leopard

Assuming you have darwinports,

% sudo port install postgresql83
% sudo port install postgis

or use the Mac OS X installers at KyngChaos.


As root:

Fedora 16 Fedora 17 and above
yum install postgis postgresql-server
postgresql-setup initdb
service postgresql start
yum install postgis postgresql-server
postgresql-setup initdb
systemctl start postgresql
openSUSE 13.1

To let the package manager know about PostGIS, you have to add a community package repository:

sudo zypper ar "Geo"
sudo zypper refresh

Then you can install PostGIS:

sudo zypper install postgis postgresql-contrib

There are setup executables for PostGIS. Download the installer that matches your PostgreSQL version and run it. Your PostgreSQL server must be running. This will install some files in a subdirectory of your PostgreSQL installation and two database tables.


Installing osm2pgsql will pull postgres and postgis as dependencies:

emerge osm2pgsql

Or you can install them explicitely with emerge postgresql-server postgis. The config file for pg_ctl will be in /etc/conf.d/postgresql-8.3 and for the server itself there'll be a sample file in /usr/share/postgresql-8.3/postgresql.conf.sample You can configure the cluster using emerge postgresql-server --config or manually if you want to customise it, then start it with /etc/init.d/posgresql-8.3 start before proceeding with the createuser instructions below.

Create database


On most systems you need to be authenticated as the PostgreSQL super user (usually named postgres) in order to execute many of the commands below.

sudo -u postgres createuser gisuser
sudo -u postgres createdb --encoding=UTF8 --owner=gisuser gis

These commands can be issued from the Admin tool GUI or run by navigating to the bin directory (e.g. C:\Program Files\PostgreSQL\8.3\bin) in an command prompt run as Administrator, then running:

C:\Program Files\PostgreSQL\8.3\bin\createuser -U postgres gisuser
C:\Program Files\PostgreSQL\8.3\bin\createdb -U postgres -E UTF8 -O gisuser gis
C:\Program Files\PostgreSQL\8.3\bin\createlang -U postgres plpgsql gis

If needed, the commands 'dropdb gis' and 'dropuser gisuser' can be used. In particular, you might find it necessary to make the user a postgres administrator (you will be asked for this when creating the user), to simplify user permissions.

openSUSE 13.1

You have to create a user in Postgresql that will be used to create all tables and data. Then some SQL scripts containing vital mapping-related instructions need to be executed. These instructions generate the user gisuser and the password "something". To change that, replace all occurences of "gisuser" and "something", respectively.

sudo su -c "createuser --superuser gisuser" postgres
sudo su -c "createdb -E UTF8 -O gisuser gis" postgres
sudo su -c "createlang plpgsql gis" postgres
echo "ALTER USER gisuser WITH PASSWORD 'something';" | psql -d gis

Please note: using the default openSUSE 11.2 configuration of PostgreSQL, you will definitely run in to this issue: Mapnik#Authentication failed. Follow the steps listed there to fix it.

Activate PostGIS

You need to activate PostGIS on the newly created database.

psql --username=postgres --dbname=gis -c "CREATE EXTENSION postgis;"
psql --username=postgres --dbname=gis -c "CREATE EXTENSION postgis_topology;"

Populate the database

The database can be populated by :



could not access file "$libdir/postgis-1.5": No such file or directory

This error shows up when both postgresql-9.0 and postgresql-8.4 are installed (Debian/testing). Uninstalling 9.0 helps, it should be also possible to switch the active toolset version.


createdb: database creation failed: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) Change default template to UTF-8]] (Note: I used UTF8 instead UNICODE as that page says.) (I got this error on Postgis 9.0.7, Mandriva 2011)

Enable easy database login by user gisuser you must change some lines in one of the database configuration files.

# for Ubuntu <=9.10:
  sudo gedit /etc/postgresql/8.3/main/pg_hba.conf
# for Ubuntu >=10.04:
  sudo gedit /etc/postgresql/8.4/main/pg_hba.conf
# for Ubuntu >=12.04:
  sudo gedit /etc/postgresql/9.1/main/pg_hba.conf
# for Ubuntu >=14.04:
  sudo gedit /etc/postgresql/9.3/main/pg_hba.conf

Near to the bottom of the file you will find these lines:

local   all         all                               ident
host    all         all          md5

On some setups you may see an entry for ipv6:

host    all         all         ::1/128               md5

Change the words ident and md5 each to trust and close the editor. Now reload the database configuration, e.g.

  sudo -u postgres /usr/lib/postgresql/9.1/bin/pg_ctl reload

See also