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 AFCCBB403D7E7A4581E48F20AF3E5DB202CB25FF@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>)
Responses Re: Lock table, Select for update and Serialization error
List pgsql-general
> As per postgres docs, 'Select for update' is used to obtain row level
> locks where as 'lock table' is used to obtain table level locks.
>
> Under serializable isolation level, select for update gives error if
> rows selected have been modified concurrently.
> but 'lock table' does not give such error even though some of the rows

> in the table are modified by concurrent transaction.
>
> Is this the expected behavior?

LOCK TABLE should never give you an error, except for a deadlock
resolution
error.

LOCK TABLE will just wait until there is no lock on the table that is
incompatible with the requested lock, then it will obtain the lock and
return.

LOCK TABLE does not modify tables or rows and so you cannot get a
serialization error, which is only issued when you run serializable
and try to modify a row that is newer than your transaction begin time.

On the other hand, LOCK TABLE will not necessarily prevent you from
subsequently receiving serialization errors if you do not request
an exclusive lock on the table.

Does that answer your questions?

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: Dave Page
Date:
Subject: Re: What is "Postgresql Hot"?
Next
From: Philippe Amelant
Date:
Subject: Re: Postgresql 8.2.4 crash with tsearch2