JA:PostGIS/Installation

From OpenStreetMap Wiki
Jump to navigation Jump to search

broom

Help (89606) - The Noun Project.svg

以下の説明は、どのようにして、PostgreSQLとPostGISをLinuxやWindows上にインストールし、適切な空間データベースを作成し、データベースパラメータを調整して良い性能を得るのかについて、解説しています。 Mapnik を OpenStreetMap データのレンダリングに使用するためのさらなる情報は、Mapnik ページで確認してください。

以下の例では、 gisuser をユーザーの名前として、 gis をデータベースのユーザー名として使います。

OpenStreetMap の Mapnik メインスタイルは、レンダリングパイプラインの一部として PostgreSQLPostGIS を使用しています。 データベースの作成は、 osmosisosm2pgsql とほぼ同じです。

PostgreSQL のバージョン9.3以降を推奨します。バージョン9.0および以前のバージョンは開発が終了しています。

PostgreSQL と PostGIS のインストール

Ubuntu と Debian

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

darwinports をお持ちであれば、

% sudo port install postgresql83
% sudo port install postgis

または、 KyngChaos にある Mac OS X インストーラーを使用してください。

Fedora

root で、

Fedora 16 Fedora 17 以降
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

PostGIS をパッケージマネージャに知らせるため、コミュニティのパッケージリポジトリを追加する必要があります。

sudo zypper ar http://download.opensuse.org/repositories/Application:/Geo/openSUSE_11.2/ "Geo"
sudo zypper refresh

それから PostGIS をインストールします。

sudo zypper install postgis postgresql-contrib
Windows

PostGIS 向けの setup バイナリがあります。 PostgreSQL のバージョンに合うインストーラーをダウンロードして実行してください。 PostgreSQL サーバーが動作している必要があります。これで PostgreSQL がインストールされている場所のサブディレクトリにいくつかのファイルがインストールされ、2つのデータベーステーブルがインストールされます。

Gentoo

osm2pgsql をインストールすると、 postgres と postgis が依存関係で引用されます。

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.

データベースの作成

一般

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
Windows

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: JA: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 :

Troubleshooting

Problem:

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.


Problem:

createdb: database creation failed: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)

http://journal.tianhao.info/2010/12/postgresql-change-default-encoding-of-new-databases-to-utf-8-optional/ 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         127.0.0.1/32          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