Unable to connect using `Postgrex` .
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
Related https://github.com/electric-sql/pglite/issues/708
Possible cause: during the initial handshake, PostgreSQL will report GUC Options but only if they haven't been reported already.
static void
ReportGUCOption(struct config_generic *record)
{
char *val = ShowGUCOption(record, false);
if (record->last_reported == NULL ||
strcmp(val, record->last_reported) != 0)
{
@itsWill Is it possible to set Postgrex (I guess through https://github.com/elixir-ecto/db_connection) to use a single connection for all the queries?
PGlite is single connection at the moment, so any client that is trying to connect but relies on multiple connections will not work at the moment.
@itsWill please try again with the latest PGlite version.
Thanks @tdrz I'll have a look this weekend.