http://www.perlmonks.org?node_id=1160340

angeloulivieri has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have searched a lot but couldn't find an answer to this. I am using the construct

$dbh = DBI->connect($dsn, $user, $pass, { RaiseError => 1, AutoCommit +=> 0 }); #Here we open a locked access to the database my $select_handle; eval{ $dbh->do("BEGIN WORK"); $dbh->do("LOCK TABLE $table"); ###CODE $dbh->do("COMMIT WORK"); };

To access a Postgres db in a exclusive way. This construct works fine but each time it is used a Warning comes out

WARNING: there is already a transaction in progress

Someone knows how can I avoid it? It is little annoying this print in the log file of my program which accesses tens of times to the database. Thanks in advance

  • Comment on How to remove the warning: "there is already a transaction in progress" when using lock table
  • Select or Download Code

Replies are listed 'Best First'.
Re: How to remove the warning: "there is already a transaction in progress" when using lock table
by runrig (Abbot) on Apr 13, 2016 at 20:39 UTC
    With AutoCommit => 0 you are already in a transaction. When you want to commit or rollback, do $dbh->commit() or $dbh->rollback(). Either of those implicitly starts a new transaction. Do not explicity execute "BEGIN WORK" or "COMMIT WORK".
Re: How to remove the warning: "there is already a transaction in progress" when using lock table
by Discipulus (Abbot) on Apr 13, 2016 at 20:42 UTC
    hello angeloulivieri,

    i think you'll get answer from monks with great psql experience, but reading here and there i can guess it is not a Perl issue but a warning (yes just an annoying one) caused (if i understand correctly) by the driver: the transaction is already started and psql give back this warning (for you safety)

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.