Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

postgresql - How to install Postgis to a Keg installation of Postgres@9.6 using Homebrew?

I have installed Postgresql@9.6 and Postgis via Homebrew. However, installing Postgis via Homebrew installs the latest version of Postgresql at 10 as dependency and pinning Postgresql at 9.6.5 blocks the install of Postgis via Homebrew.

Performing 'CREATE EXTENSION postgis;' returns:

ERROR: could not open extension control file "/usr/local/Cellar/postgresql@9.6/9.6.5/share/postgresql@9.6/extension/postgis.control": No such file or directory

I've also tried uninstalling the Postgresql (at 10) and editing the Postgis formula to depend on Postgres@9.6 instead of Postgresql.

This is similar to How to install Postgis to a Keg installation of Postgres@9.5 using Homebrew? but with a later keg formula

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I managed to do it after many combinations. In a nutshell, solution is to install the old version of the original package postgres, switch to it, and install the old version of postgis.

Install postgres

1/ Install the current version of postgres (10.1 as speaking)

brew install postgres

2/ Install the old version of postgres using its old formula. Proper link can be found using github or git log on the Tap repo (/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/).

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d014fa223f77bee4b4097c5e80faa0954e28182f/Formula/postgresql.rb

This will install the version 9.6.5 (last one before 10.x series).

3/ Switch to it so links are defaulted to postgres 9.6

brew switch postgres 9.6.5

Install postgis

4/ Install old version of postgis (2.3). This is using the same sha version of the Formula so everything is linked correctly (using the current postgis will expect postgresql 10, so it will end up to a version mismatch when initializing extension).

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d014fa223f77bee4b4097c5e80faa0954e28182f/Formula/postgis.rb

Use them

5/ If required initialise the DB

initdb /usr/local/var/postgres

6/ Create and use your DB

createdb mydb
psql mydb
mydb=# CREATE EXTENSION postgis;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...