Skip site navigation (1) Skip section navigation (2)

Re: reindexdb hangs

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: dx k9 <bitsandbytes88(at)hotmail(dot)com>, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: reindexdb hangs
Date: 2007-09-12 20:30:28
Message-ID: 20070912203028.GB6208@alvh.no-ip.org (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-hackers
Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> 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)

In response to

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2007-09-12 21:47:47
Subject: Re: Patch queue triage
Previous:From: Josh BerkusDate: 2007-09-12 18:51:24
Subject: Re: RETURNING and DO INSTEAD ... Intentional or not?

pgsql-admin by date

Next:From: Tino SchwarzeDate: 2007-09-12 20:46:57
Subject: automatically detecting long timed locks
Previous:From: Joe ConwayDate: 2007-09-12 17:34:58
Subject: Re: how to change the port number for the Postgres server

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group