Skip to content

Instantly share code, notes, and snippets.

@rhiroyuki
Last active March 13, 2019 18:52
Show Gist options
  • Save rhiroyuki/4b2b06f965c584cd430326f7c42e7bbc to your computer and use it in GitHub Desktop.
Save rhiroyuki/4b2b06f965c584cd430326f7c42e7bbc to your computer and use it in GitHub Desktop.
rails db:create error: FATAL: role does not exist

Error

FATAL:  role "ricardo" does not exist
Couldn't create 'somedb_development' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "ricardo" does not exist
bin/rails:4:in `<main>'

Caused by:
PG::ConnectionBad: FATAL:  role "ricardo" does not exist
bin/rails:4:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

Solution

su
su -l postgres
createuser -s -r ricardo

Error 2

[postgres@ricardo-pc ~]$ initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/lib/postgres/data ... initdb: could not create directory "/var/lib/postgres/data": Permission denied
sudo rm -rf /var/lib/postgres/data
chown -hR postgres /var/lib/postgres

# re-do initdb

# restart postgres daemon
sudo systemctl restart postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment