Skip to content

Unable to connect using Postgrex . #817

@itsWill

Description

@itsWill

I'm trying to connect to pglite from an elixir application.

When connecting through TCP settings or unix sockets to the the PGLite started with: npx pglite-server --path=/tmp/.s.PGSQL.5432

I get the following error:

Interactive Elixir (1.18.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(2)> Postgrex.start_link(socket_dir: "/tmp", port: 5432, username: "postgres", password: "postgres", database: "postgres", show_sensitive_data_on_connection_error: true)
{:ok, #PID<0.213.0>}

00:43:24.134 [error] :gen_statem #PID<0.215.0> terminating
** (FunctionClauseError) no function clause matching in String.split/3
    (elixir 1.18.4) lib/string.ex:504: String.split(nil, " ", [parts: 2])
    (postgrex 0.21.1) lib/postgrex/utils.ex:72: Postgrex.Utils.parse_version/1
    (postgrex 0.21.1) lib/postgrex/protocol.ex:1062: Postgrex.Protocol.bootstrap_send/3
    (postgrex 0.21.1) lib/postgrex/protocol.ex:749: Postgrex.Protocol.handshake/3
    (postgrex 0.21.1) lib/postgrex/protocol.ex:229: Postgrex.Protocol.connect_endpoints/6
    (db_connection 2.8.1) lib/db_connection/connection.ex:79: DBConnection.Connection.handle_event/4
    (stdlib 6.2) gen_statem.erl:3737: :gen_statem.loop_state_callback/11
    (stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Process Label: "db_conn_1"
Queue: [internal: {:connect, :init}]
Postponed: []
State: Postgrex.Protocol
Callback mode: :handle_event_function, state_enter: false

notably:

(elixir 1.18.4) lib/string.ex:504: String.split(nil, " ", [parts: 2])
    (postgrex 0.21.1) lib/postgrex/utils.ex:72: Postgrex.Utils.parse_version/1

Makes me think that the version is not being passed back to pglite during handshake to Postgrex.

However within PGLite I can see the version:

=> SHOW server_version;
 server_version
----------------
 17.5
(1 row)

This is the relevant line in Postgrex: https://github.com/elixir-ecto/postgrex/blob/251f30b6c4eb8e642eaec990d96059ec18f81ba3/lib/postgrex/protocol.ex#L1062

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions