From: | "Joris Dobbelsteen" <Joris(at)familiedobbelsteen(dot)nl> |
---|---|
To: | <sudhirj(at)cse(dot)iitb(dot)ac(dot)in> |
Cc: | <pgsql-general(at)postgresql(dot)org>, "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at> |
Subject: | Re: Lock table, Select for update and Serialization error |
Date: | 2007-05-23 00:04:58 |
Message-ID: | 73427AD314CC364C8DF0FFF9C4D693FF037B40@nehemiah.joris2k.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>-----Original Message-----
>From: pgsql-general-owner(at)postgresql(dot)org
>[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of sudhir
>Sent: dinsdag 22 mei 2007 19:21
>To: Albe Laurenz
>Cc: pgsql-general(at)postgresql(dot)org
>Subject: Re: [GENERAL] Lock table, Select for update and
>Serialization error
>
>OK. In your example lock table command is used to avoid
>rollbacks due to concurrent transaction.
>So LOCK TABLE is useful in this situation.
>
>I have one last doubt:
>why there is difference between behavior of 'select for
>update' and 'lock table'.
>one causes serialization error and other does not.
>(even though both are variations of locking mechanism)
The locking level is at a very different level and you have to see the
implications of the diffent ways:
The LOCK statement is to prevent other transactions from accessing the
table. This is a high-level lock with very low overhead to take. The
disadvantage is obviously the performance impact is has, as it is highly
likely to block other transactions.
The mechanism is very useful to get some guarentees about what will
happen with the data in the table. This allows for synchronizing
modification between different transactions.
The select for update has two uses:
1) Ensure the data is current and remains so, for a small subset of a
table.
2) Prevent deadlocks caused by lock escallation.
What I didn't put explicitly is that select for update is to indicate
that a tuple will be updated.
For serializable it implies that the current version you see should be
current.
Obviously there is a common need for something with the concurrency
benefit of "select for update", but with relaxed requirements. The
postgres developers envisioned this and for this purpose use "select for
share".
The select for share only does:
1) Ensure the data is current and remains so, for a small subset of the
table.
Summarizing:
* Lock table - High-level: executes fast, but concurrency problems.
Guarentees about future changes.
Select for update - Low-level, concurrent, ensures data validity and
indicates its modified shortly.
Select for share - Low-level, concurrent, ensures data validity.
Hopefully this clears it up a bit.
- Joris Dobbelsteen
[snip]
From | Date | Subject | |
---|---|---|---|
Next Message | marcelo Cortez | 2007-05-23 00:13:05 | help with query |
Previous Message | Joris Dobbelsteen | 2007-05-22 23:35:56 | Re: Lock table, Select for update and Serialization error |