2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

homebrewで古いpostgresqlとpostgisをインストールする

Posted at

課題:何も考えずにbrew reinstall postgresqlしたら壊れた

もともとpostgresql 9.5を使っていた状態で、psqlが認識しなくなったのでbrew reinstall postgresqlを実行したら9.6がインストールされてしまい、pg_upgradeの処理が必要になったけれど、そもそもreinstallしたから9.5ないのでできないし面倒臭いという状態に。もう一度9.5が使いたい。

9.5のインストールに成功。しかしpostgisが…。

brew install postgresql95で9.5は入ったのだけれど、postgisが入ってない。
しかし、brew install postgisを行うと、依存関係にpostgresqlがあると言われて強制的に9.6が入る。

解決:古いバージョンをcheckoutしてインストール

Homebrewで旧バージョンをインストールする方法(brew verionsはもう使えない)を参考に、古いバージョンを使うことにしました。

なお、cd先のディレクトリはhomebrewのインストール先次第では違うと思うので、適宜読み替えてください。

前提

関連するものは全て一旦停止・削除しておきましょう!
以下の命令は必要ないものもあるかもしれないので、適宜実行してください(多分害はないと思うけれど、自己責任で)

brew services stop postgresql
brew services stop postgresql95
brew uninstall postgresql
brew uninstall postgis
brew uninstall postgresql95

postgresql

以下を実行します。

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
git log postgresql.rb

すると、

commit db96a14dde07fdd4600d2a8cc3d4a917806d3228
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Wed Nov 2 08:29:01 2016 +0000

    postgresql: update 9.5.5 bottle.

というコミットが見つかるので、それをcheckoutしました。

git checkout db96a14dde07fdd4600d2a8cc3d4a917806d3228 postgresql.rb

postgis

postgisもcheckoutします。最新のものはpostgresql9.6に対応しているため、9.5ではcreate extension postgis;でエラーになったためです。

git log postgis.rb

すると、こちらも同様に、

commit a1f02e19405897966e7998f917f7c8ab14e6732e
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Wed Oct 12 23:44:00 2016 +0100

    postgis: update 2.3.0 bottle.

というコミットが見つかったのでそれをcheckoutします。

git checkout a1f02e19405897966e7998f917f7c8ab14e6732e postgis.rb

インストールを実行

brew install postgis

これで、postgresql 9.5, postgis 2.3がインストールされます。

あとは、psqlでposgisが使えるか確認します。
Railsプロジェクトやってる人ならば、プロジェクトのディレクトリでbin/rails dbconsoleを使うと楽です。
そして、以下を実行してpostgisがあるかどうかを確認します。

select * from pg_available_extensions;

あったら、使えるようにしましょう。

create extension postgis;

以上です。

感想

こうなると面倒臭いので、そろそろpostgresqlをDockerで動かしたい…。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?