0
votes

Im using Mac on High Sierra 10.13.6

I try to Setup a Rails Application to run locally on my Mac. When i try to setup the Database with 'createdb xyz' and 'bin/setup', i get an error message:

Database 'xyz' does not exist FATAL: role "postgres" does not exist

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "template"=>"template0", "host"=>"localhost", "username"=>"postgres", "password"=>"postgres", "database"=>"xyz"} rails aborted!

Any ideas how to fix this?

2

2 Answers

0
votes

Firstly you need to create a postgres user for your rails app. You can do that by switching in to postgres user by following command.

> sudo su postgres
> psql

Then create an user:

> create role role_name with createdb login password 'password';

then exit > \q > exit

Replace the username & password in config/database.yml file with the credentials you created in postgres and then run bin/setup

For further reference you can follow this link

0
votes

If you installed Postgres using homebrew, it probably was created a SUPERUSER using your operating system (OS) USER, like your name. If you need a Postgres user, you must create using these commands:

dedeco@MacBook-Pro-Dedeco> psql postgres                                                                                                              
psql (12.2)
Type "help" for help.

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 dedeco    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=# CREATE USER postgres SUPERUSER;
CREATE ROLE
postgres=#