Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d174c3

Browse files
committed
Explain privileges required for LOCK. Minor wordsmithing too.
1 parent9ad7379 commit1d174c3

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

‎doc/src/sgml/ref/lock.sgml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.29 2001/12/08 03:24:37 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.30 2002/01/18 01:05:43 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -76,8 +76,7 @@ where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
7676
<listitem>
7777
<note>
7878
<para>
79-
Automatically acquired by <command>SELECT...FOR UPDATE</command>.
80-
While it is a shared lock, may be upgraded later to a ROW EXCLUSIVE lock.
79+
Automatically acquired by <command>SELECT ... FOR UPDATE</command>.
8180
</para>
8281
</note>
8382

@@ -175,6 +174,9 @@ where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
175174
Conflicts with ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE,
176175
SHARE, SHARE ROW EXCLUSIVE,
177176
EXCLUSIVE and ACCESS EXCLUSIVE modes.
177+
This mode allows only concurrent ACCESS SHARE, i.e., only reads
178+
from the table can proceed in parallel with a transaction holding
179+
this lock mode.
178180
</para>
179181
</listitem>
180182
</varlistentry>
@@ -225,7 +227,7 @@ LOCK TABLE
225227
</computeroutput></term>
226228
<listitem>
227229
<para>
228-
The lock was successfullyapplied.
230+
The lock was successfullyacquired.
229231
</para>
230232
</listitem>
231233
</varlistentry>
@@ -310,23 +312,26 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
310312
</para>
311313

312314
<para>
313-
For example, an application runs a transaction at READ COMMITTED isolation
314-
level and needs to ensure the existence of data in a table for the
315-
duration of the
316-
transaction. To achieve this you coulduse SHARE lock mode over the
317-
table before querying. This willprotect data fromconcurrent changes
318-
andprovide anyfurther read operations over the tablewith data in their
319-
actual current state, because SHARE lock mode conflicts with any ROW EXCLUSIVE
320-
one acquired by writers, and your
315+
For example,supposean application runs a transaction at READ COMMITTED
316+
isolationlevel and needs to ensure the existence of data in a table for
317+
theduration of the
318+
transaction. To achieve this you couldobtain SHARE lock mode over the
319+
table before querying. This willpreventconcurrent data changes
320+
andensurefurther read operations over the tablesee data in their
321+
actual current state, because SHARE lock mode conflicts with any ROW
322+
EXCLUSIVE lock acquired by writers, and your
321323
<command>LOCK TABLE <replaceable class="PARAMETER">name</replaceable> IN SHARE MODE</command>
322-
statement will wait until any concurrent write operations commit or rollback.
324+
statement will wait until any concurrent write operations commit or
325+
rollback. Thus, once you obtain the lock, there are no uncommitted
326+
writes outstanding.
323327

324328
<note>
325329
<para>
326-
To read data in their real current state when running a transaction
327-
at the SERIALIZABLE isolation level you have to execute a LOCK TABLE
328-
statement before executing any DML statement, when the transaction defines
329-
what concurrent changes will be visible to itself.
330+
To read data in their actual current state when running a transaction
331+
at the SERIALIZABLE isolation level, you have to execute the LOCK TABLE
332+
statement before executing any DML statement. A serializable
333+
transaction's view of data will be frozen when its first DML statement
334+
begins.
330335
</para>
331336
</note>
332337
</para>
@@ -341,7 +346,7 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
341346
</para>
342347

343348
<para>
344-
To continue with the deadlock (when twotransaction wait for one another)
349+
To continue with the deadlock (when twotransactions wait for one another)
345350
issue raised above, you should follow two general rules to prevent
346351
deadlock conditions:
347352
</para>
@@ -364,8 +369,8 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
364369
<listitem>
365370
<para>
366371
Transactions should acquire two conflicting lock modes only if
367-
one of them is self-conflicting (i.e., may be held by one
368-
transaction attime only). If multiple lock modes are involved,
372+
one of them is self-conflicting (i.e., may be held byonlyone
373+
transaction ata time). If multiple lock modes are involved,
369374
then transactions should always acquire the most restrictive mode first.
370375
</para>
371376

@@ -399,19 +404,17 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
399404
</title>
400405

401406
<para>
402-
<command>LOCK</command> is a <productname>PostgreSQL</productname>
403-
language extension.
407+
<literal>LOCK ... IN ACCESS SHARE MODE</> requires <literal>SELECT</>
408+
privileges on the target table. All other forms of <command>LOCK</>
409+
require <literal>UPDATE</> and/or <literal>DELETE</> privileges.
404410
</para>
405411

406412
<para>
407-
Except for ACCESS SHARE, ACCESS EXCLUSIVE, and SHARE UPDATE EXCLUSIVE lock
408-
modes, the <productname>PostgreSQL</productname> lock modes and the
409-
<command>LOCK TABLE</command> syntax are compatible with those
410-
present in <productname>Oracle</productname>.
411-
</para>
412-
413-
<para>
414-
<command>LOCK</command> works only inside transactions.
413+
<command>LOCK</command> is useful only inside a transaction block
414+
(<command>BEGIN</>...<command>COMMIT</>), since the lock is dropped
415+
as soon as the transaction ends. A <command>LOCK</> command appearing
416+
outside any transaction block forms a self-contained transaction, so the
417+
lock will be dropped as soon as it is obtained.
415418
</para>
416419

417420
</refsect2>
@@ -471,6 +474,13 @@ COMMIT WORK;
471474
concurrency levels on transactions. We support that too; see
472475
<xref linkend="SQL-SET-TRANSACTION" endterm="SQL-SET-TRANSACTION-TITLE"> for details.
473476
</para>
477+
478+
<para>
479+
Except for ACCESS SHARE, ACCESS EXCLUSIVE, and SHARE UPDATE EXCLUSIVE lock
480+
modes, the <productname>PostgreSQL</productname> lock modes and the
481+
<command>LOCK TABLE</command> syntax are compatible with those
482+
present in <productname>Oracle</productname>(TM).
483+
</para>
474484
</refsect2>
475485
</refsect1>
476486
</refentry>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp