Multiple UNIX-domain sockets?

Lists: pgsql-novice
From: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
To: pgsql-novice(at)postgresql(dot)org
Subject: Multiple UNIX-domain sockets?
Date: 2006-09-25 15:58:36
Message-ID: 200609251558.k8PFwb0M088776@lurza.secnetix.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice


Hi,

I need to run a postgresql server with multiple UNIX-domain
sockets, i.e. not just the one in /tmp. Is that possible
at all? According to the documentation, the syntax of
unix_socket_directory doesn't seem to allow it.

(I had the idea to create hardlinks to the socket in /tmp,
but unfortunately /tmp is a separate file system on a
memory disk, so it's not possible to create hardlinks to
somewhere else.)

Best regards
Oliver

--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"With sufficient thrust, pigs fly just fine. However, this
is not necessarily a good idea. It is hard to be sure where
they are going to land, and it could be dangerous sitting
under them as they fly overhead." -- RFC 1925


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple UNIX-domain sockets?
Date: 2006-09-25 16:54:19
Message-ID: 11491.1159203259@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de> writes:
> I need to run a postgresql server with multiple UNIX-domain
> sockets, i.e. not just the one in /tmp. Is that possible
> at all?

No ... why would you need it?

(The postmaster could probably be made to do this if it was important,
but I don't see the use-case.)

> (I had the idea to create hardlinks to the socket in /tmp,
> but unfortunately /tmp is a separate file system on a
> memory disk, so it's not possible to create hardlinks to
> somewhere else.)

Wouldn't a symlink work?

regards, tom lane


From: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple UNIX-domain sockets?
Date: 2006-09-25 18:56:56
Message-ID: 200609251856.k8PIuujY098837@lurza.secnetix.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice


Tom Lane wrote:
> Oliver Fromme writes:
> > I need to run a postgresql server with multiple UNIX-domain
> > sockets, i.e. not just the one in /tmp. Is that possible
> > at all?
>
> No ... why would you need it?

See below.

> (The postmaster could probably be made to do this if it was important,
> but I don't see the use-case.)
>
> > (I had the idea to create hardlinks to the socket in /tmp,
> > but unfortunately /tmp is a separate file system on a
> > memory disk, so it's not possible to create hardlinks to
> > somewhere else.)
>
> Wouldn't a symlink work?

No, it wouldn't. I'm sorry, I should have explained why
I need it in the first place.

My operating system is FreeBSD, and it supports a feature
called "jails" which is similar to chroot, but has a lot
of additional functionality (separate process spaces and
other things). I would like to run an untrustworthy
application within such a jail. The application needs to
access a database, for which I will be using PostgreSQL.
However, I do not want to install postgres within the same
jail, because I intend to use it for other purposes, too.
In the future there might be a another application in a
different jail, which also accesses a postgres database.

Well, because of the chrooted environment, the application
cannot access postgres' socket in /tmp. Hardlinks don't
work because they're separate filesystems. Symlinks don't
work because a symlink cannot point to an object outside
of a jail.

The only solution would be to use TCP sockets on localhost,
but the TCP/IP overhead is considerably higher, especially
when there are lots of small queries (which I expect).
I've foiund several benchmarks in various mailinglists,
some mention a factor of 10.

Therefore I would definitely prefer to use UNIX-domain
sockets instead, if possible.

Best regards
Oliver

--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

PI:
int f[9814],b,c=9814,g,i;long a=1e4,d,e,h;
main(){for(;b=c,c-=14;i=printf("%04d",e+d/a),e=d%a)
while(g=--b*2)d=h*b+a*(i?f[b]:a/5),h=d/--g,f[b]=d%g;}


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple UNIX-domain sockets?
Date: 2006-09-25 19:07:09
Message-ID: 12475.1159211229@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de> writes:
> The only solution would be to use TCP sockets on localhost,
> but the TCP/IP overhead is considerably higher, especially
> when there are lots of small queries (which I expect).
> I've foiund several benchmarks in various mailinglists,
> some mention a factor of 10.

Really? A decently designed TCP stack should have enough shortcuts
for local traffic to be competitive with Unix sockets. Have you
measured a significant performance problem for yourself?

regards, tom lane


From: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple UNIX-domain sockets?
Date: 2006-09-26 13:15:27
Message-ID: 200609261315.k8QDFRdq048973@lurza.secnetix.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice


Tom Lane wrote:
> Oliver Fromme writes:
> > The only solution would be to use TCP sockets on localhost,
> > but the TCP/IP overhead is considerably higher, especially
> > when there are lots of small queries (which I expect).
> > I've foiund several benchmarks in various mailinglists,
> > some mention a factor of 10.
>
> Really? A decently designed TCP stack should have enough shortcuts
> for local traffic to be competitive with Unix sockets.

TCP/IP is a very non-trivial protocol. It has to deal with
fragmentation, re-assembly, retransmission and reordering,
calculating and verifying checksums, transmission window
control, packet filtering etc., and all of that includes
connections to localhost, too.

Compared to that, UNIX domain sockets are extremely simple.

> Have you
> measured a significant performance problem for yourself?

I have to admit that I haven't done any benchmarks myself.
The problem is that it's not easy (and takes much time) to
set up such benchmarks under realistic conditions and get
useful numbers. I've found the following postings:

http://freebsd.rambler.ru/bsdmail/freebsd-stable_2005/msg07530.html
http://freebsd.rambler.ru/bsdmail/freebsd-stable_2005/msg07442.html

They don't relate to PostgreSQL, though, but to other apps
that can use TCP sockets and UNIX sockets.

Best regards
Oliver

--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"Python is an experiment in how much freedom programmers need.
Too much freedom and nobody can read another's code; too little
and expressiveness is endangered."
-- Guido van Rossum