Skip to content

pgduck client: include conninfo in start-failure error#361

Open
sfc-gh-dachristensen wants to merge 3 commits into
mainfrom
pgguru/issue-293-conninfo-errdetail
Open

pgduck client: include conninfo in start-failure error#361
sfc-gh-dachristensen wants to merge 3 commits into
mainfrom
pgguru/issue-293-conninfo-errdetail

Conversation

@sfc-gh-dachristensen
Copy link
Copy Markdown
Collaborator

@sfc-gh-dachristensen sfc-gh-dachristensen commented May 18, 2026

When the connection to pgduck_server fails, the user-facing ERROR only says "could not start query engine", which leaves administrators with nothing to
debug a misconfigured server (e.g. environment variables overriding the configured conninfo).

This PR adds a LOG_SERVER_ONLY ereport before the user-facing ERROR with the connection string in errdetail. The conninfo lands in the PostgreSQL server
log where the administrator can see it, but is never sent to the client (which may be a less-trusted role and the conninfo can include credentials).

The user-facing ERROR is unchanged — the libpq error message is still only included in assertion-enabled builds, and the conninfo is never included.

It may still be worth a follow-up to look at the underlying behavior of environment variables superseding the configured connection string; that seems
undesirable.

Add an errdetail() clause to the "could not start query engine"
ereport() so users can see which connection string was being used
when the connection to pgduck_server failed.

Issue: #293
Signed-off-by: David Christensen <david.christensen@snowflake.com>
Comment thread pg_lake_engine/src/pgduck/client.c Outdated
sfc-gh-dachristensen added a commit that referenced this pull request May 22, 2026
Per review on PR #361: the connection string may include credentials and is
an internal detail not appropriate for the client. Emit a separate LOG
ereport() with errmsg + errdetail before the user-facing ERROR so
administrators can still debug misconfigured servers (issue #293) via the
PostgreSQL server log without leaking the conninfo to the client.

Signed-off-by: David Christensen <david.christensen@snowflake.com>
sfc-gh-dachristensen added a commit that referenced this pull request May 22, 2026
Per review on PR #361: the connection string may include credentials and is
an internal detail not appropriate for the client. Emit a separate LOG
ereport() with errmsg + errdetail before the user-facing ERROR so
administrators can still debug misconfigured servers (issue #293) via the
PostgreSQL server log without leaking the conninfo to the client.

Signed-off-by: David Christensen <david.christensen@snowflake.com>
@sfc-gh-dachristensen sfc-gh-dachristensen force-pushed the pgguru/issue-293-conninfo-errdetail branch from 181666a to c131d1e Compare May 22, 2026 22:21
Comment thread pg_lake_engine/src/pgduck/client.c
Per review on PR #361: the connection string may include credentials and is
an internal detail not appropriate for the client. Emit a separate LOG
ereport() with errmsg + errdetail before the user-facing ERROR so
administrators can still debug misconfigured servers (issue #293) via the
PostgreSQL server log without leaking the conninfo to the client.

Signed-off-by: David Christensen <david.christensen@snowflake.com>
@sfc-gh-dachristensen sfc-gh-dachristensen force-pushed the pgguru/issue-293-conninfo-errdetail branch from c131d1e to 085dd9b Compare May 22, 2026 22:24
Comment thread pg_lake_engine/src/pgduck/client.c
initStringInfo(&buf);

PGconn *probe = PQconnectStart(PgduckServerConninfo);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this when connections are failing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably PQconninfoParse() is a better choice here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though that doesn't incorporate defaults; will poke around a little more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a combination of PQconndefaults() and that should work.

Add ResolvePgduckConninfo(), which uses PQconnectStart + PQconninfo to
let libpq overlay environment variables (PGHOSTADDR, PGPORT, etc.) and
compiled-in defaults onto pg_lake_engine.host, then formats the result
as a conninfo string with passwords and debug-only fields stripped.

The LOG_SERVER_ONLY errdetail emitted on connection failure now uses
this resolved string, so an administrator debugging issue #293-style
env-var overrides sees the values libpq actually used rather than just
the configured GUC.

Signed-off-by: David Christensen <david.christensen@snowflake.com>
@sfc-gh-dachristensen sfc-gh-dachristensen force-pushed the pgguru/issue-293-conninfo-errdetail branch from 0df0208 to bba35ff Compare May 28, 2026 16:09

if (defaults == NULL)
{
/* OOM inside libpq; fall back to the raw configured string */
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fairly useless to do this if we're in OOM situation, but YOLO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants