Table vs. row level locks confusion

Started by Peter Eisentrautover 24 years ago2 messages
#1Peter Eisentraut
peter_e@gmx.net

The following section

http://www.ca.postgresql.org/devel-corner/docs/postgres/locking-tables.html

titled "Locking and Tables", has two subsections, "Table-level locks" and
"Row-level locks". Under table-level locks we find lock names such as
RowShareLock and RowExclusiveLock -- are those table-level locks? Under
row-level locks we find no specific lock names mentioned.

What I wonder is, if I do

BEGIN;
LOCK table1 IN ROW EXCLUSIVE MODE;

what do I lock? The table? A row? Which row?

Clarification appreciated.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: Table vs. row level locks confusion

Peter Eisentraut <peter_e@gmx.net> writes:

The following section
http://www.ca.postgresql.org/devel-corner/docs/postgres/locking-tables.html
titled "Locking and Tables", has two subsections, "Table-level locks" and
"Row-level locks". Under table-level locks we find lock names such as
RowShareLock and RowExclusiveLock -- are those table-level locks?

Yes, despite the names. (The various lock-type names are pretty
horrible IMHO, but they are claimed to be Oracle-compatible.)
Anything you do with a LOCK command is a table-level lock.

Under row-level locks we find no specific lock names mentioned.

The only row-level locking mechanism available to users is
to UPDATE, DELETE, or SELECT FOR UPDATE a particular row.
All rows affected by such a command are locked against other
such commands (but not against plain SELECT).

regards, tom lane