Skip to content

fix: handle host query parameter for unix socket connections#1378

Open
quad341 wants to merge 1 commit intogolang-migrate:masterfrom
quad341:fix/postgres-host-query-param
Open

fix: handle host query parameter for unix socket connections#1378
quad341 wants to merge 1 commit intogolang-migrate:masterfrom
quad341:fix/postgres-host-query-param

Conversation

@quad341
Copy link
Copy Markdown

@quad341 quad341 commented Mar 30, 2026

Summary

  • When host is specified as a query parameter (e.g., ?host=/var/run/postgresql for unix socket connections) and the URL has no host in the authority section, lib/pq silently connects to localhost:5432 instead of the specified socket path
  • This converts to a key-value connection string when a query-param host is detected so lib/pq reliably uses it
  • Adds test coverage for the host-as-query-param pattern

Test plan

  • Added testHostQueryParam test that connects using postgres:///db?host=<ip>&port=<port> format
  • Existing postgres driver tests still pass

🤖 Generated with Claude Code

…res driver

When host is specified as a query parameter (e.g., ?host=/var/run/postgresql
for unix socket connections) and the URL has no host in the authority section,
lib/pq silently connects to localhost:5432 instead. Convert to key-value
connection string so the host parameter is reliably used.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 54.481% (+0.05%) from 54.432%
when pulling 6b75efe on quad341:fix/postgres-host-query-param
into 2bd822b on golang-migrate:master.

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