Greetings,
I'm writing a Perl DBI script using the DBD::Pg driver. There's a point
in the script at which I need to drop the database I'm working with and
recreate it from some files that have been generated by the script. I'm
calling the external dropdb and createdb programs to do this, after
calling $dbh->disconnect to disconnect from the database.
Unfortunately, the disconnect call apparently doesn't really disconnect,
because the dropdb command fails with an error that other users are
still connected to the database.
There are no active statement handles when I call disconnect (they've
all gone out of scope), so I don't think the problem is an active
statement. Furthermore, I tried adding $sth->finish calls to all the
statement handles, and it didn't help. I also tried calling
$dbh->DESTROY explicitly and setting $dbh to undef, and none of these
caused Perl to completely disconnect from the database.
I've searched on the Web and haven't found anything that addresses this
problem. I've also looked in the DBI and DBD::Pg source code but wasn't
able to figure anything out from them.
The only workaround I've been able to come up with is to put all the
code in the script from the DBI->connect to the $dbh->disconnect into a
subprocess, so that when the subprocess exits, the database handle will
definitely be gone. The problem with this approach is that there are
global variables that the database code needs to update, but of course
the changes it makes to those global variables in the subprocess don't
affect the parent that's waiting for the subprocess to exit.
Any suggestions?
Thanks,
Jonathan Kamens