Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cyHtw-0006vo-2R for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Apr 2017 13:01:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cyHtv-0003VL-KP for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Apr 2017 13:01:35 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cyHtE-0002Hv-G0 for pgsql-bugs@postgresql.org; Wed, 12 Apr 2017 13:00:52 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cyHtA-0004li-NK for pgsql-bugs@postgresql.org; Wed, 12 Apr 2017 13:00:51 +0000 Received: from [192.168.127.1] (port=23218 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1cyHt8-0003Ha-0E; Wed, 12 Apr 2017 13:00:46 +0000 Received: from [127.0.0.1] (port=52064 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1cyHt7-000B5P-5U; Wed, 12 Apr 2017 13:00:45 +0000 From: Andrew Gierth To: Tom Lane Cc: lara.schembri@nyxgg.com, pgsql-bugs@postgresql.org Subject: Re: BUG #14621: ERROR: compressed data is corrupt In-Reply-To: <8691.1491999088@sss.pgh.pa.us> (Tom Lane's message of "Wed, 12 Apr 2017 08:11:28 -0400") Message-ID: <87tw5tvlzn.fsf@news-spur.riddles.org.uk> References: <20170412073107.25947.15117@wrigleys.postgresql.org> <8691.1491999088@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 12 Apr 2017 14:00:44 +0100 MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org >>>>> "Tom" == Tom Lane 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