Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How to remove the warning: "there is already a transaction in progress" when using lock table

by angeloulivieri (Novice)
on Apr 13, 2016 at 20:08 UTC ( #1160340=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1160340]
Approved by Discipulus
Front-paged by cavac
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2022-10-07 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (30 votes). Check out past polls.

    Notices?