Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

Last modified 10 years ago

#4546 closed enhancement (fixed)

PATCH: Proper UNIX socket support for PostgreSQL

Reported by: pacopablo Owned by: Matthew Good
Priority: normal Milestone: 0.10.4
Component: general Version: 0.10.3
Severity: normal Keywords: postgresql, unix, socket
Cc: pacopablo@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Matthew Good)

Currently, if one wants to use UNIX sockets for PostgreSQL (much nicer than TCP), trac only supports connecting to the default socket defined in the PGHOST environment variable.

This is hackish.

Attached is a 2 line patch that allows the host to be specified in the database url. it also give preference to UNIX sockets of TCP sockets. This meaning that if a TCP host s specified and a UNIX socket are given, the UNIX socket will be used.

Usage:

postgres://user:password@/database?host=/path/to/socket/dir

Currently, one can only connect to the default socket dir via:

postgres://user:password@/database

Attachments (2)

postgres_unix_socket.patch (581 bytes ) - added by pacopablo 18 years ago.
patch to enable use of UNIX sockets withPostgreSQL
postgres_unix_socket.2.patch (579 bytes ) - added by pacopablo 18 years ago.
updated patch that supports both psycopg2 and pyPgSQL

Download all attachments as: .zip

Change History (7)

by pacopablo, 18 years ago

Attachment: postgres_unix_socket.patch added

patch to enable use of UNIX sockets withPostgreSQL

comment:1 by pacopablo, 18 years ago

Ok, so me and my bad typing. Obviously, the examples of the db strings should be the following:

postgres://user:password@/database?host=/path/to/socket/dir

and

postgres://user:password@/database

Will someone please fix the ticket description? Thanks

comment:2 by Matthew Good, 18 years ago

Description: modified (diff)
Milestone: 0.10.4
Owner: changed from Jonas Borgström to Matthew Good
Status: newassigned

Looks ok, though I'd like to check out how to do this for pyPgSQL as well too.

by pacopablo, 18 years ago

updated patch that supports both psycopg2 and pyPgSQL

comment:3 by pacopablo, 18 years ago

OK, just attached patch that is tested working with both psycopg2 and pyPgSQL.

They are both very similar except that pyPgSQL take positional parameters where psycopg2 takes a dsn. Anyway, the solution was to simply move the 2 lines before the if psycopg: block

in reply to:  3 comment:4 by Matthew Good, 18 years ago

Resolution: fixed
Status: assignedclosed

Replying to pacopablo:

OK, just attached patch that is tested working with both psycopg2 and pyPgSQL.

Thanks. I've applied the patch in r4579 and r4580 with a small change to use the in operator instead of has_key.

comment:5 by Ryan J Ollos, 10 years ago

Keywords: postgresql unix socket → postgresql, unix, socket

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matthew Good.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Matthew Good to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.