2
1

More than 1 year has passed since last update.

rails sをしたら、PGSQL.5432エラーが出力された件

Last updated at Posted at 2022-08-11

環境:
・Ubuntu 20.04 LTS
・psql (PostgreSQL) 14.4
・Rails 7.0.3.1

Railsサーバーを起動しようと、rails sをしたところ、
下記のエラーメッセージが出力されて起動に失敗した。

connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "hogehoge" does not exist

本エラーの原因については、
"hogehoge"のRoleが存在しなかったため発生したエラーであり、
"hogehoge"のRoleを作成することでエラーは解決した。

PostgreSQLに接続してRoleの一覧を確認してみる

failed: FATAL: role "hogehoge" does not exist

エラーメッセージには"hogehoge"というロールが存在しないと書いてあるので、
PostgreSQLに接続して、Roleの一覧を確認してみる。

psql postgres

postgres=# \du

                                     List of roles
   Role name   |                         Attributes                         | Member of
---------------+------------------------------------------------------------+-----------
 {hogehoge}    | Superuser, Create role, Create DB                          | {}

"hogehoge"というロールが既にあるじゃないか…と思ったが、
"hogehoge"というロールがあるのではなく、"{hogehoge}"というロールが存在しているだけだった。
(いつこのRoleを作ったんだっけ…)

hogehogeのロールをCreateして
再度、Rails sしたところ、
正常にRailsサーバーが起動することを確認した。

CREATE ROLE hogehoge LOGIN CREATEDB CREATEROLE PASSWORD 'hogehoge_password';

                                     List of roles
   Role name   |                         Attributes                         | Member of
---------------+------------------------------------------------------------+-----------
 hogehoge      | Create role, Create DB                                     | {}
 {hogehoge}    | Superuser, Create role, Create DB                          | {}

ROLEを作成するときに参考にした記事:
https://qiita.com/sibakenY/items/407b721ad1bd0975bd00#createuser%E3%81%8C%E3%81%A7%E3%81%8D%E3%81%AA%E3%81%84

2
1
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
2
1