まずは、brew でインストール可能な PostgreSQL を探す
% brew search postgresql
==> Formulae
postgresql@11 postgresql@12 postgresql@13 postgresql@14 postgresql@15 postgresql@16 postgresql@17 qt-postgresql postgrest
==> Casks
navicat-for-postgresql posture-pal
If you meant "postgresql" specifically:
postgresql breaks existing databases on upgrade without human intervention.
See a more specific version to install with:
brew formulae | grep postgresql@
postgres だけ指定したら最新バージョンで現行システム上書くでってことかな?
それで構わないので、今回は postgres だけ指定。
% brew install postgresql
Warning: Formula postgresql was renamed to postgresql@14.
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/14/manifests/14.13_3
<略>
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14
To start postgresql@14 now and restart at login:
brew services start postgresql@14
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14
shinoda@shinodamasanorinoMacBook-Air smart_lap % brew services list
Name Status User File
postgresql@14 none
これでインストール終了。
メッセージに起動方法が書かれているので、起動してみる。
% /opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14 &
[1] 34533
shinoda@shinodamasanorinoMacBook-Air smart_lap % 2024-11-13 20:40:08.668 JST [34533] LOG: starting PostgreSQL 14.13 (Homebrew) on aarch64-apple-darwin24.1.0, compiled by Apple clang version 16.0.0 (clang-1600.0.26.4), 64-bit
<略>
クライアントソフトの psql も実行してみる。
% psql --version
psql (PostgreSQL) 14.13 (Homebrew)
うむ。ちゃんとインストールされているな。
ちなみに、Homebrew でインストールした場合は、brew services コマンドでの起動もできるようだ。
起動して、すぐに停止してみる。
% brew services start postgresql
Warning: Formula postgresql was renamed to postgresql@14.
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
% brew services stop postgresql
Warning: Formula postgresql was renamed to postgresql@14.
Stopping `postgresql@14`... (might take a while)
==> Successfully stopped `postgresql@14` (label: homebrew.mxcl.postgresql@14)
問題なし。
さて、続いて PostgreSQL の設定をするか。