X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E86D33A5C1E for ; Sat, 4 Dec 2004 17:35:49 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02183-06 for ; Sat, 4 Dec 2004 17:35:44 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 243143A5C48 for ; Sat, 4 Dec 2004 17:35:44 +0000 (GMT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 4C37C35649; Sat, 4 Dec 2004 09:34:31 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 4AC1135647; Sat, 4 Dec 2004 09:34:31 -0800 (PST) Date: Sat, 4 Dec 2004 09:34:31 -0800 (PST) From: Stephan Szabo To: sarlav kumar Cc: pgsqlperform Subject: Re: lock problem In-Reply-To: <20041204165641.75035.qmail@web51306.mail.yahoo.com> Message-ID: <20041204093004.D37548@megazone.bigpanda.com> References: <20041204165641.75035.qmail@web51306.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200412/99 X-Sequence-Number: 9474 On Sat, 4 Dec 2004, sarlav kumar wrote: > Thanks for the information on replication tools!! > Now, I have a question regarding locking tables and updating tables > that have a relationship to the locked table. > > I opened up two pgsql windows logged in using same userid. > Let's say I lock a table "customerdata" on one window. > begin; > lock table customerdata; > > Then in the other window,I want to make an update to table "customer". > begin; > update customer set status=0 where id=111; > > The relation ship between the two tables is as follows > customerdata.uid is FK on customer.id. There are no triggers that will > try to update customerdata table when the above update statement is > issued. > > My problem is the update does not continue unless the lock on > customerdata is released. Is it because the lock statement does a lock > on all related tables? Is it possible to lock only the particular table > we want to lock and not the related tables? The no action foreign key triggers grab a Row Share on the referencing table which conflicts with the Exclusive lock that LOCK TABLE takes by default. Depending on what you're trying to prevent, you may be able to ask lock table for a lesser lock (see the list and descriptions here: http://www.postgresql.org/docs/7.4/static/explicit-locking.html#LOCKING-TABLES ).