1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/mvcc.sgml,v 2.64 2006/10/20 20:35:13 neilc Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/mvcc.sgml,v 2.65 2006/12/01 01:04:36 tgl Exp $ -->
2
2
3
3
<chapter id="mvcc">
4
4
<title>Concurrency Control</title>
@@ -504,16 +504,17 @@ SELECT SUM(value) FROM mytab WHERE class = 2;
504
504
most <productname>PostgreSQL</productname> commands automatically
505
505
acquire locks of appropriate modes to ensure that referenced
506
506
tables are not dropped or modified in incompatible ways while the
507
- command executes. (For example, <command>ALTER TABLE</> cannot be
508
- executed concurrently with other operations on the same table.)
507
+ command executes. (For example, <command>ALTER TABLE</> cannot safely be
508
+ executed concurrently with other operations on the same table, so it
509
+ obtains an exclusive lock on the table to enforce that.)
509
510
</para>
510
511
511
512
<para>
512
513
To examine a list of the currently outstanding locks in a database
513
- server, use the <structname>pg_locks</structname> system view
514
- (<xref linkend="view-pg-locks">). For more
515
- information on monitoring the status of the lock manager
516
- subsystem, refer to <xref linkend="monitoring">.
514
+ server, use the
515
+ <link linkend="view-pg-locks"><structname>pg_locks</structname></link>
516
+ system view. For more information on monitoring the status of the lock
517
+ manager subsystem, refer to <xref linkend="monitoring">.
517
518
</para>
518
519
519
520
<sect2 id="locking-tables">
@@ -545,7 +546,6 @@ SELECT SUM(value) FROM mytab WHERE class = 2;
545
546
an <literal>ACCESS EXCLUSIVE</literal> lock cannot be held by more than one
546
547
transaction at a time) while others are not self-conflicting (for example,
547
548
an <literal>ACCESS SHARE</literal> lock can be held by multiple transactions).
548
- Once acquired, a lock is held till end of transaction.
549
549
</para>
550
550
551
551
<variablelist>
@@ -731,6 +731,16 @@ SELECT SUM(value) FROM mytab WHERE class = 2;
731
731
</para>
732
732
</tip>
733
733
734
+ <para>
735
+ Once acquired, a lock is normally held till end of transaction. But if a
736
+ lock is acquired after establishing a savepoint, the lock is released
737
+ immediately if the savepoint is rolled back to. This is consistent with
738
+ the principle that <command>ROLLBACK</> cancels all effects of the
739
+ commands since the savepoint. The same holds for locks acquired within a
740
+ <application>PL/pgSQL</> exception block: an error escape from the block
741
+ releases locks acquired within it.
742
+ </para>
743
+
734
744
</sect2>
735
745
736
746
<sect2 id="locking-rows">
@@ -741,8 +751,9 @@ SELECT SUM(value) FROM mytab WHERE class = 2;
741
751
can be exclusive or shared locks. An exclusive row-level lock on a
742
752
specific row is automatically acquired when the row is updated or
743
753
deleted. The lock is held until the transaction commits or rolls
744
- back. Row-level locks do not affect data querying; they block
745
- <emphasis>writers to the same row</emphasis> only.
754
+ back, in just the same way as for table-level locks. Row-level locks do
755
+ not affect data querying; they block <emphasis>writers to the same
756
+ row</emphasis> only.
746
757
</para>
747
758
748
759
<para>
@@ -759,7 +770,7 @@ SELECT SUM(value) FROM mytab WHERE class = 2;
759
770
other transactions from acquiring the same shared lock. However,
760
771
no transaction is allowed to update, delete, or exclusively lock a
761
772
row on which any other transaction holds a shared lock. Any attempt
762
- to do so will block until the shared locks have been released.
773
+ to do so will block until the shared lock(s) have been released.
763
774
</para>
764
775
765
776
<para>
@@ -882,10 +893,11 @@ UPDATE accounts SET balance = balance - 100.00 WHERE acctnum = 22222;
882
893
that are an awkward fit for the MVCC model. Once acquired, an
883
894
advisory lock is held until explicitly released or the session ends.
884
895
Unlike standard locks, advisory locks do not
885
- honor transaction semantics. For example, a lock acquired during a
896
+ honor transaction semantics: a lock acquired during a
886
897
transaction that is later rolled back will still be held following the
887
- rollback. The same lock can be acquired multiple times by its
888
- owning process: for each lock request there must be a corresponding
898
+ rollback, and likewise an unlock is effective even if the calling
899
+ transaction fails later. The same lock can be acquired multiple times by
900
+ its owning process: for each lock request there must be a corresponding
889
901
unlock request before the lock is actually released. (If a session
890
902
already holds a given lock, additional requests will always succeed, even
891
903
if other sessions are awaiting the lock.) Like all locks in
0 commit comments