Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 0E7489FA4DB; Wed, 12 Sep 2007 17:30:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 07689-05; Wed, 12 Sep 2007 17:30:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 3FDE49FA5EF; Wed, 12 Sep 2007 17:30:29 -0300 (ADT) Received: from perhan.alvh.no-ip.org ([190.95.8.15]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l8CKUU3x008916; Wed, 12 Sep 2007 13:30:31 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 62B1847C68; Wed, 12 Sep 2007 16:30:28 -0400 (CLT) Date: Wed, 12 Sep 2007 16:30:28 -0400 From: Alvaro Herrera To: Tom Lane Cc: dx k9 , pgsql-admin@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: reindexdb hangs Message-ID: <20070912203028.GB6208@alvh.no-ip.org> References: <22018.1178144703@sss.pgh.pa.us> <20070825222150.GU31461@alvh.no-ip.org> <4909.1188082313@sss.pgh.pa.us> <20070829222341.GX7911@alvh.no-ip.org> <12577.1188428726@sss.pgh.pa.us> <20070830164151.GS5872@alvh.no-ip.org> <7460.1188500061@sss.pgh.pa.us> <20070910220700.GC3060@alvh.no-ip.org> <1367.1189470012@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1367.1189470012@sss.pgh.pa.us> User-Agent: Mutt/1.5.16 (2007-06-11) X-Virus-Scanned: ClamAV 0.91.1/4255/Wed Sep 12 00:18:47 2007 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Wed, 12 Sep 2007 13:30:31 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/83 X-Sequence-Number: 26844 Tom Lane wrote: > Alvaro Herrera writes: > > I am unsure if I should backpatch to 8.1: the code in cluster.c has > > changed, and while it is relatively easy to modify the patch, this is a > > rare bug and nobody has reported it in CLUSTER (not many people clusters > > temp tables, it seems). Should I patch only REINDEX? How far back? > > I'd say go as far back as you can conveniently modify the patch for. > This is a potential data-loss bug (even if only for temporary data) > so we ought to take it seriously. OK, I fixed it all the way back that it was needed: 7.4 for CLUSTER and 8.1 for REINDEX. Before 7.4 there wasn't a database-wide version of CLUSTER. This wasn't a very serious bug in any case, because it would have thrown an ERROR if it tried to cluster a remote temp table. So apparently no one ever saw it, because I can't remember any report about it. For REINDEX the story is very different, because what happens is that queries start silently returning wrong data. My test case was alvherre=# create temp table foo (a int primary key); NOTICE: CREATE TABLE / PRIMARY KEY creará el índice implícito «foo_pkey» para la tabla «foo» CREATE TABLE alvherre=# insert into foo select * from generate_series(1,40000); INSERT 0 40000 -- "reindex database alvherre" in another session alvherre=# select * from foo where a = 400; a ----- (0 rows) If you now REINDEX this table in the current session, it correctly returns one tuple. So if somebody is executing a procedure which involve temp tables and someone else concurrently does a REINDEX DATABASE, the queries of the first session are automatically corrupted. It seems like the worst kind of bug. Maybe we need additional protections on the bufmgr to prevent this kind of problem. We only introduced REINDEX DATABASE as a way to reindex user indexes in 8.1. Before that, it only considered system catalogs, which ISTM are never temp. Many thanks to dx k9 for the original report. -- Alvaro Herrera http://www.PlanetPostgreSQL.org/ "Endurecerse, pero jamás perder la ternura" (E. Guevara)