X-Original-To: pgsql-hackers-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 889D59FB1BC for ; Thu, 14 Sep 2006 12:20:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 50611-08 for ; Thu, 14 Sep 2006 12:20:23 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C41689FA0FC for ; Thu, 14 Sep 2006 12:20:32 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k8EFKU4i029470; Thu, 14 Sep 2006 11:20:30 -0400 (EDT) To: andy cc: Alvaro Herrera , pgsql-hackers@postgreSQL.org Subject: Re: [ADMIN] Vacuum error on database postgres In-reply-to: <45095CDD.8090704@squeakycode.net> References: <44F82150.5000809@pnlassociates.com> <4001.1157121669@sss.pgh.pa.us> <27602.1158238299@sss.pgh.pa.us> <45095CDD.8090704@squeakycode.net> Comments: In-reply-to andy message dated "Thu, 14 Sep 2006 08:45:01 -0500" Date: Thu, 14 Sep 2006 11:20:30 -0400 Message-ID: <29469.1158247230@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.107 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/1116 X-Sequence-Number: 90645 andy writes: > Tom Lane wrote: >> andy writes: >>> So I'm ok, but I tried it again, by dropping the database and re-running >>> both scripts and got the same error again. So thought I'd offer a test >>> case if there was interest. >> >> Absolutely. I've seen just enough of these reports to make me think >> there's an underlying bug. > Here are some urls: ... Doh ... I think the critical bit is here: autovacuum = on # enable autovacuum subprocess? The problem is that ANALYZE takes only AccessShareLock on a table, so it's entirely possible for two backends to try to ANALYZE the same table concurrently, and in particular for autovacuum to try to do so while your foreground VACUUM ANALYZE is running. That leads to concurrent insertion attempts into pg_statistic for the same key. This behavior dates from a time when there was no good alternative. One possible fix today would be to make ANALYZE take ShareUpdateExclusive lock instead, thus ensuring there is only one ANALYZE at a time on a table. However I'm a bit concerned by the possibility that ANALYZE-inside-a-transaction could accumulate a whole bunch of such locks in a random order, leading at least to a risk of deadlocks against other ANALYZEs. (We have to hold the lock till commit, else we aren't fixing the problem.) Do we need a specialized lock type just for ANALYZE? Would sorting the target list of rel OIDs be enough? Perhaps it's not worth worrying about? regards, tom lane