Explain privileges required for LOCK. Minor wordsmithing too.
This commit is contained in:
parent
9ad737978d
commit
1d174c3086
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.29 2001/12/08 03:24:37 thomas Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.30 2002/01/18 01:05:43 tgl Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -76,8 +76,7 @@ where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
|
|||||||
<listitem>
|
<listitem>
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
Automatically acquired by <command>SELECT...FOR UPDATE</command>.
|
Automatically acquired by <command>SELECT ... FOR UPDATE</command>.
|
||||||
While it is a shared lock, may be upgraded later to a ROW EXCLUSIVE lock.
|
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
@ -175,6 +174,9 @@ where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
|
|||||||
Conflicts with ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE,
|
Conflicts with ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE,
|
||||||
SHARE, SHARE ROW EXCLUSIVE,
|
SHARE, SHARE ROW EXCLUSIVE,
|
||||||
EXCLUSIVE and ACCESS EXCLUSIVE modes.
|
EXCLUSIVE and ACCESS EXCLUSIVE modes.
|
||||||
|
This mode allows only concurrent ACCESS SHARE, i.e., only reads
|
||||||
|
from the table can proceed in parallel with a transaction holding
|
||||||
|
this lock mode.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -225,7 +227,7 @@ LOCK TABLE
|
|||||||
</computeroutput></term>
|
</computeroutput></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The lock was successfully applied.
|
The lock was successfully acquired.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -310,23 +312,26 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
For example, an application runs a transaction at READ COMMITTED isolation
|
For example, suppose an application runs a transaction at READ COMMITTED
|
||||||
level and needs to ensure the existence of data in a table for the
|
isolation level and needs to ensure the existence of data in a table for
|
||||||
duration of the
|
the duration of the
|
||||||
transaction. To achieve this you could use SHARE lock mode over the
|
transaction. To achieve this you could obtain SHARE lock mode over the
|
||||||
table before querying. This will protect data from concurrent changes
|
table before querying. This will prevent concurrent data changes
|
||||||
and provide any further read operations over the table with data in their
|
and ensure further read operations over the table see data in their
|
||||||
actual current state, because SHARE lock mode conflicts with any ROW EXCLUSIVE
|
actual current state, because SHARE lock mode conflicts with any ROW
|
||||||
one acquired by writers, and your
|
EXCLUSIVE lock acquired by writers, and your
|
||||||
<command>LOCK TABLE <replaceable class="PARAMETER">name</replaceable> IN SHARE MODE</command>
|
<command>LOCK TABLE <replaceable class="PARAMETER">name</replaceable> IN SHARE MODE</command>
|
||||||
statement will wait until any concurrent write operations commit or rollback.
|
statement will wait until any concurrent write operations commit or
|
||||||
|
rollback. Thus, once you obtain the lock, there are no uncommitted
|
||||||
|
writes outstanding.
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
To read data in their real current state when running a transaction
|
To read data in their actual current state when running a transaction
|
||||||
at the SERIALIZABLE isolation level you have to execute a LOCK TABLE
|
at the SERIALIZABLE isolation level, you have to execute the LOCK TABLE
|
||||||
statement before executing any DML statement, when the transaction defines
|
statement before executing any DML statement. A serializable
|
||||||
what concurrent changes will be visible to itself.
|
transaction's view of data will be frozen when its first DML statement
|
||||||
|
begins.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
</para>
|
</para>
|
||||||
@ -341,7 +346,7 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To continue with the deadlock (when two transaction wait for one another)
|
To continue with the deadlock (when two transactions wait for one another)
|
||||||
issue raised above, you should follow two general rules to prevent
|
issue raised above, you should follow two general rules to prevent
|
||||||
deadlock conditions:
|
deadlock conditions:
|
||||||
</para>
|
</para>
|
||||||
@ -364,8 +369,8 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Transactions should acquire two conflicting lock modes only if
|
Transactions should acquire two conflicting lock modes only if
|
||||||
one of them is self-conflicting (i.e., may be held by one
|
one of them is self-conflicting (i.e., may be held by only one
|
||||||
transaction at time only). If multiple lock modes are involved,
|
transaction at a time). If multiple lock modes are involved,
|
||||||
then transactions should always acquire the most restrictive mode first.
|
then transactions should always acquire the most restrictive mode first.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -399,19 +404,17 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
|
|||||||
</title>
|
</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<command>LOCK</command> is a <productname>PostgreSQL</productname>
|
<literal>LOCK ... IN ACCESS SHARE MODE</> requires <literal>SELECT</>
|
||||||
language extension.
|
privileges on the target table. All other forms of <command>LOCK</>
|
||||||
|
require <literal>UPDATE</> and/or <literal>DELETE</> privileges.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Except for ACCESS SHARE, ACCESS EXCLUSIVE, and SHARE UPDATE EXCLUSIVE lock
|
<command>LOCK</command> is useful only inside a transaction block
|
||||||
modes, the <productname>PostgreSQL</productname> lock modes and the
|
(<command>BEGIN</>...<command>COMMIT</>), since the lock is dropped
|
||||||
<command>LOCK TABLE</command> syntax are compatible with those
|
as soon as the transaction ends. A <command>LOCK</> command appearing
|
||||||
present in <productname>Oracle</productname>.
|
outside any transaction block forms a self-contained transaction, so the
|
||||||
</para>
|
lock will be dropped as soon as it is obtained.
|
||||||
|
|
||||||
<para>
|
|
||||||
<command>LOCK</command> works only inside transactions.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
</refsect2>
|
</refsect2>
|
||||||
@ -471,6 +474,13 @@ COMMIT WORK;
|
|||||||
concurrency levels on transactions. We support that too; see
|
concurrency levels on transactions. We support that too; see
|
||||||
<xref linkend="SQL-SET-TRANSACTION" endterm="SQL-SET-TRANSACTION-TITLE"> for details.
|
<xref linkend="SQL-SET-TRANSACTION" endterm="SQL-SET-TRANSACTION-TITLE"> for details.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
Except for ACCESS SHARE, ACCESS EXCLUSIVE, and SHARE UPDATE EXCLUSIVE lock
|
||||||
|
modes, the <productname>PostgreSQL</productname> lock modes and the
|
||||||
|
<command>LOCK TABLE</command> syntax are compatible with those
|
||||||
|
present in <productname>Oracle</productname>(TM).
|
||||||
|
</para>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
</refentry>
|
</refentry>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user