Skip to content

Respect libpq env vars in the default Postgres URL - #1046

Open
ChrisJr404 wants to merge 1 commit into
xataio:mainfrom
ChrisJr404:respect-libpq-env-vars-in-default-url
Open

Respect libpq env vars in the default Postgres URL#1046
ChrisJr404 wants to merge 1 commit into
xataio:mainfrom
ChrisJr404:respect-libpq-env-vars-in-default-url

Conversation

@ChrisJr404

Copy link
Copy Markdown

Fixes #717.

Right now if you run pgroll without --postgres-url it falls back to a hardcoded postgres://postgres:postgres@localhost and silently ignores the libpq environment variables, so people coming from psql get a confusing connection attempt instead of one that uses their PGHOST/PGUSER/etc.

Following the direction in the issue, this keeps the local Postgres default when nothing is set, but lets PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE and PGSSLMODE override the individual fields when they are present. With no env vars set the default string is unchanged, so existing setups keep working.

The default is now built in internal/connstr.DefaultURL() and used as the flag default in cmd/root.go. Added table tests for the env var handling and a note in the CLI docs.

When --postgres-url is not set, pgroll fell back to a hardcoded
postgres://postgres:postgres@localhost default and ignored the standard
libpq environment variables. That is surprising for anyone used to psql
and friends, which pick up PGHOST, PGUSER and so on.

Keep defaulting to a local Postgres when nothing is set, but let PGHOST,
PGPORT, PGUSER, PGPASSWORD, PGDATABASE and PGSSLMODE override the
individual fields when they are present.
@github-actions
github-actions Bot temporarily deployed to Docs Preview August 25, 2026 14:49 Inactive
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.

pgroll init defaults to localhost:5432

1 participant