Last year, I questioned why CREATE TRIGGER acquires an
AccessExclusiveLock on its target table:

    http://archives.postgresql.org/pgsql-hackers/2005-03/msg00764.php

Acquiring an ExclusiveLock should be sufficient: we can safely allow
concurrent SELECTs on the table. (The -hackers thread discusses both
CREATE TRIGGER and ALTER TABLE ADD FK; the latter might require some
more consideration, so I'll tackle that later.)

This patch implements this change, and updates the documentation.

Barring any objections, I'll apply this in a day or two.

-Neil

Index: doc/src/sgml/mvcc.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/mvcc.sgml,v
retrieving revision 2.56
diff -c -r2.56 mvcc.sgml
*** doc/src/sgml/mvcc.sgml	23 Apr 2006 03:39:52 -0000	2.56
--- doc/src/sgml/mvcc.sgml	4 Jul 2006 06:21:07 -0000
***************
*** 683,691 ****
  	</para>
  
  	<para>
!          This lock mode is not automatically acquired on user tables by any
!          <productname>PostgreSQL</productname> command.  However it is
!          acquired on certain system catalogs in some operations.
  	</para>
         </listitem>
        </varlistentry>
--- 683,691 ----
  	</para>
  
  	<para>
!          Acquired by <command>CREATE TRIGGER</>. This lock mode is also
!          acquired by <productname>PostgreSQL</> on certain system catalogs in
!          some operations.
  	</para>
         </listitem>
        </varlistentry>
Index: src/backend/commands/trigger.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/commands/trigger.c,v
retrieving revision 1.203
diff -c -r1.203 trigger.c
*** src/backend/commands/trigger.c	16 Jun 2006 20:23:44 -0000	1.203
--- src/backend/commands/trigger.c	4 Jul 2006 06:21:13 -0000
***************
*** 92,98 ****
  	ObjectAddress myself,
  				referenced;
  
! 	rel = heap_openrv(stmt->relation, AccessExclusiveLock);
  
  	if (stmt->constrrel != NULL)
  		constrrelid = RangeVarGetRelid(stmt->constrrel, false);
--- 92,102 ----
  	ObjectAddress myself,
  				referenced;
  
! 	/*
! 	 * Make sure we block concurrent data-modifying commands and DDL, but we
! 	 * can safely allow SELECTs.
! 	 */
! 	rel = heap_openrv(stmt->relation, ExclusiveLock);
  
  	if (stmt->constrrel != NULL)
  		constrrelid = RangeVarGetRelid(stmt->constrrel, false);
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to