Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id EB6271337B93 for ; Mon, 28 Mar 2011 17:01:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 10451-02 for ; Mon, 28 Mar 2011 20:01:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 171CD1337BD6 for ; Mon, 28 Mar 2011 17:01:35 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p2SK1XNY028595; Mon, 28 Mar 2011 16:01:34 -0400 (EDT) To: Christopher Browne cc: Robert Haas , Jan Wieck , pgsql-bugs Subject: Re: BUG #5946: Long exclusive lock taken by vacuum (not full) In-reply-to: References: <201103250856.p2P8ufGc004544@wwwmaster.postgresql.org> <4345.1301066239@sss.pgh.pa.us> <13556.1301069421@sss.pgh.pa.us> <1301080686-sup-7539@alvh.no-ip.org> <15329.1301082238@sss.pgh.pa.us> <16028.1301086103@sss.pgh.pa.us> <18898.1301286552@sss.pgh.pa.us> Comments: In-reply-to Christopher Browne message dated "Mon, 28 Mar 2011 15:01:10 -0400" Date: Mon, 28 Mar 2011 16:01:33 -0400 Message-ID: <28594.1301342493@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/367 X-Sequence-Number: 29877 Christopher Browne writes: > - Grab timestamp > - Grab exclusive lock > - Process [Some number of pages] > - Check time. > - If [# of ms] have passed then check to see if anyone else has a lock > O/S on the table. > - Commit & give up the lock for a bit if they do > - Go back and process more pages if they don't Actually, we could simplify that even further. Keep the code exactly as-is, but every small-number-of-pages, check to see if someone is waiting on a conflicting lock, and if so, fall out of the page checking loop. Truncate away however many pages we know at that time are safe, and end the vacuum normally. We'd have to rejigger the stuff in the lock manager that tries to boot autovacuum off the lock forcibly, but with a bit of luck that would get less crocky not more so. This wouldn't really have any parameters that require tuning, I think, and the max delay till the lock is released is not too much more than the time needed for ftruncate(). The really good thing about it is that vacuum's work is never wasted. regards, tom lane