Why it is throw error "Failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password)"?

I am try to migrate elixir those days, so I have simple project to create GraphQL API’s with Phoenix. When I start the server like " iex -S mix phx.server", it is throw an error like

[error] Postgrex.Protocol (#PID<0.396.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user “example_api”

I guess I have to fix somethings about pg_hba.conf.


# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all               trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
local   replication     all                                     trust
host    replication     all               trust
host    replication     all             ::1/128                 trust

app config:

config :example_api, ExampleAPI.Repo,
  username: "example_api",
  password: "example_api",
  hostname: "localhost",
  database: "myExample_api",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10


 defp deps do
      {:phoenix, "~> 1.6.6"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.6"},
      {:postgrex, ">= 0.16.2"},
      {:phoenix_live_dashboard, "~> 0.6"},
      {:swoosh, "~> 1.3"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.18"},
      {:jason, "~> 1.2"},
      {:plug_cowboy, "~> 2.5"},
      {:absinthe, "~> 1.3.1"},
      {:absinthe_plug, "~> 1.3.0"},
      {:absinthe_ecto, "~> 0.1.3"}

The error is telling you that the database does not know of a user example_api or that it does exist and the password is not example_api.

Did you create a use for the database with that name?

The error is pretty clear that a connection was established at a network level so you shouldn’t have to make any changes to the Postgres configuration.

tnx for ur answer, I have to use postgres in my project, still not get it how to fix

You need to change these entries to match a user already configured in your Postgres database. Or create a user and password with these names in the database.


I get it now, thnx so much