LoginSignup
6
2

Rails7+Herokuで「ActiveRecord::ConnectionNotEstablished (connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" 」

Last updated at Posted at 2023-09-16

はじめに

個人開発のアプリ制作を始めました。
調べながらの実装になるので、メモとして記載しています。

※注意※
プログラミング学習中の初心者です。
記述に間違いがあれば、ご指摘いただけますと幸いです。

環境

Mac M1
Rails 7.0.7.2
Ruby 3.2.0
Node.js 20.2.0
Yarn 1.22.19

発生事由

ユーザーの新規登録を実装し、Herokuへpushしたところ、 pushはできましたが、下記のエラー画面が出ました。
Image from Gyazo
Herokuのログ

ActiveRecord::ConnectionNotEstablished (connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory

Postgresが落ちているのかと思いましたが、起動していました。

$ brew services list

Name          Status  User         File
mysql         none                 
postgresql@14 started ユーザー名 ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist

Heroku上でmigrateができていなかったからと行おうとしたところ、やはり同じエラーが表示。

$ heroku run rails db:migrate
Running rails db:migrate on ⬢ grow-journey... up, run.4405 (Basic)
rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?

解決方法

調べたところ、Heroku Postgresを追加しなければいけませんでした。(有料)

$ heroku addons:create heroku-postgresql

再度$ heroku run rails db:migrateで無事Herokuの画面上で新規登録ページが表示されました。

参考

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2