Skip to content

pgconn: read the default service file from %APPDATA%\postgresql on Windows - #2697

Merged
jackc merged 2 commits into
jackc:masterfrom
b84330808:windows-default-servicefile
Oct 27, 2026
Merged

jackc merged 2 commits into
jackc:masterfrom
b84330808:windows-default-servicefile

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

On Windows, libpq looks for the per-user connection service file at %APPDATA%\postgresql\.pg_service.conf, next to pgpass.conf (see https://www.postgresql.org/docs/current/libpq-pgservice.html and pqGetHomeDirectory in fe-connect.c). pgx looks for it at %USERPROFILE%\.pg_service.conf, so a service that works with psql can't be found by pgx:

cannot parse `service=abc`: failed to read service (failed to read service file: C:\Users\me\.pg_service.conf)

This makes the libpq location the default when APPDATA is set, the same as passfile and the SSL files already do. If there is no file there but %USERPROFILE%\.pg_service.conf exists, pgx keeps using that one so existing setups don't break. Happy to drop that fallback if you'd rather match libpq exactly.

The new tests in pgconn/defaults_windows_test.go only build on Windows. Two of them fail on master and all three pass with this change.

This is an AI proposal: I used Claude Code (Claude Opus 5.5) to write this change. The prompt was a general "find, reproduce and fix a real bug in a Go database library" brief; it found this by comparing pgx's Windows defaults with libpq's.

b84330808 and others added 2 commits October 25, 2026 00:27
…ndows

libpq looks for the per-user connection service file at
%APPDATA%\postgresql\.pg_service.conf on Windows, next to pgpass.conf
and the client certificates. pgx looked for it at
%USERPROFILE%\.pg_service.conf instead, so a service set up for psql
could not be found by pgx.

The old location is still used when there is no service file at the
libpq location, so existing setups keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jackc
jackc merged commit 65a4125 into jackc:master Oct 27, 2026
22 checks passed
@jackc

jackc commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Merged with a small tweak to the fallback logic.

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