Repository navigation
docs: Explain the default socket directory of dbConnect() - #673
Conversation
Without a host, libpq connects to the socket directory compiled into the libpq loaded at run time: /var/run/postgresql for Debian and Ubuntu's libpq, /tmp for upstream builds. Document this and the workarounds (`host` or `PGHOST`). Closes #564. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Question: How should RPostgres handle a libpq whose default socket directory is
|
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Superseded: Accepted limitationsSuperseded by #673 (comment).
Generated by Claude Code |
|
|
Redshift is reached over TCP, so `?Redshift` stays as on `main`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
|
Confirmed: Redshift clusters are reached over TCP only, so Unix sockets do not apply. Generated by Claude Code |
Accepted limitations
Generated by Claude Code |
|
Also resolve conflicts. |
…-dir Keep both the "Default host" section from this branch and the "Schemas" section from #675 in ?Postgres. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Closes #564.
Analysis
When neither
host,PGHOST, nor a service sets the host, libpq connects to a Unix-domain socket inDEFAULT_PGSOCKET_DIR, a compile-time constant of the libpq that is loaded at run time (on Windows, it connects tolocalhost). RPostgres does not choose it: on Linux,configurelinks-lpqdynamically against whateverpkg-config/pg_configfinds; nothing is bundled or downloaded.#define DEFAULT_PGSOCKET_DIR "/tmp"insrc/include/pg_config_manual.h./var/run/postgresql(debian/patches/51-default-sockets-in-var.patch, "Put server Unix sockets into /var/run/postgresql/ by default"). Checked in the Ubuntu noblepostgresql-16source package; the Debian bookworm archive was not reachable from the session, but the patch is Debian's own.libpq.so.5dynamically (objdump -p:NEEDED libpq.so.5), so they inherit the system default.Reproduction on Ubuntu 24.04 with a PostgreSQL 16 server whose socket is in
/var/run/postgresql:dbConnect(Postgres())connects, host/var/run/postgresql.libpq-dev: same.connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory, the exact error from the issue;postgresHasDefault()isFALSE. Withhost = "/var/run/postgresql"orPGHOST=/var/run/postgresql, it connects.So a Debian user sees
/tmpwhenever the libpq that ends up loaded is not Debian's: a source install of RPostgres whosepkg-config/pg_configpoints at a non-Debian libpq (PostgreSQL built from source, conda, Homebrew on Linux), or a non-Debianlibpq.so.5that precedes the system one on the run-time library path (R'setc/ldpathsin the Posit/rig builds puts/usr/local/libbefore/usr/lib/x86_64-linux-gnu). Which of these applied to the reporter is not known. The conda-forge and Homebrew defaults were not checked in this session.Change
Documentation only: a new "Default host" section in
?Postgresexplains where the default comes from (localhoston Windows; on Unix-like systems a socket directory compiled into libpq,/var/run/postgresqlin some distributions such as Debian and Ubuntu,/tmpupstream), the error it produces, and the two workarounds (host = "/var/run/postgresql"orPGHOST), and points topostgresHasDefault().?Redshiftis unchanged (man/Redshift.Rdis identical tomain): Redshift clusters are reached over TCP at their endpoint, so Unix-domain sockets do not apply. The text therefore lives in a Postgres-only section instead of the sharedhostparameter.dbConnect()itself stays unchanged: probing several socket directories would make it depend on the file system and could silently connect to a different server. This follows the stance stated on #553 thatdbConnect()should be fully deterministic and that onlypostgresDefault()/postgresHasDefault()should change. #553 (in progress oncopilot/align-postgres-default-settings) changes those helpers and their error message; this PR deliberately leavesR/default.Ralone to avoid conflicts. The options are posted as a question.No tests: the change is documentation only.
Clean review: no findings above Low; two wording fixes applied. Accepted limitations.
https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Generated by Claude Code