2024.08.21(更新日: 2024.08.21)
ローカルにPostgreSQLをインストールした

はじめに
自作Railsアプリケーションで、デフォルトのSQliteを使用している。
前回の記事で、Herokuでは容量の問題でSQliteを使用できないということが分かった。
SQliteからPostgreSQLに変更する必要がある。
不要な記述は削除しておく
config/environments/production.rb に記入した以下の記述は不要なので削除しておこう。

公式ドキュメントのステップを参考にする

まずはローカルにPostgreSQLをインストールしていく
以下のように、ローカルでPostgreSQLをインストールする必要があると書かれていた。

そのため、インストールしていこう。
こちらの記事を参考にする。
Homebrewを確認してアップデートする
brew –versionをした結果。

brew updateをした結果。

brew upgradeをした結果。

brew cleanupをした結果。

brew services listをした結果。

インストールできるpostgreSQLを確認する
brew search postgresqlを打った。

hiroki@shibatahiroshitakanoiMac money-app % brew search postgresql
==> Formulae
postgresql@10 postgresql@11 postgresql@12 postgresql@13 postgresql@14 postgresql@15 postgresql@16 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@
postgreSQLをインストールする
brew install postgresqlでインストールを試みた。

以下の記述があったので、postgresqlのバージョン14がダウンロードされたはずだ。
==> Installing postgresql@14
==> Pouring postgresql@14--14.13.sonoma.bottle.tar.gz
==> /usr/local/Cellar/postgresql@14/14.13/bin/initdb --locale=C -E UTF-8 /usr/local/var/postgresql@14
==> Caveats
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /usr/local/var/postgresql@14
For more details, read:
https://www.postgresql.org/docs/14/app-initdb.html
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:
/usr/local/opt/postgresql@14/bin/postgres -D /usr/local/var/postgresql@14
==> Summary
psql –versionでバージョンを確認すると、14.13だった。

postgreSQLのインストールに成功した。
投稿ID : 24261
コメントを残す