LoginSignup
0
0

More than 3 years have passed since last update.

rails db:create実行時のFATAL: role "admin0" does not existとPG::ConnectionBad: FATAL: role "admin0" does not existの対処方

Posted at

rails db:create実行時にエラーが出た際の解決方法について後発者のために解決方法のまとめを書いておく。

実行環境

windows 10 home
ubuntu 20.04 LTS
ruby 2.7.1
Rails 6.0.3
postgresql 11

エラー文

$ rails db:create
FATAL:  role "admin0" does not exist
Couldn't create 'taskleaf2_development' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: FATAL:  role "admin0" does not exist
/home/admin0/taskleaf2/bin/rails:9:in `<top (required)>'
/home/admin0/taskleaf2/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

今回要所となるのは上から5行目まであたりだろうか。

エラー解決順序

以前私は同じようなエラーに出会っていて既に解決したことがあったので同じ方法をとってみた。
https://teratail.com/questions/297341

$ yarn install

だがこれでも解決できなかった。

エラーがPG::ConnectionBad:である点に着目してみることにする。
だが以下のコマンドのようにDBは起動しているはずだし、、、?

$ sudo service postgresql start
[sudo] admin0 のパスワード:
 * Starting PostgreSQL 11 database server [ OK ]
 * Starting PostgreSQL 13 database server [ OK ]

別(下)の手段で起動にチャレンジしてみることにした。

$ sudo su - postgres
 \q

再度rails db:createを実行したところエラー文に変化が現れた。

$ rails db:create
WARNING:  could not flush dirty data: Function not implemented
Created database 'taskleaf2_development'
WARNING:  could not flush dirty data: Function not implemented
Created database 'taskleaf2_test'

あとはこのエラー文で検索したところ
https://stackoverflow.com/questions/45437824/postgresql-warning-could-not-flush-dirty-data-function-not-implemented
こちらが有力そうだったので
/etc/postgresql/11/main/postgresql.confの内容の一部を以下のように書き換えた

fsync = off
data_sync_retry = true

再度rails db:createを実行してみる

rails db:create
Database 'taskleaf2_development' already exists
Database 'taskleaf2_test' already exists

どうやら成功したようだ。
サーバーも起動できたので今回はこれで問題解決したと判断する。

0
0
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
0
0