Reputation: 2400
I have installed postgres using package manager (brew). After starting the service as background and run this to create database on Phoenix I got this error:
dedeco@MacBook-Pro-Dedeco> mix ecto.create
23:57:56.112 [error] GenServer #PID<0.242.0> terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist
(db_connection) lib/db_connection/connection.ex:87: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for Hello.Repo couldn't be created: killed
Upvotes: 2
Views: 1542
Reputation: 2400
If you installed Postgres using homebrew, it probably was created a SUPERUSER using your operating system (OS) USER, like your name.
So 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=#
Another option is changing the postgres user int the file config/dev.exs
(or prod.exs, it depends which env you are) as follow:
# Configure your database
config :hello, Hello.Repo,
username: "<USER_NAME>",
password: "<PASSWORD>",
database: "hello_dev",
hostname: "localhost",
show_sensitive_data_on_connection_error: true,
pool_size: 10
Upvotes: 3