PostgreSQLをHomebrewでmacにインストールする

FBCSinatraを使ったプラクティスでPostgreSQLを使うのでHomebrewでのインストールから起動までをメモ。

PostgreSQL: macOS packages

環境

  • macOS 12.3.1
  • Homebrew 3.5.3

手順

インストールからパス確認。

# インストール
$ brew update
$ brew install postgresql
$ psql --version
psql (PostgreSQL) 14.4

# パス確認
$ which psql
/opt/homebrew/bin/psql

起動からテーブルの確認。

# 起動
$ brew services start postgresql
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
$ brew services list
Name       Status  User    File
postgresql started karlley ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

# データベース確認
$ psql -l
                           List of databases
   Name    |  Owner  | Encoding | Collate | Ctype |  Access privileges
-----------+---------+----------+---------+-------+---------------------
 postgres  | karlley | UTF8     | C       | C     |
 template0 | karlley | UTF8     | C       | C     | =c/karlley         +
           |         |          |         |       | karlley=CTc/karlley
 template1 | karlley | UTF8     | C       | C     | =c/karlley         +
           |         |          |         |       | karlley=CTc/karlley
(3 rows)

postgresqlの再起動と停止。

# 再起動
$ brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

# 停止
$ brew services stop postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
$ brew services list
Name       Status User File
postgresql none

感想

brew 経由でインストールしておくとアンインストールも楽なので気軽に色々インストールできるので良い。 SinatraのDB化はサクッと終わらせたいなー。

参照

PostgreSQL: macOS packages

[macOS High Sierra][Homebrew] PostgreSQL のインストールからDB作成まで - Qiita