LoginSignup
4
4

More than 5 years have passed since last update.

Macへの PostgreSQL, PostGISインストール

Last updated at Posted at 2019-01-06

macOS High SierraにPostgreSQLとPostGISをHomebrewでインストールした際のメモ。
昔とは色々変わっているところも多いようなので手探りで。

環境

  • macOS High Sierra 10.13.6
  • Homebrew 1.8.6

インストール

PostgreSQLのインストール

> brew install postgres

PostGISのインストール

> brew install postgis

PostGISインストール時に以下のようなエラーが発生。

Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

以下のように対応したのち、postgisを再インストール。

参考:Homebrewで入れたPythonでのlinkエラー問題

> sudo mkdir /usr/local/Frameworks
> sudo chown [username]:admin /usr/local/Frameworks

インストールされたバージョンは以下

  • PostgreSQL 11.1
  • PostGIS 2.5.1

DBの作成と起動

おそらくPostgreSQLインストールの時点で /usr/local/var/postgresql/ 以下にDBが存在している?様子だが、これを削除してから以下のように作り直した。

> initdb /usr/local/var/postgres -E utf8

サービスの起動はbrew servicesを使用(postgresqlインストール時のメッセージを参考に)。

> brew services start postgresql

一応、postgresユーザをスーパーユーザとして作成しておく。

> createuser -s postgres

PostGISのDB作成。

> createdb -U postgres geomdb
> psql -U postgres geomdb

psql (11.1)
Type "help" for help.

geomdb=# CREATE EXTENSION postgis;
CREATE EXTENSION
geomdb=# SELECT PostGIS_Version();
            postgis_version
---------------------------------------
 2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

geomdb=#

参照

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4