LoginSignup
3
1

More than 5 years have passed since last update.

homebrewでインストールしたpostgresでpsqlコマンドのエラーが出た場合

Posted at

状況

少し古めのpostgres(9.4系)をmacOS Mojaveのローカルで構築する場合に、psqlコマンドがエラーになる問題が発生した。
brewでインストールした場合に発生する現象だったため、解消までの流れを記録します。

環境

  • macOS Mojave
  • Postgres9.4.15

発生した問題

brewでPostgreSQL 9.4.15を指定してインストールしたく、

フォーミュラのコミット履歴から9.4.15リビジョンを指定して実行する

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/be423627e2cef2ed798858d8663646f896e697f9/Formula/postgresql@9.4.rb

インストール後、psqlコマンドを叩いた際にエラーが発生しました。。

(path指定は省略)

$ psql -V
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
  Referenced from: /usr/local/opt/postgresql@9.4/bin/psql
  Reason: image not found
Abort trap: 6

readlineを確認してみると...

$ brew info readline
readline: stable 8.0.0 (bottled) [keg-only]
Library for command-line editing
https://tiswww.case.edu/php/chet/readline/rltop.html
/usr/local/Cellar/readline/8.0.0 (48 files, 1.5MB)
  Poured from bottle on 2019-04-08 at 13:30:15
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/readline.rb
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

~ 略

Postgres9.4はreadline7を必要とする模様。
そして、インストールされているreadlineは8.0.0だったのでreadline7のインストールを試みる。

$ brew search readline
==> Formulae
libreadline-java                                 readline ✔                                       with-readline                                    homebrew/portable-ruby/portable-readline

見当たらない。。
旧verのreadlineがbrew経由で入っていればCeller内のバージョンを使えば良いのだが、本事象では8しか入っていなかった。
無い!では困るので手動で入れよう。GNU Readline Libraryで直接取得することにする。
今回必要なのは ftp://ftp.gnu.org/gnu/readline/readline-7.0.tar.gzなのでダウンロードしてmake installする。今回はディレクトリを7.0とする。

$ ./configure --prefix=/usr/local/Cellar/readline/7.0 --mandir=/usr/local/Cellar/readline/7.0/share/man --infodir=/usr/local/Cellar/readline/7.0/share/info --enable-multibyte
$ make
$ make install

どれ、インストールできたか確認...

$ brew info readline
readline: stable 8.0.0 (bottled) [keg-only]
Library for command-line editing
https://tiswww.case.edu/php/chet/readline/rltop.html
/usr/local/Cellar/readline/7.0 (154 files, 6.8MB)
  Built from source
/usr/local/Cellar/readline/8.0.0 (48 files, 1.5MB)
  Poured from bottle on 2019-04-08 at 14:53:57

~ 略

infoで認識したようなので7を認識するように切り替える。

$ brew switch readline 7.0
Cleaning /usr/local/Cellar/readline/7.0
Cleaning /usr/local/Cellar/readline/8.0.0
Opt link created for /usr/local/Cellar/readline/7.0

シンボリックリンクも貼られたようなのでpsqlを叩いてみよう。

$ psql -V
psql (PostgreSQL) 9.4.15

よかった、解決です。

Cellerへの過去Verインストールは以下を参考にさせて頂きました

参考: https://blog.skylarking.me/2016/10/07/psql-readline-error/

 keg-onlyについて補足

readlineはkeg-onlyとなっていて、Cellarにあるだけでは/usr/local/opt/readline/lib/にシンボリックリンクが貼られないとのこと。
そもそも/usr/local/opt/readline/lib/が存在しないような場合は、一旦brew unlinkするか/usr/local/opt/readline/を物理削除してからbrew link readline --forceするべし。

参考: https://stackoverflow.com/questions/17015285/understand-homebrew-and-keg-only-dependencies

3
1
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
3
1