How to deal with FATAL: role "admin0" does not exist and PG :: ConnectionBad: FATAL: role "admin0" does not exist when executing rails db: create

I will write a summary of the solution for latecomers about the solution when an error occurs when executing rails db: create.

Execution environment

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

Error statement

$ 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)

Is the key point this time around the 5th line from the top?

Error resolution order

I had encountered a similar error before and had already resolved it, so I tried the same method. https://teratail.com/questions/297341

$ yarn install

However, even this could not be solved.

Notice that the error is PG :: ConnectionBad :. However, the DB should be running like the following command ...?

$ sudo service postgresql start
[sudo]admin0 password:
 * Starting PostgreSQL 11 database server [ OK ]
 * Starting PostgreSQL 13 database server [ OK ]

I decided to try starting it by another means (below).

$ sudo su - postgres
 \q

When I ran rails db: create again, the error statement changed.

$ 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'

After that, I searched with this error sentence https://stackoverflow.com/questions/45437824/postgresql-warning-could-not-flush-dirty-data-function-not-implemented Because this seemed to be influential Part of the contents of /etc/postgresql/11/main/postgresql.conf was rewritten as follows

fsync = off
data_sync_retry = true

Try running rails db: create again

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

Apparently it was successful. Since the server was able to start, it is judged that this solved the problem this time.

Recommended Posts

How to deal with FATAL: role "admin0" does not exist and PG :: ConnectionBad: FATAL: role "admin0" does not exist when executing rails db: create
What to check when rails db: migration does not pass
How to specify db when creating an app with rails
[Rails] [Memo] When to add = to <%%> and when not
What to do when rails db: seed does not reflect in the database
How to build API with GraphQL and Rails
[Ruby] 5 errors that tend to occur when scraping with Selenium and how to deal with them
How to deal with errors in Rails s could not find a JavaScript runtime.
How to deal with fatal: remote origin already exists.
[Rails] How to deal with URL changes after render
Common problems with WSL and how to deal with them
(Ruby on Rails6) How to create models and tables
[Docker + Rails] How to deal with Rails server startup failure
When the server does not start with rails s
How to solve the problem when the value is not sent when the form is disabled in rails and sent
Check how to set the timeout when connecting with Spring + HikariCP + MySQL and executing SQL
Cases where Rails fails to start due to an invalid config/master.key and how to deal with it
How to automatically generate ER diagram when migrating with Rails6
How to set environment variables when using Payjp with Rails
How to deal with the error ERROR: While executing gem ... (Gem :: FilePermissionError)
How to get the log when install4j does not start
How to deal with different versions of rbenv and Ruby
[Rails / RSpec] How to deal with element has zero size error
How to deal with 405 Method Not Allowed error in Tomcat + JSP
[Rails] How to execute "rails db: create" etc. in production environment EC2
[Rails] How to introduce kaminari with Slim and change the design
Android: How to deal with "Could not determine java version from '10 .0.1'"
[Rails] How to avoid "Use hash rockets syntax" when executing Rubocop
Project facet Java version 13 is not supported. How to deal with
[Rails] What to do when rails s does not respond or does not stop