Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5A4131337B8B for ; Fri, 25 Mar 2011 11:16:24 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 42546-06 for ; Fri, 25 Mar 2011 14:16:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from spinlock.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id B0BFC1337B61 for ; Fri, 25 Mar 2011 11:16:13 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by spinlock.commandprompt.com (Postfix) with ESMTP id A6105348024; Fri, 25 Mar 2011 07:16:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at commandprompt.com Received: from spinlock.commandprompt.com ([127.0.0.1]) by localhost (spinlock.commandprompt.com.commandprompt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JBSCf+p6pKdb; Fri, 25 Mar 2011 07:16:11 -0700 (PDT) Received: from perhan.alvh.no-ip.org (unknown [190.95.20.220]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id 4F9ED348022; Fri, 25 Mar 2011 07:16:11 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 2747C6EA88; Fri, 25 Mar 2011 11:16:08 -0300 (CLST) Content-Type: text/plain; charset=UTF-8 Cc: pgsql-bugs Subject: Re: BUG #5946: Long exclusive lock taken by vacuum (not full) From: Alvaro Herrera To: Maxim Boguk In-reply-to: <201103250856.p2P8ufGc004544@wwwmaster.postgresql.org> References: <201103250856.p2P8ufGc004544@wwwmaster.postgresql.org> Date: Fri, 25 Mar 2011 11:16:08 -0300 Message-Id: <1301062308-sup-5944@alvh.no-ip.org> User-Agent: Sup/git Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201103/325 X-Sequence-Number: 29835 Excerpts from Maxim Boguk's message of vie mar 25 05:56:41 -0300 2011: > From documentation I know that vacuum (without full) can truncate empty > pages from end of a relation if they are free and vacuum successfully grabed > exclusive lock for short time. > > However, I wasn't ready to learn that 'short exclusive lock' can be 10-20 > minutes in some cases. > > In my case vacuum tried to truncate last 10-15GB from 100Gb relation, and > each time (3) it was cost 10+ minutes of service downtime (because that > table was completely locked). > > Is that correct behaviour? Are here any way to speedup that process or at > least allow read-only queries during that time? > > PS: no exessive disk IO observed during that 10+ min locks. I think you may be using a version prior to a fix we did to that code, to have it avoid sleeping due to vacuum_cost_delay. This shouldn't happen in 8.4 because it was fixed prior to that, though. Author: Alvaro Herrera Branch: master Release: REL8_3_0 [21c27af65] 2007-09-10 17:58:45 +0000 Branch: REL8_2_STABLE Release: REL8_2_5 [053731ab0] 2007-09-10 17:58:50 +0000 Branch: REL8_1_STABLE Release: REL8_1_10 [e52f4ec32] 2007-09-10 17:58:56 +0000 Branch: REL8_0_STABLE Release: REL8_0_14 [a44103519] 2007-09-10 17:59:03 +0000 Remove the vacuum_delay_point call in count_nondeletable_pages, because we hold an exclusive lock on the table at this point, which we want to release as soon as possible. This is called in the phase of lazy vacuum where we truncate the empty pages at the end of the table. An alternative solution would be to lower the vacuum delay settings before starting the truncating phase, but this doesn't work very well in autovacuum due to the autobalancing code (which can cause other processes to change our cost delay settings). This case could be considered in the balancing code, but it is simpler this way. -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support