From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | dan(at)sidhe(dot)org |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Sharing database handles across forked child processes |
Date: | 2007-11-13 17:13:35 |
Message-ID: | 20071113171335.GC6945@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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.
> If one child closes the handle, what happens to the handle in all the
> other children? The parent?
Just closing the file descriptor is ok. Just forgetting about it is ok
too.. Best just ignore you have it open at all...
> This isn't a great thing to do, I realize, but I'm wedging database access
> into an existing heavily fork-bound perl program, so my hands are somewhat
> tied architecturally. (If it means I have to constantly test to see if the
> handle's valid, and may have to deal with a handle randomly going away on
> me, I can handle that -- I'm more worried about data corruption and
> deadlock problems here, stuff I can't reasonably catch at the application
> level)
You're going to need a seperate handle for each process. Two processes
writing to the same socket won't work. Maybe just setup a table indexed
by PID and make sure you only use your own. Or after a fork() do a
"close $dbh->getfd()" (untested).
Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-11-13 17:26:52 | Re: Sharing database handles across forked child processes |
Previous Message | dan | 2007-11-13 17:02:31 | Sharing database handles across forked child processes |