[postgresql] dyld: Library not loadedの解決方法
postgresqlが動かなくなり、アンインストールしようか悩むほど格闘したので、解決方法を書いておこうと思います。
(長時間格闘した割にあっさり直ってしまいましたが)
エラー内容
数日ぶりにpostgresqlを使用したアプリを立ち上げようとしたら接続できなくなっておりました。。。
postgresコマンドで接続を試みても以下のようにエラーが出ておりました。
$ postgres
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
Referenced from: /usr/local/bin/postgres
Reason: image not found
fish: 'postgres' terminated by signal SIGABRT (Abort)
posgtresqlの起動をし直したり、postmaster.pidが残ったままになってることも疑ってみましたが治らず。。。
postgresqlのログを確認してみたらなぜか9月30日にシャットダウンされており、そこから全く動いてくれていないようでした。以下はローカルで動かしたpostgresqlのログです。
9月30日何もしてないのに突然何故。。。?!
/usr/local/var/log/postgresql
2019-09-24 12:30:16.234 JST [50321] ERROR: relation "users" does not exist
2019-09-24 12:30:16.234 JST [50321] STATEMENT: ALTER TABLE "users" ADD "name" character varying DEFAULT '' NOT NULL
2019-09-30 14:46:10.019 JST [1037] LOG: received smart shutdown request
2019-09-30 14:46:10.152 JST [1037] LOG: background worker "logical replication launcher" (PID 1374) exited with exit code 1
2019-09-30 14:46:10.170 JST [1369] LOG: shutting down
2019-09-30 14:46:11.421 JST [1037] LOG: database system is shut down
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
Referenced from: /usr/local/opt/postgresql/bin/postgres
Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
Referenced from: /usr/local/opt/postgresql/bin/postgres
Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
Referenced from: /usr/local/opt/postgresql/bin/postgres
Reason: image not found
解決方法
`brew upgrade postgresql` しただけで直ってしまいましたw
アンインストールしようか悩むほど数時間格闘したのにw
どうやら実行時にライブラリを読み込むDyldというツールが勝手にアップデートされており、バージョン11.1_1のpostgresqlを参照できなくなっていたことが原因のようでした。
$ brew upgrade postgresql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (homebrew/core, homebrew/cask and homebrew/services).
==> New Formulae
diffr pnetcdf wagyu
==> Updated Formulae
node ✔ gleam opa
ruby-build ✔ gmime openapi-generator
angular-cli gnutls parallel
apache-arrow go@1.12 phoronix-test-suite
armadillo groonga php@7.2
aws-okta grpc picard-tools
b2-tools gspell prometheus
balena-cli haproxy protobuf
bee icdiff protobuf-c
bnd iso-codes rke
caffe joplin roswell
cgal juju rust
clib k3d salt
cloc kcov screen
cmake kerl shogun
collectd libcaca skafos
conan libfabric starship
crystal libphonenumber terragrunt
deno libpulsar v8
embulk lightning vert.x
ethereum lmod wsk
exploitdb minizinc wtf
ffsend mkl-dnn yaml-cpp
fluid-synth mosh zbackup
fonttools nano zint
frugal ne znc
==> Upgrading 1 outdated package:
postgresql 11.1_1 -> 11.5_1
==> Upgrading postgresql
==> Downloading https://homebrew.bintray.com/bottles/postgresql-11.5_1.mojave.bo
==> Downloading from https://akamai.bintray.com/46/463c6a192a0b6a5d1359b68db2400
######################################################################## 100.0%
==> Pouring postgresql-11.5_1.mojave.bottle.tar.gz
==> /usr/local/Cellar/postgresql/11.5_1/bin/initdb --locale=C -E UTF-8 /usr/loca
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
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/11.5_1: 3,189 files, 35.4MB
Removing: /usr/local/Cellar/postgresql/11.1_1... (3,548 files, 40.3MB)
感想その他
環境周り難しいですね!!
Dyldが何者なのか知っていればもっと素早く解決できていた気がします。。。
すぐに解決方法見つけられなかったため、自分の検索力も高めていきたいです。。。!!
参考文献