Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C56441337B5D for ; Tue, 8 Mar 2011 04:00:17 -0400 (AST) 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 06928-10 for ; Tue, 8 Mar 2011 08:00:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og114.obsmtp.com (exprod7og114.obsmtp.com [64.18.2.215]) by mail.postgresql.org (Postfix) with ESMTP id D3DC11337B4E for ; Tue, 8 Mar 2011 04:00:08 -0400 (AST) Received: from source ([209.85.215.173]) (using TLSv1) by exprod7ob114.postini.com ([64.18.6.12]) with SMTP ID DSNKTXXiB4DQIp7nbZq8d1yryOhIz9s+QV5/@postini.com; Tue, 08 Mar 2011 00:00:09 PST Received: by eyb6 with SMTP id 6so2149764eyb.18 for ; Tue, 08 Mar 2011 00:00:05 -0800 (PST) Received: by 10.213.113.20 with SMTP id y20mr3313857ebp.24.1299571205021; Tue, 08 Mar 2011 00:00:05 -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 t5sm385506eeh.20.2011.03.08.00.00.03 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Mar 2011 00:00:03 -0800 (PST) Message-ID: <4D75E201.20402@enterprisedb.com> Date: Tue, 08 Mar 2011 10:00:01 +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: Greg Stark CC: daveg , PostgreSQL-development Subject: Re: Re: PD_ALL_VISIBLE flag was incorrectly set happend during repeatable vacuum References: <4D2D6A56.9060808@enterprisedb.com> <20110228212832.GH26397@sonic.net> <1B3CCBDD-4AC6-404A-9E26-DB4CA2554228@endpoint.com> <20110303071208.GA4053@sonic.net> <4D6F4E5D.6080507@enterprisedb.com> <20110304090031.GE4053@sonic.net> <4D710ABD.5090103@enterprisedb.com> <20110307235340.GA21941@sonic.net> In-Reply-To: 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: 201103/534 X-Sequence-Number: 183784 On 08.03.2011 04:07, Greg Stark wrote: > Well from that log you definitely have OldestXmin going backwards. And > not by a little bit either. at 6:33 it set the all_visible flag and > then at 7:01 it was almost 1.3 million transactions earlier. In fact > to precisely the same value that was in use for a transaction at 1:38. > That seems like a bit of a coincidence though it's not repeated > earlier. Yep. After staring at GetOldestXmin() again, it finally struck me how OldestXmin can move backwards. You need two databases for it, which probably explains why this has been so elusive. Here's how to reproduce that: CREATE DATABASE foodb; CREATE DATABASE bardb; session 1, in foodb: foodb=# begin isolation level serializable; BEGIN foodb=# CREATE TABLE foo (a int4); -- just something to force this xact to have an xid CREATE TABLE foodb=# (leave the transaction open) session 2, in bardb: bardb=# CREATE TABLE foo AS SELECT 1; SELECT bardb=# vacuum foo; -- to set the PD_ALL_VISIBLE flag VACUUM session 3, in bardb: bardb=# begin isolation level serializable; BEGIN bardb=# SELECT 1; ?column? ---------- 1 (1 row) (leave transaction open) session 2, in bardb: bardb=# vacuum foo; WARNING: PD_ALL_VISIBLE flag was incorrectly set in relation "foo" page 0 (OldestXmin 803) VACUUM bardb=# What there are no other transactions active in the same database, GetOldestXmin() returns just latestCompletedXid. When you open a transaction in the same database after that, its xid will be above latestCompletedXid, but its xmin includes transactions from all databases, and there might be a transaction in some other database with an xid that precedes the value that GetOldestXmin() returned earlier. I'm not sure what to do about that. One idea is track two xmin values in proc-array, one that includes transactions in all databases, and another that only includes transactions in the same database. GetOldestXmin() (when allDbs is false) would only pay attention to the latter. It would add a few instructions to GetSnapshotData(), though. Another idea is to give up on the warning when it appears that oldestxmin has moved backwards, and assume that it's actually fine. We could still warn in other cases where the flag appears to be incorrectly set, like if there is a deleted tuple on the page. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com