On 8/9/07, Joachim Schrod <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm new to this mailing list, so I don't know if this is a FAQ; but
> haven't found an answer via Google or Gmane search.

I wouldn't call it a FAQ, but it is not particularly DBD::Pg specific.
 The answers that I'll give apply for most drivers that you could use.

> What is the proper way to handle DBD::Pg database connections in
> subprocesses?
> I have a master process that has a connection open (and changes the
> database). The subprocesses need to access the database as well.
>
> I understand that I have to set the master's connection $dbh
> attribute InactiveDestroy to true in the child processes, to
> prevent them disconnecting the master connection.

Yes.  And you can't send any information over that connection in the
child process else you'll have nasty race conditions and a confused
server.  (Because the server won't know what communication is coming
from the parent, and what is from the child.

> My first question is: Before I do so, can I use $dbh->clone() to
> create a new connection for the child process, or should I issue a
> new connect() statement for that?
> If both works, are there any advantages or disadvantages that I
> should be aware of?

You can call clone before or after.  Please be aware that all that
clone does is issue a connect that is the same as the original connect
- the connection will therefore be in the original database.

> My second issue: AFAIU, setting InactiveDestroy is only needed for
> subprocesses that exit() or die(). If I have a fork/exec combo, I
> don't need that, do I? (Well, maybe for the case that exec won't
> succeed and the subprocess dies for that reason?)

I would still do that.  Because a future version of Perl could add
logic to do cleanup before calling exec.  Lest you think this is
hypothetical, exit used to not do cleanup, and now does.  (I forget
whether that bad decision was made in Perl 5.6 or 5.8.)

> Thanks in advance for any answer,

No problem.

> PS: I tried to post via gmane, but that doesn't work as gmane uses
> the [EMAIL PROTECTED] list. I hope that the email
> doesn't appear twice.

I only saw it once.  This doesn't mean that another copy won't appear
sometime in the future, but that hasn't happened yet.

Cheers,
Ben

Reply via email to