By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,660 Members | 1,299 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,660 IT Pros & Developers. It's quick & easy.

Question regarding Perl, DBI, and fork()

P: n/a
I have a job-processing backend written in perl, talking to a (of course)
postgres database. The perl app has a master process that checks the
database periodically for jobs that need processed. When there are
available jobs, it grabs some number of them (up a few hundred), and
fork()'s to create job processing processes, one per job, again up to a few
hundred.

I know the child processes inherit the db handle, as I learned the hard way
about InactiveDestroy ;) so my question is this:

Can the children (safely) use this handle to run database queries, or
should I just consider the handle garbage? I didn't want to "just try and
see" because there's always the possibility it could work "by accident"
during the low-load testing, and fail at some other time.

Relevant versions of everything are:

FreeBSD 4.8 (Tracking RELENG_4, now 4.9-RC)
PostGreSQL 7.3.4
perl 5.003 (FreeBSD default)
perl DBI 1.37
perl DBD::Pg 1.22

I'm on the list, CC directly only if you're bored. Thanks.

-Allen
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sun, Oct 26, 2003 at 03:04:29PM -0500, Allen Landsidel wrote:
Can the children (safely) use this handle to run database queries, or
should I just consider the handle garbage? I didn't want to "just try and
see" because there's always the possibility it could work "by accident"
during the low-load testing, and fail at some other time.
No, you can't. Even multithread programs can't use the same connection at
the same time (they can if serialised or if they use different connections).

Now, getting rid of the handle without it closing the connection would be a
trick.
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ "All that is needed for the forces of evil to triumph is for enough good
men to do nothing." - Edmond Burke
"The penalty good people pay for not being interested in politics is to be
governed by people worse than themselves." - Plato


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE/nE1oY5Twig3Ge+YRAuC5AJ48M+224nRfrGgF9OHGl1PsHWlO1w CbBZSc
oF6pwwvw9dHy4Vi75LQFxZw=
=Pmon
-----END PGP SIGNATURE-----

Nov 12 '05 #2

P: n/a
When grilled further on (Mon, 27 Oct 2003 09:40:40 +1100),
Martijn van Oosterhout <kl*****@svana.org> confessed:
On Sun, Oct 26, 2003 at 03:04:29PM -0500, Allen Landsidel wrote:
Can the children (safely) use this handle to run database queries, or
should I just consider the handle garbage? I didn't want to "just try and
see" because there's always the possibility it could work "by accident"
during the low-load testing, and fail at some other time.


No, you can't. Even multithread programs can't use the same connection at
the same time (they can if serialised or if they use different connections).

Now, getting rid of the handle without it closing the connection would be a
trick.


I've had good success setting InactiveDestroy (as Allen found), and in my
children, I re-connect to the db. Works for me, although I'm only using up to
16 children + parent.

Cheers,
Rob

--
17:35:03 up 86 days, 10:58, 4 users, load average: 2.09, 2.04, 2.00

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iEYEARECAAYFAj+canYACgkQgy51bQc2FFk07gCg1+bNp1P4sM qBQHYlQEFlT/ay
BXwAn36Ra/QMftBUjpZ9YboevKQhM9ov
=C8Ww
-----END PGP SIGNATURE-----

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.