Re: [Fwd: Re: deadlock on the same relation] - Mailing list pgsql-general

From Tom Lane
Subject Re: [Fwd: Re: deadlock on the same relation]
Date
Msg-id 6887.1133556366@sss.pgh.pa.us
Whole thread Raw
In response to [Fwd: Re: deadlock on the same relation]  ("Francesco Formenti - TVBLOB S.r.l." <francesco.formenti@tvblob.com>)
List pgsql-general
"Francesco Formenti - TVBLOB S.r.l." <francesco.formenti@tvblob.com> writes:
> Tom Lane wrote:
>> Probably you have been careless about avoiding "lock upgrade"
>> situations.

> Unfortunately, the first operation I do after the "BEGIN" declaration is
> the LOCK TABLE in access exclusive mode, and is the only explicit lock I
> perform in all the stored procedures.

If you mean that you placed a LOCK TABLE inside the stored procedure,
that's far from being the same thing as the start of the transaction.
For example, if your application does

    BEGIN;
    SELECT * FROM mytab;
    SELECT myprocedure();
    COMMIT;

then by the time control arrives inside myprocedure your transaction
already holds a nonexclusive lock on "mytab".  If you do LOCK TABLE mytab
inside the function then you're risking deadlock.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Reduce NUMERIC size by 2 bytes, reduce max length to 508 digits
Next
From: Jaime Casanova
Date:
Subject: Re: accessing text of the query in a rule