Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 347691337B92 for ; Tue, 22 Feb 2011 02:48:10 -0400 (AST) 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 50016-05 for ; Tue, 22 Feb 2011 06:48:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og111.obsmtp.com (exprod7og111.obsmtp.com [64.18.2.175]) by mail.postgresql.org (Postfix) with ESMTP id 009351337B81 for ; Tue, 22 Feb 2011 02:48:01 -0400 (AST) Received: from source ([209.85.215.178]) (using TLSv1) by exprod7ob111.postini.com ([64.18.6.12]) with SMTP ID DSNKTWNcIGr82Fm+HVR2g//I9/Ga2/xDnWhH@postini.com; Mon, 21 Feb 2011 22:48:02 PST Received: by eya25 with SMTP id 25so1292920eya.9 for ; Mon, 21 Feb 2011 22:47:59 -0800 (PST) Received: by 10.14.45.74 with SMTP id o50mr2534144eeb.28.1298357279045; Mon, 21 Feb 2011 22:47:59 -0800 (PST) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id q52sm5651903eei.15.2011.02.21.22.47.57 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 Feb 2011 22:47:58 -0800 (PST) Message-ID: <4D635C1C.7040304@enterprisedb.com> Date: Tue, 22 Feb 2011 08:47:56 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.16) Gecko/20101226 Icedove/3.0.11 MIME-Version: 1.0 To: Mark Kirkwood CC: pgsql-bugs@postgresql.org Subject: Re: Hung Vacuum in 8.3 References: <4D6330E9.6030809@catalyst.net.nz> In-Reply-To: <4D6330E9.6030809@catalyst.net.nz> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201102/184 X-Sequence-Number: 29456 On 22.02.2011 05:43, Mark Kirkwood wrote: > This is 8.3.14 on Debian Lenny x86-64. > > I'm seeing a hung vacuum: > > postgres=# select procpid, query_start,waiting, current_query from > pg_stat_activity where current_query like '%VACUUM%'; > procpid | query_start | waiting | current_query > --------+-------------------------------+---------+--------------------------------------------------------------------------------------------- > > 7347 | 2011-02-22 06:02:02.400247+13 | f | VACUUM ANALYZE; > > at approx 1300 (so it has been sitting there for approx 7 hours, normal > database vacuum time is 10 minutes). Now according to pg_stat_activity > and pg_locks it is *not* waiting for a lock, but no vacuuming appears to > be going on. strace says: > > $ strace -p 7347 > > Process 7347 attached - interrupt to quit > semop(33456157, 0x7ffff512bad0, 1 > > Ok, so we are waiting on a semaphore - hmm, why is it not showing up as > waiting on a lock of some kind? > > Of interest is this: > > postgres=# select procpid, query_start, current_query from > pg_stat_activity order by query_start limit 1; > procpid | query_start | current_query > ---------+-------------------------------+------------------------------------------------------------------------------------- > > 25953 | 2011-02-22 04:24:07.417138+13 | SELECT n.node_id, n.node_ -- > long query, joining several large tables - text snipped > > So this guy had been running from before the vacuum started, so probably > vacuum is wanting to do lazy_truncate_heap() on one of the tables in the > join (no gdb on this box unfortunately). I am however still puzzled > about why no locks are being waited on. A long query on the same table can block vacuum. Vacuum needs to take a so-called "cleanup lock" on each page, which means that it has to wait until no other backend holds a pin on the page. A long-running query can keep a page pinned for a long time. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com