pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Hitesh Bhambhani <hitesh.bhambhani@asg.com>
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #5599: Vacuum fails due to index corruption issues
Date: Thu, 05 Aug 2010 11:06:57 -0400
Message-ID: <1880.1281020817@sss.pgh.pa.us> (raw)
In-Reply-To: <8B7319E089E48047A0B688CE9CF54FD855C3C916@USRES8MAIL.asg.com>
References: <201008042147.o74LlCge057659@wwwmaster.postgresql.org>
	<1280978913-sup-5475@alvh.no-ip.org>
	<8B7319E089E48047A0B688CE9CF54FD855C3C916@USRES8MAIL.asg.com>

Hitesh Bhambhani <hitesh.bhambhani@asg.com> writes:
>> From: Alvaro Herrera [mailto:alvherre@commandprompt.com]
>> Sent: Wednesday, August 04, 2010 11:30 PM
>> There probably is.  What kind of relation are the ones unable to truncate?
>> Please see in pg_class where relfilenode = '41274' in this
>> case:
>> 
> [HiteshB] the relation is called pmoinstance_idx_pmotypeid.

So the relation that couldn't be truncated is indeed the same one
complained of in the later message.

What it looks like to me is that page 30 was deleted, and then vacuum
tried to truncate it off the index altogether, and that failed because
of Windows randomness, and then later it's trying to delete page 30
again.  Which naturally fails because the parent downlink entry is long
gone.  But it's odd that it tries to delete page 30 twice.  The page
should have been in BTP_DELETED state before the truncate attempt, and
therefore should still be dead later, so why's it trying again?

[ thinks for a bit ... ]  I do see a way that could happen.  The page
could still be live on disk when we reach smgrtruncate(): the update
to BTP_DELETED state might only exist in a dirty shared buffer.  And
lookee here what smgrtruncate does:

    /*
     * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will
     * just drop them without bothering to write the contents.
     */
    DropRelFileNodeBuffers(reln->smgr_rnode, forknum, isTemp, nblocks);

So we throw away the BTP_DELETED state update without ever writing it to
disk, and then when the truncate fails, the old page state is still out
there, ready to confuse us later.

Seems like we need to think harder about recovering from a truncate
failure.  A few random ideas:

1. Write the dirty buffers before dropping them.  Kind of ugly from a
performance viewpoint, but simple and safe.

2. Treat truncation failure as a PANIC condition; then WAL replay will
fix things.  Unpleasant.  Actually, worse than unpleasant: I think what
the comment in RelationTruncate() is pointing out is that if the
failure is repeatable, we'd fail to recover at all.

3. Don't discard the dirty buffers until after successfully truncating.
The hard part here is to be sure no other process (like bgwriter) will
try to write them in between.  I don't see a way to guarantee that,
at least not without interlock infrastructure that doesn't exist today.

And see also that comment in RelationTruncate().  Seems like the whole
problem of coping with truncation failure needs more thought than we've
given it.

			regards, tom lane



view thread (18+ messages)  latest in thread

Message-ID: <1880.1281020817@sss.pgh.pa.us>
Permalink:  ../1880.1281020817@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1880.1281020817@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, hitesh.bhambhani@asg.com, alvherre@commandprompt.com
  Subject: Re: BUG #5599: Vacuum fails due to index corruption issues
  In-Reply-To: <1880.1281020817@sss.pgh.pa.us>
  References: <201008042147.o74LlCge057659@wwwmaster.postgresql.org> <1280978913-sup-5475@alvh.no-ip.org> <8B7319E089E48047A0B688CE9CF54FD855C3C916@USRES8MAIL.asg.com> <1880.1281020817@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox