Skip site navigation (1) Skip section navigation (2)

Re: Change lock requirements for adding a trigger

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Decibel! <decibel(at)decibel(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Change lock requirements for adding a trigger
Date: 2008-06-13 20:06:50
Message-ID: 1213387611.25121.250.camel@ebony.site (view raw or flat)
Thread:
Lists: pgsql-hackers
On Wed, 2008-06-04 at 16:33 -0400, Tom Lane wrote:
> Simon Riggs <simon(at)2ndquadrant(dot)com> writes:
> > We have
> > * relhasindex (bool) set by CREATE INDEX but not unset by DROP INDEX
> > * relhasrules (bool)
> > * reltriggers (int2)  set by CREATE and DROP, since its an integer
> 
> Right.
> 
> > If CREATE INDEX can take a Share lock and can update pg_class, why would
> > it not be theoretically possible for CREATE TRIGGER? 
> 
> It's (probably) theoretically possible, if we replace reltriggers with a
> bool that acts more like relhasindex, ie it's a hint to go look in
> pg_triggers.  

Looking at this area of locking, I've noticed that the locks held by
CREATE TRIGGER are more of a problem than might be apparent. 

* Locks held by CREATE TRIGGER are an issue for trigger-based
replication systems, where triggers are frequently added and removed to
various tables.

* ALTER TABLE .. ADD FOREIGN KEY holds an AccessExclusiveveLock on
*both* referencing and referenced tables. It does this because we must
add triggers to both tables. So reducing the lock strength required by
CREATE TRIGGER would also allow a reduction in lock strength for adding
FKs.

So useful steps will be to

* refactor pg_class code so that CREATE TRIGGER uses an identical
approach to CREATE INDEX

* reduce lock strength for CREATE TRIGGER and ALTER TABLE ... ADD
FOREIGN KEY so that it takes a ShareLock during
ATAddForeignKeyConstraint()

* look at how we can reduce lock strength for other ALTER TABLE
subcommands. Not sure how yet.

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


In response to

Responses

pgsql-hackers by date

Next:From: Alvaro HerreraDate: 2008-06-13 20:14:13
Subject: Re: TODO Item: Allow pg_hba.conf to specify host namesalong with IP addresses
Previous:From: Dickson S. GuedesDate: 2008-06-13 19:54:20
Subject: Re: TODO Item: Allow pg_hba.conf to specify host names along with IP addresses

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group