X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7DDF3D1B344 for ; Tue, 20 Jul 2004 15:30:28 -0300 (ADT) 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 58210-05 for ; Tue, 20 Jul 2004 18:30:27 +0000 (GMT) Received: from polaris.pinpointresearch.com (66-7-238-130.cust.telepacific.net [66.7.238.130]) by svr1.postgresql.org (Postfix) with ESMTP id E03FDD1B343 for ; Tue, 20 Jul 2004 15:30:19 -0300 (ADT) Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id 01E7B105EF; Tue, 20 Jul 2004 11:30:19 -0700 (PDT) From: Steve Crawford Organization: Pinpoint Research To: sad , pgsql-sql@postgresql.org Subject: Re: locks and triggers. give me an advice please Date: Tue, 20 Jul 2004 11:30:19 -0700 User-Agent: KMail/1.5.1 References: <000001c46ddd$491501d0$c201a8c0@borderveygqj37> <37d451f70407191529610a8eba@mail.gmail.com> <200407200936.44292.sad@bankir.ru> In-Reply-To: <200407200936.44292.sad@bankir.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200407201130.19676.scrawford@pinpointresearch.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/131 X-Sequence-Number: 18383 > often, I am turning triggers off and on to perform a mass operation > on a table, and i am interested how should i care of another user > operations. > > the scene is: > table t1 with user defined triggers > and many tables reference t1, (so FK triggers defined on t1) > > the operation i want to perform on t1 makes a great load to a > server and have no use in triggers at all. > the best way to perform this operation is to delete all records, > modify, and insert them back without changing any adjuscent table. > (this way takes a few seconds.) > so i turn off triggers on t1 completely (updating > pg_class.reltriggers) operate > and turn on triggers on t1. > > it works fine. > > the question is: > > what should i do to prevent other users of data modification on the > t1 and the adjuscent tables while triggers is off ? If I understand your question correctly you should use a transaction and lock the table; begin transaction; lock t1 in access exclusive mode; Turn off triggers and do your updates. (Note, "truncate t1" is faster than "delete from t1" followed by a "vacuum full" and you might consider running "reindex table t1" after your mass update or if appropriate drop your indexes, load the data, then recreate them.) Re-establish triggers. commit; --end of transaction unlocks the table Cheers, Steve