- changed milestone to 0.7.6
[DOCS] No example of Unix Domain socket connections in 'Database Urls' section
In the section Database Urls all the examples are for TCP socket connection and there is not a single example for Unix domain socket. Here's a simple one:
postgresql:///database?user=foo&host=/var/run/postgresql
Also, in the same section, there's a link to RFC-1738, but it seems that rfc.net is currently offline.
Comments (6)
-
repo owner -
reporter Replying to zzzeek:
if you skip the "host" portion of the URL, psycopg2 will use a unix socket, though this behavior is not confirmed across other database backends. I'm not familiar with using "/var/run/postgresql" as the "host" is there a source for that usage ? It's not listed at http://initd.org/psycopg/docs/module.html .
Not much source, but my own experimentation. When I change 'host' to '/var/lib/postgresql' it fails with error:
OperationalError: (OperationalError) could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/lib/postgresql/.s.PGSQL.5432"?
Apparently, when the 'host' part is dropped, it defaults to '/var/run/postgresql'. And the '.s.PGSQL.%d' part is automatically appended with 'port' key.
-
repo owner I'm not too keen on adding to the main docs an undocumented and not sure if its supported use case with psycopg2, do you think you can ping them and get them to confirm/ document this use case? Also this would really be under the "psycopg2 notes" and not the main "connecting with URLs" section. More links under "connecting with URLs" to the individual dialect "connecting" sections would be more appropriate here. I'd break the example into individual blurbs for each dialect along with a link.
-
reporter Ok, did a bit reading and it seems that psycopg2's {{{connect()}}} takes the variables and passes them directly to libpq's *PQconnectdbParams()] function that deals with the {{{host}}} following way:
host:: Name of host to connect to. If this begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. The default behavior when host is not specified is to connect to a Unix-domain socket in /tmp (or whatever socket directory was specified when PostgreSQL was built). On machines without Unix-domain sockets, the default is to connect to localhost.
-
repo owner - changed status to resolved
-
repo owner - removed milestone
Removing milestone: 0.7.6 (automated comment)
- Log in to comment
if you skip the "host" portion of the URL, psycopg2 will use a unix socket, though this behavior is not confirmed across other database backends. I'm not familiar with using "/var/run/postgresql" as the "host" is there a source for that usage ? It's not listed at http://initd.org/psycopg/docs/module.html .