pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: lara.schembri@nyxgg.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14621: ERROR: compressed data is corrupt
Date: Wed, 12 Apr 2017 14:00:44 +0100
Message-ID: <87tw5tvlzn.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <8691.1491999088@sss.pgh.pa.us>
References: <20170412073107.25947.15117@wrigleys.postgresql.org>
	<8691.1491999088@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:

 >> Please note i have tried the chk function 
 >> declare t text;                          
 >> begin t := $1;                           
 >> return false;                          
 >> exception when others then return true;
 >> end;                                     

 >> which did not work.

 Tom> You would get better responses if you defined what you meant by
 Tom> "did not work", but I'm going to guess that the issue is that this
 Tom> code failed to expose corrupted data.  That's probably because it
 Tom> would have just assigned the bad datum to "t" without
 Tom> decompressing it.

The original intended use of that function (which is one I used to give
out regularly to people on IRC when working with them on data corruption
issues, and no doubt some of them have subsequently posted it on blogs
or whatnot) is to pass in the whole-row var for $1 like so:

select ctid, id from brokentable t where chk(t);

the intent being to detect failures of external toast fetches or other
corruption symptoms.

Unfortunately this is no longer as useful as it was, since a fix some
time back now has chk(t) detoast the fields of t before entering the
function, so the exception doesn't get caught.  These days I usually
have people use this one instead:

create function chk(tid) returns boolean language plpgsql
as $f$
  declare
    r text;
  begin
    r := (select t from brokentable t where ctid=$1);
    return false;
  exception when others then
    return true;
  end;
$f$;

select ctid, id from brokentable t where chk(ctid);

In both versions of the function, it's relying on the fact that
everything will get detoasted and decompressed as part of casting the
record value to text.

-- 
Andrew (irc:RhodiumToad)


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (4+ messages)  latest in thread

Message-ID: <87tw5tvlzn.fsf@news-spur.riddles.org.uk>
Permalink:  ../87tw5tvlzn.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87tw5tvlzn.fsf@news-spur.riddles.org.uk

 · 

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: andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, lara.schembri@nyxgg.com
  Subject: Re: BUG #14621: ERROR: compressed data is corrupt
  In-Reply-To: <87tw5tvlzn.fsf@news-spur.riddles.org.uk>
  References: <20170412073107.25947.15117@wrigleys.postgresql.org> <8691.1491999088@sss.pgh.pa.us> <87tw5tvlzn.fsf@news-spur.riddles.org.uk>

* 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