Re: after insert trigger hangs - Mailing list pgsql-general

From Tom Lane
Subject Re: after insert trigger hangs
Date
Msg-id 28727.1142607392@sss.pgh.pa.us
Whole thread Raw
In response to after insert trigger hangs  (pradeep singh <lets_begin_with_me@yahoo.com>)
List pgsql-general
pradeep singh <lets_begin_with_me@yahoo.com> writes:
> CREATE OR REPLACE FUNCTION recalc_add_bitset()
> RETURNS trigger AS $$

>     use DBI;
>     my $dbname = 'database_name';
>     my $dbh = DBI->connect("dbi:Pg:dbname='$dbname'",
> "postgres_user_id", "password", {AutoCommit => 0,
> RaiseError=>1});

That (using DBI in a trigger) is a really bad idea in most cases.
The DBI connection is a separate transaction that (a) can't see
the uncommitted results of your transaction and (b) can have lock
conflicts against your transaction.  I suspect (b) explains the
hang, though the part of the problem you've shown us doesn't make
it clear exactly why there's a conflict.

plperl has a database access protocol, learn to use it.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Slow trigger on identical DB but different machine
Next
From: Richard Huxton
Date:
Subject: Re: Encountering NULLS in plpgsql