Re: Table with invalid page blocks

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Gerdan Rezende dos Santos <gerdan(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Table with invalid page blocks
Date: 2015-12-07 00:18:24
Message-ID: 5664D050.1020501@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/4/15 11:34 AM, Gerdan Rezende dos Santos wrote:
> Someone has some way of identifying all invalid blocks of a table
> postgresql?
> Plpgsql a function, a tool, somehow.
>
>
> I found one solution on
> http://www.postgresql.org/message-id/1184245756.24101.178.camel@coppola.muc.ecircle.de,
> but I can not change in order to identify any defective blocks at once.

If your question is "How can I modify that function to report ALL
invalid CTIDs?" then you probably need to use a cursor and wrap the
FETCH in a BEGIN/END block with an exception handler. Something like:

DECLARE
curs refcursor;
rec record;
last_good tid;
bad boolean := false;
BEGIN
OPEN curs NO SCROLL FOR EXECUTE 'SELECT ctid FROM ' || table_name;
LOOP
BEGIN
FETCH curs INTO rec;
EXIT WHEN NOT FOUND;
IF bad THEN
RAISE WARNING 'Next good CTID %', rec.ctid;
bad := false;
END IF;
last_good := rec.ctid;
EXCEPTION WHEN OTHERS
RAISE WARNING E'Error %: %\nLast good CTID %', SQLSTATE, SQLERRM, last_good;
bad := true;
END;
END LOOP;
END;
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2015-12-07 00:28:07 Re: plperlu stored procedure seems to freeze for a minute
Previous Message Adrian Klaver 2015-12-06 22:46:18 Re: Generating an XSD file from an existing database