先日、Mac OS上にインストールしていたpsqlコマンドを使って任意のDBにログインを試みていた際、以下のエラーが出るようになってしまっていました。それまでは使えていたのだが、何かの拍子でこういう状況になってしまったらしい。特に思い当たる節は無かったのですがこれは困る、という事で幾つか試行錯誤した記録を残しておこうと思います。OSはmacOS Sierra(10.12.3)、PostgreSQLは9.6.2です(でした?)
dyld: lazy symbol binding failed: Symbol not found: _PQsetErrorContextVisibility Referenced from: /usr/local/bin/psql Expected in: /usr/local/lib/libpq.5.dylib dyld: Symbol not found: _PQsetErrorContextVisibility Referenced from: /usr/local/bin/psql Expected in: /usr/local/lib/libpq.5.dylib Abort trap: 6
まずは上記のエラーメッセージで検索。しかしめぼしそうなネタは見つからず… (Ruby周りの情報は出ているのだが)
PostgreSQLはbrewでインストールしていたので一旦アンインストール。
$ brew uninstall postgresql Uninstalling /usr/local/Cellar/postgresql/9.6.1... (3,242 files, 36.4M)
で再インストール。するとエラーが出るものの、
already exists. You may want to remove it: rm ‘/usr/local/lib/libpq.5.dylib’
というような形でヒントになりそうな情報も併せて出てきました。上記エラーメッセージでも出てきていたヤツですね。
$ brew install postgresql Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.2.sierra.bottle.tar.gz Already downloaded: /Users/shinyaa31/Library/Caches/Homebrew/postgresql-9.6.2.sierra.bottle.tar.gz ==> Pouring postgresql-9.6.2.sierra.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink lib/libpq.5.dylib Target /usr/local/lib/libpq.5.dylib already exists. You may want to remove it: rm '/usr/local/lib/libpq.5.dylib' To force the link and overwrite all conflicting files: brew link --overwrite postgresql To list all files that would be deleted: brew link --overwrite --dry-run postgresql Possible conflicting files are: /usr/local/lib/libpq.5.dylib ==> Using the sandbox ==> Caveats If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/Homebrew/homebrew/issues/2510 To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see: https://www.postgresql.org/docs/9.6/static/upgrading.html To migrate existing data from a previous minor version (9.0-9.5) of PostgreSQL, see: https://www.postgresql.org/docs/9.6/static/pgupgrade.html You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`. Do not run `brew cleanup postgresql` until you have performed the migration. To have launchd start postgresql now and restart at login: brew services start postgresql Or, if you don't want/need a background service you can just run: pg_ctl -D /usr/local/var/postgres start ==> Summary 🍺 /usr/local/Cellar/postgresql/9.6.2: 3,251 files, 36.5M $
該当ライブラリの存在を確認後、rm
コマンドで削除。
$ ll /usr/local/lib/libpq.5.dylib $ rm '/usr/local/lib/libpq.5.dylib'
brewによるPostgreSQLのアンインストール&インストールで無事復旧出来ました。
$ brew uninstall postgresql $ brew install postgresql $ psql --version psql (PostgreSQL) 9.6.2