Re: Sharing database handles across forked child processes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: dan(at)sidhe(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: Sharing database handles across forked child processes
Date: 2007-11-13 17:26:52
Message-ID: 18873.1194974812@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> On Tue, Nov 13, 2007 at 12:02:31PM -0500, dan(at)sidhe(dot)org wrote:
>> How does Postgres handle sharing database handles across child processes?
>> That is, if I have a process that opens a connection to the database and
>> then forks a few child processes, what happens?
>>
>> Can the child processes safely use the handle?

> No.

For some time now, libpq has set FD_CLOEXEC on the socket connection to
the backend, which ensures that child processes won't be able to mess up
the parent's database connection. However it sounded like Dan might be
doing fork without exec, in which case he's definitely at risk ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Reg Me Please 2007-11-13 17:58:21 Re: Postgres table size
Previous Message Martijn van Oosterhout 2007-11-13 17:13:35 Re: Sharing database handles across forked child processes