Re: Lock table, Select for update and Serialization error - Mailing list pgsql-general

From Albe Laurenz
Subject Re: Lock table, Select for update and Serialization error
Date
Msg-id AFCCBB403D7E7A4581E48F20AF3E5DB202CF7E68@EXADV1.host.magwien.gv.at
Whole thread Raw
In response to Lock table, Select for update and Serialization error  (sudhir <sudhirj@cse.iitb.ac.in>)
List pgsql-general
One last comment:

sudhir wrote:
> T1# BEGIN -- snapshot taken
> T1# Set transaction isolation level serializable;
> T2# BEGIN -- snapshot taken
> T2# Set transaction isolation level serializable;
> T1# Update account set bal=bal-100 where accno=129;

The 'snapshot taken' are misplaced.

The snapshots are actually taken when the first 'real'
statement in the transaction is executed.

In the case of T1, this would be at
  Update account set bal=bal-100 where accno=129;

This is, as Tom Lane has pointed out, the reason why
locking the table as first statement in a transaction
will prevent serialization errors.

Tom said, 'the first DML statement', but as far as I know
a SELECT statement will also cause the snapshot to be taken.

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: PFC
Date:
Subject: Re: Using a trigger with an object-relational manager
Next
From: Hannes Dorbath
Date:
Subject: Re: partial word matching