Postgrex.start_link crashes with KeyError

I cloned an umbrella project that is working perfectly in my computer (macOS) to a colleague’s computer (macOS) and we are having problems with mix ecto.create.

Trying to isolate the problem we ran the following command in iex -S mix and we get the following error:

{:ok, pid} = Postgrex.start_link(hostname: "localhost", username: "postgres", password: "postgres", database: "postgres")
{:ok, #PID<0.397.0>}

15:06:05.107 [error] GenServer #PID<0.399.0> terminating
** (KeyError) key :messages not found in: %{opts: [types: Postgrex.DefaultTypes, hostname: "localhost", username: "postgres", password: "postgres", database: "postgres"], prepare: :named, ssl: false, types_key: {'localhost', 5432, "postgres"}, types_lock: {#PID<0.401.0>, #Reference<0.4115175174.1123287042.227985>}, types_mod: Postgrex.DefaultTypes}
    (stdlib) :maps.get(:messages, %{opts: [types: Postgrex.DefaultTypes, hostname: "localhost", username: "postgres", password: "postgres", database: "postgres"], prepare: :named, ssl: false, types_key: {'localhost', 5432, "postgres"}, types_lock: {#PID<0.401.0>, #Reference<0.4115175174.1123287042.227985>}, types_mod: Postgrex.DefaultTypes})
    (elixir) lib/map.ex:267: Map.update!/3
    (postgrex) lib/postgrex/protocol.ex:2815: Postgrex.Protocol.handle_msg/3
    (postgrex) lib/postgrex/protocol.ex:825: Postgrex.Protocol.bootstrap_recv/5
    (postgrex) lib/postgrex/protocol.ex:576: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: 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

Any idea?

Looks like a bug. Can you please open up an issue? My guess is that the root cause is something related to permission. Maybe the user does not exist or does not have access to access that database or socket connections are forbidden. There is a postgres configuration follow to set those.

@josevalim, done …

1 Like