问题
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
回答1:
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;
回答2:
Installing PEX, a package manager for Postgresql allowed me to install Postgis for the keg version of Postgresql@9.6 and use CREATE EXTENSION postgis;
This isn't a Homebrew solution but after a lot of searching, it finally allowed me to use Postgis.
回答3:
Hello
I ran into this same problem of multiple implementation of pgsql versions including legacy ones. So after a bit of research I would like to share my solution.
Problem:I am working on a macbook pro 2013 with 10.11 el capitan. I am GIS developer and extensive user of homebrew. I didn't pin the postgresql package for compatibility reasons. Thus, the package got updated to postgresql version 10.5 along other packages. This caused me to be unable to use postgresql version 9.4. The cleverest solution would have been to use a brew switch postgresql 9.4.19
. Except that when compiling postgis 2.5.0 from osgeo/osgeo4mac
it defautls (looks for) the postgresql binary folder to install the symlinked (or not) extensions. Here again another compatibility problem. One could tinker a bit with homebrew files and transfer files manually. That's ill advice...the package manager (homebrew) needs to stay a coherent ecosystem to provide for a stable workspace.
Proposed Solution:
- Go here BigSQL and download the dmg of your chosen version
- install the software where you want in your filesystem
- within the installation folder you'll find a directory named
pg9x
; x being the version number (e.g pg95 for postgresql 9.5 and so on... - in this folder you'll find a file named
pg9x.env
- source this file to your
.profile
withsource /your/path/pg9x/pg9x.env
line - in the main installation folder, for instance
/your/path/pg9x/
, you'll finde a python script calledpgc
, alias it to your.profile
withalias pgc="your/path/pgc"
- save your
.profile
and refresh your environment variable withsource .profile
on the command prompt - still within the command prompt, type
pgc list
, you'll get a list of installed packages. You'll see the version of postgesql you've downloaded - to install another version of postgresql, say 9.6, type
pgc install pg96
- to install postgis for pg95 type
pgc install postgis22-pg95
- to install postgis for pg96 type
pgc install postgis23-pg96
- now, after installation you'll need to initialize the downloaded component with
pgc init pg96
orpgc init postgis23-pg96
etc... - to check if your daemon is running correctly type
pgc status
- to start a version daemon of your choice type for example
pgc start pg95
- to stop a version daemon of your choice type
pgc stop pg95
- the installation also comes with an LTS release of pgadmin3 that works fine with all versions (not the case of brew version of pgadmin3), this is very convenient
- type
pgc help
for more options
Let the elephant dance^^
Hope this helps.
Spicy.
来源:https://stackoverflow.com/questions/47079305/how-to-install-postgis-to-a-keg-installation-of-postgres9-6-using-homebrew