Repository navigation
Conversation
Update documentation to accurately reflect libpq's full default chain: - dbname: mention PGDATABASE env var, then fallback to user name - user: add OS username fallback when PGUSER is not set - host,port: add libpq defaults (Unix socket, port 5432) when env vars unset - service: add PGSERVICE env var mention - postgresHasDefault(): clarify not all env vars are required Co-authored-by: krlmlr <[email protected]>
Co-authored-by: krlmlr <[email protected]>
…ssage Per reviewer feedback, dbConnect should remain fully deterministic. Only the postgresHasDefault() error message in default.R is updated to clarify libpq defaults. All changes to dbConnect_PqDriver.R and generated man pages are reverted. Co-authored-by: krlmlr <[email protected]>
Reverted all |
main's history was rewritten after the branch was cut, so every conflict resolves to main's version. The branch's own change to R/default.R is reworked in the next commit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
… server like other clients When the attempt with libpq's defaults fails and no host is set in the arguments or in `PGHOST`, `PGHOSTADDR` or `PGSERVICE`, both functions also try the socket directories `/var/run/postgresql`, `/private/tmp` and `/tmp`, each only if it holds a socket for the port, and then `localhost`, as sqlx and pgx do. `dbConnect()` is unchanged, and its documentation points to them. The message of `postgresHasDefault()` lists every failed attempt instead of implying that all `PG*` variables must be set. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
postgresDefault() and postgresHasDefault() find a local server like other clients
Question: fall back to
|
Question: fall back after any error, or only after connection failures?As of a240659,
Generated by Claude Code |
…st once `connect_default()` now stops at a server that answers with an error, skips the socket directory libpq has just tried, uses `connect_timeout = 5` for the fallbacks unless a timeout is set, uses the first port of a list for the socket file name, keeps the first line of each libpq message, and no longer passes `host` twice when the caller gives `host = NULL`. The DBItest context reuses the host the fallback found. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Question: should examples gated by
|
…ages in English Dropping every NULL argument turned `timezone = NULL` into the default "UTC". Only `host` is replaced now. The connection attempts run with `LANGUAGE=en`, so that the fallback also works where libpq's messages are translated, and the remembered host is documented as internal, for tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
…abase default time zone Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Accepted limitations
Generated by Claude Code |
|
Holding off to better understand the limitations. |
postgresDefault()andpostgresHasDefault()now find a local server in the places other PostgreSQL clients look, not only where the libpq that RPostgres links to was built to look.dbConnect()stays fully deterministic and unchanged; its documentation forhostandportpoints to the two functions.Closes #552.
Behavior
dbConnect(Postgres(), ...)exactly as before, so everything libpq does by itself still applies: thePG*environment variables,~/.pgpass, and libpq's compiled-in defaults.LANGUAGE=enas a best effort) and no host is chosen, neither in...(host,hostaddr,service) nor inPGHOST,PGHOSTADDRorPGSERVICE, they also try the socket directories/var/run/postgresql,/private/tmpand/tmp(each only if it holds.s.PGSQL.<port>for the first port, and not the one libpq just tried), thenhost = "localhost", withconnect_timeout = 5unless a timeout is set. A server that answers with an error, such as failed authentication, ends the search. Users who setPGHOSTetc. get the old single attempt.tests/testthat/helper-DBItest.Rreuses it.localhost.localhostis refused at once (about 30 ms here forpostgresHasDefault(port = 1)). CRAN examples and tests keep seeingFALSEand a skip.postgresHasDefault()message no longer implies that all ofPGHOST,PGPORT,PGUSER,PGPASSWORDandPGDATABASEmust be set; it lists every attempt with the first line of libpq's error and links the libpq environment variable docs.How other clients decide defaults
PG*variables,pg_service.conf,~/.pgpass, and the socket directory compiled into the libpq they load (libpq environment variables, psycopg connection docs).PGHOST,PGPORT,PGUSER,PGPASSWORD,PGDATABASEand more; withoutPGHOSTit uses the first of/var/run/postgresql,/private/tmp,/tmpholding.s.PGSQL.<port>, elselocalhost(default_host()). This PR follows it.PG*variables,.pgpassand the service file; the default host is the first existing directory of/var/run/postgresql,/private/tmp,/tmp, elselocalhost(defaultHost(),ParseConfig()).Config).PG*variables,~/.pgpass, elselocalhost:5432and the OS user, never a Unix socket by default (defaults.js).Overlap
A separate branch,
claude/fix-564-socket-dir, fixes #564 (dbConnect()looking for the socket in/tmpon Debian), which may change libpq's compiled-in socket directory. This PR touches onlyR/default.R, thehost,portdocumentation inR/dbConnect_PqDriver.Rand the generated man pages. With #564 fixed, the first attempt here succeeds more often and the fallbacks matter mostly for a libpq built elsewhere (static or bundled libpq, Homebrew vs. system server).Tests
tests/testthat/test-default.R: candidate selection with and without a host, first port of a port list, fallback order and error reporting (snapshot), stopping at a server that answered, skipping the socket libpq tried, the exact arguments reachingdbConnect()(host passed once, timeout added),postgresHasDefault()returningFALSEquickly with and withoutPGHOST, andpostgresDefault(timezone = NULL)keeping the database's default time zone.Review
Three rounds of clean review; nothing above Low remains. Accepted limitations.
History
Copilot started this PR by rewording the
postgresHasDefault()message. The branch was then merged withmain, whose history had been rewritten, resolving every conflict tomain's version.https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Generated by Claude Code