案件がある度に開発環境をセットアップするため、いつの間にか macOS に PostgreSQL がバージョン 14 と 18 の二つ入っていた。
Homebrew で 14 を入れて、公式サイトの dmg ファイルで 18 を入れたようだ。
Homebrew のリストには 14 が、
~ % brew list | grep postgresqlpostgresql@14
/Library/PostgreSQL の下に 18が入っている。
~ % ls -ld /Library/PostgreSQL/18drwxr-xr-x@ 21 postgres daemon 672 5月 28 06:49 /Library/PostgreSQL/18
ちなみに、18 は自動起動が設定されているようで、何もしなくてもデーモンが起動している。
~ % ps aux | grep PostgreSQLpostgres 534 0.0 0.0 435512752 1120 ?? Ss 11 7月26 6:33.81 /Library/PostgreSQL/18/bin/postgres -D /Library/PostgreSQL/18/datashinoda 78278 0.0 0.0 435300560 1360 s000 S+ 4:24午後 0:00.01 grep PostgreSQL
しかし、psql コマンドは 14 の方にパスが通っているようだ。
~ % which psql/opt/homebrew/bin/psql
というわけで、PostgreSQL 環境をきれいに一本化したいので、当然最新版の 18 の方を生かすことにする。
14 については自動起動の設定はされていないようなので(brew services start postgresql@14 すれば起動する)、単純に 14 のアンインストールと、psql のパスの付け替えをする。
~ % brew uninstall postgresql@14Uninstalling /opt/homebrew/Cellar/postgresql@14/14.22... (3,337 files, 48.3MB)==> Autoremoving 6 unneeded formulae:<略>
途中、
Warning: The following openssl@3 configuration files have not been removed!
Warning: The following ca-certificates configuration files have not been removed!
というような警告が出るが、これは「postgresql@14 はアンインストールしたけど、openssl@3 は他に使ってるソフトがあるかもしれないので念の為残しておくね」というものなので無視。
次に、psql のパスを 18 に向ける。
~ % echo 'export PATH="/Library/PostgreSQL/18/bin:$PATH"' >> ~/.zshrc~ % source ~/.zshrc~ % which psql/Library/PostgreSQL/18/bin/psql~ % psql -Vpsql (PostgreSQL) 18.3
これで OK。
~ % psql -U postgresPassword for user postgres: <パスワード入力:表示されない>psql (18.3)Type "help" for help.postgres=# \dbList of tablespacesName | Owner | Location------------+----------+----------pg_default | postgres |pg_global | postgres |(2 rows)
ちゃんと 18.3 の psql が起動している。
電気ウナギ的○○
About Backコメント(0)
電気ウナギ的○○