11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/mvcc.sgml,v 2.23 2002/02/18 16:13:10 tgl Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/mvcc.sgml,v 2.24 2002/03/27 02:36:51 petere Exp $
33-->
44
55 <chapter id="mvcc">
@@ -376,24 +376,28 @@ ERROR: Can't serialize access due to concurrent update
376376 </indexterm>
377377
378378 <para>
379- <productname>PostgreSQL</productname>
380- provides various lock modes tocontrol concurrent
381- access to data in tables. Some of these lock modesare acquired by
382- <productname>PostgreSQL</productname>
383- automatically before statement execution, while others are
384- provided to be used by applications. All lock modes acquired in a
385- transaction are held for the duration
386- of thetransaction .
379+ <productname>PostgreSQL</productname> provides various lock modes
380+ to control concurrent access todata in tables. Users normally
381+ need not be concerned about the different lock modesbecause
382+ <productname>PostgreSQL</productname> commands automatically
383+ acquire locks of appropriate modes to ensure data integrity while
384+ permitting an appropriate level of concurrent access.
385+ Nevertheless, a user can manually lock a table in any of the
386+ available modes using the<command>LOCK TABLE</command> command .
387387 </para>
388388
389- <sect2>
390- <title>Table-level locks</title>
389+ <para>
390+ The list below shows the available lock modes and the contexts in
391+ which they are used. Remember that all of these lock modes are
392+ table-level locks, even if the name contains the word
393+ <quote>row</quote>. The names of the lock modes are historical.
394+ </para>
391395
392- <para>
393396 <variablelist>
397+ <title>Table-level lock modes</title>
394398 <varlistentry>
395399 <term>
396- AccessShareLock
400+ <literal>ACCESS SHARE</literal>
397401 </term>
398402 <listitem>
399403<para>
@@ -402,170 +406,169 @@ ERROR: Can't serialize access due to concurrent update
402406</para>
403407
404408<para>
405- Conflicts with AccessExclusiveLock only.
409+ Conflicts with the <literal>ACCESS EXCLUSIVE</literal> lock
410+ mode only.
406411</para>
407412 </listitem>
408413 </varlistentry>
409414
410415 <varlistentry>
411416 <term>
412- RowShareLock
417+ <literal>ROW SHARE</literal>
413418 </term>
414419 <listitem>
415420<para>
416- Acquired by <command>SELECT FOR UPDATE</command>
417- and <command>LOCK TABLE</command>
418- <option>IN ROW SHARE MODE</option> statements.
421+ The <command>SELECT FOR UPDATE</command> command acquires a
422+ lock of this mode.
419423</para>
420424
421425<para>
422- Conflicts with ExclusiveLock and AccessExclusiveLock modes.
426+ Conflicts with the <literal>EXCLUSIVE</literal> and
427+ <literal>ACCESS EXCLUSIVE</literal> lock modes.
423428</para>
424429 </listitem>
425430 </varlistentry>
426431
427432 <varlistentry>
428433 <term>
429- RowExclusiveLock
434+ <literal>ROW EXCLUSIVE</literal>
430435 </term>
431436 <listitem>
432437<para>
433- Acquired by <command>UPDATE</command>, <command>DELETE </command>,
434- <command>INSERT </command> and <command>LOCK TABLE </command>
435- <option>IN ROW EXCLUSIVE MODE</option> statements .
438+ The commands <command>UPDATE</command>,
439+ <command>DELETE </command>, and <command>INSERT </command>
440+ automatically acquire this lock mode .
436441</para>
437442
438443<para>
439- Conflicts with ShareLock, ShareRowExclusiveLock, ExclusiveLock and
440- AccessExclusiveLock modes.
444+ Conflicts with the <literal>SHARE</literal>, <literal>SHARE ROW
445+ EXCLUSIVE</literal>, <literal>EXCLUSIVE</literal>, and
446+ <literal>ACCESS EXCLUSIVE</literal> lock modes.
441447</para>
442448 </listitem>
443449 </varlistentry>
444450
445451 <varlistentry>
446452 <term>
447- ShareUpdateExclusiveLock
453+ <literal>SHARE UPDATE EXCLUSIVE</literal>
448454 </term>
449455 <listitem>
450456<para>
451- Acquired by <command>VACUUM</command> (without <option>FULL</option>)
452- and <command>LOCK TABLE</command>
453- <option>IN SHARE UPDATE EXCLUSIVE MODE</option>
454- statements.
457+ Acquired by <command>VACUUM</command> (without <option>FULL</option>).
455458</para>
456459
457460<para>
458- Conflicts with ShareUpdateExclusiveLock, ShareLock,
459- ShareRowExclusiveLock, ExclusiveLock and AccessExclusiveLock modes.
461+ Conflicts with the <literal>SHARE UPDATE EXCLUSIVE</literal>,
462+ <literal>SHARE</literal>, <literal>SHARE ROW
463+ EXCLUSIVE</literal>, <literal>EXCLUSIVE</literal>, and
464+ <literal>ACCESS EXCLUSIVE</literal> lock modes.
460465</para>
461466 </listitem>
462467 </varlistentry>
463468
464469 <varlistentry>
465470 <term>
466- ShareLock
471+ <literal>SHARE</literal>
467472 </term>
468473 <listitem>
469474<para>
470- Acquired by <command>CREATE INDEX</command>
471- and <command>LOCK TABLE</command>
472- <option>IN SHARE MODE</option>
473- statements.
475+ Acquired by <command>CREATE INDEX</command>.
474476</para>
475477
476478<para>
477- Conflicts with RowExclusiveLock, ShareUpdateExclusiveLock,
478- ShareRowExclusiveLock,
479- ExclusiveLock and AccessExclusiveLock modes.
479+ Conflicts with the <literal>ROW EXCLUSIVE</literal>,
480+ <literal>SHARE UPDATE EXCLUSIVE</literal>, <literal>SHARE ROW
481+ EXCLUSIVE</literal>, <literal>EXCLUSIVE</literal>, and
482+ <literal>ACCESS EXCLUSIVE</literal> lock modes.
480483</para>
481484 </listitem>
482485 </varlistentry>
483486
484487 <varlistentry>
485488 <term>
486- ShareRowExclusiveLock
489+ <literal>SHARE ROW EXCLUSIVE</literal>
487490 </term>
488491 <listitem>
489492<para>
490- Acquired by <command>LOCK TABLE</command>
491- <option>IN SHARE ROW EXCLUSIVE MODE</option> statements.
493+ This lock mode is not automatically acquired by any command.
492494</para>
493495
494496<para>
495- Conflicts with RowExclusiveLock, ShareUpdateExclusiveLock,
496- ShareLock, ShareRowExclusiveLock,
497- ExclusiveLock and AccessExclusiveLock modes.
497+ Conflicts with the <literal>ROW EXCLUSIVE</literal>,
498+ <literal>SHARE UPDATE EXCLUSIVE</literal>,
499+ <literal>SHARE</literal>, <literal>SHARE ROW
500+ EXCLUSIVE</literal>, <literal>EXCLUSIVE</literal>, and
501+ <literal>ACCESS EXCLUSIVE</literal> lock modes.
498502</para>
499503 </listitem>
500504 </varlistentry>
501505
502506 <varlistentry>
503507 <term>
504- ExclusiveLock
508+ <literal>EXCLUSIVE LOCK</literal>
505509 </term>
506510 <listitem>
507511<para>
508- Acquired by <command>LOCK TABLE</command>
509- <option>IN EXCLUSIVE MODE</option> statements.
512+ This lock mode is not automatically acquired by any command.
510513</para>
511514
512515<para>
513- Conflicts with RowShareLock, RowExclusiveLock,
514- ShareUpdateExclusiveLock, ShareLock,
515- ShareRowExclusiveLock, ExclusiveLock and AccessExclusiveLock
516- modes.
516+ Conflicts with the <literal>ROW SHARE</literal>, <literal>ROW
517+ EXCLUSIVE</literal>, <literal>SHARE UPDATE
518+ EXCLUSIVE</literal>, <literal>SHARE</literal>, <literal>SHARE
519+ ROW EXCLUSIVE</literal>, <literal>EXCLUSIVE</literal>, and
520+ <literal>ACCESS EXCLUSIVE</literal> lock modes.
517521</para>
518522 </listitem>
519523 </varlistentry>
520524
521525 <varlistentry>
522526 <term>
523- AccessExclusiveLock
527+ <literal>ACCESS EXCLUSIVE</literal>
524528 </term>
525529 <listitem>
526530<para>
527- Acquired by <command>ALTER TABLE</command>,
528- <command>DROP TABLE</command>,
529- <command>VACUUM FULL</command> and <command>LOCK TABLE</command>
530- <option>IN ACCESS EXCLUSIVE MODE</option> (or plain
531- <command>LOCK TABLE</command>) statements.
531+ Acquired by the <command>ALTER TABLE</command>, <command>DROP
532+ TABLE</command>, and <command>VACUUM FULL</command> commands.
533+ This is also the default lock mode for <command>LOCK TABLE</command>
534+ statements that do not specify a mode explicitly.
532535</para>
533536
534537<para>
535- Conflicts with all modes (AccessShareLock, RowShareLock,
536- RowExclusiveLock, ShareUpdateExclusiveLock, ShareLock,
537- ShareRowExclusiveLock, ExclusiveLock and AccessExclusiveLock).
538+ Conflicts with locks of all modes ( <literal>ACCESS
539+ SHARE</literal>, <literal>ROW SHARE</literal>, <literal>ROW
540+ EXCLUSIVE</literal>, <literal>SHARE UPDATE
541+ EXCLUSIVE</literal>, <literal>SHARE</literal>, <literal>SHARE
542+ ROW EXCLUSIVE</literal>, <literal>EXCLUSIVE</literal>, and
543+ <literal>ACCESS EXCLUSIVE</literal>).
538544</para>
539545 </listitem>
540546 </varlistentry>
541547 </variablelist>
542548
543549 <note>
544550 <para>
545- Only AccessExclusiveLock blocks <command>SELECT</command> (without
546- <option>FOR UPDATE</option>) statement.
551+ Only an <literal>ACCESS EXCLUSIVE</literal> lock blocks a
552+ <command>SELECT</command> (without <option>FOR UPDATE</option>)
553+ statement.
547554 </para>
548555 </note>
549- </para>
550- </sect2>
551-
552- <sect2>
553- <title>Row-level locks</title>
554556
555557 <para>
556- Row-level locks are acquired when rows are being updated (or deleted or
557- marked for update).
558- Row-level locks don't affect data querying. They block
559- writers to <emphasis>the same row</emphasis> only.
558+ In addition to table-level locks, there are row-level locks.
559+ Row-level locks are acquired when rows are being updated (or
560+ deleted or marked for update). Row-level locks don't affect data
561+ querying; they block writers to <emphasis>the same row</emphasis>
562+ only. Row-level locks cannot be acquired explicitly by the user.
560563 </para>
561564
562565 <para>
563- <productname>PostgreSQL</productname>
564- doesn't remember any information about modified rows in memory and
565- so has no limit to the number of rows locked at one time. However,
566- locking a row may cause a disk write; thus, for example,
567- <command>SELECT FOR UPDATE</command> will modify
568- selected rows to mark them and so will result in disk writes.
566+ <productname>PostgreSQL</productname> doesn't remember any
567+ information about modified rows in memory, so is has no limit to
568+ the number of rows locked at one time. However, locking a row
569+ may cause a disk write; thus, for example, <command>SELECT FOR
570+ UPDATE</command> will modify selected rows to mark them and so
571+ will result in disk writes.
569572 </para>
570573
571574 <para>
@@ -575,7 +578,6 @@ ERROR: Can't serialize access due to concurrent update
575578 updated. Application writers normally need not be concerned with
576579 page-level locks, but we mention them for completeness.
577580 </para>
578- </sect2>
579581 </sect1>
580582
581583 <sect1 id="locking-indexes">