前提
homebrew を使う
時々起こる問題の種類
- OpenSSLをUpdateするなど、homebrew でUpdateをかけた時に、再起動で失敗する
- PostgreSQLのVersionをあげて、DBデータを置き換えるのに手間取る
基本的な役割の確認
- homebrew : インストール、アップデート
- Launchd : 起動
homebrew の起動
こちら
https://qiita.com/takuya0301/items/c0720753de98572703b8
- 起動
- サービス状態のリスト表示
postgres 起動後
DB一覧
psql -l
DatabaseにRailsで利用するDatabase名があるか確認。なければつくる。
権限整合性がなくなるのを避けるため、psql で作らずに rails で作る。
rake db:create
rake db:migrate
DB作成で失敗したら、権限がないことを疑う。
エラーメッセージでわかる。
ユーザー一覧
ターミナルで psql から postgres へ入る
psql postgres
postgres 内で操作
\du
ユーザーにRailsで設定したユーザーがあるか確認。なければつくる。
ユーザー作成
postgres 内で操作
CREATE USER username;
CREATE ROLE と表示されたらOK
ユーザーにDB作成権限をつける
postgres 内で操作
ALTER ROLE username CREATEDB;
こちら分かりやすい
https://eng-entrance.com/postgresql-role#i
PostgreSQL DBデータ移行
こちらが分かりやすい
PostgreSQL DB のアップグレードは brew postgresql-upgrade-database が便利
https://qiita.com/yasulab/items/237c3f9634055d665745