Proposed toast info extraction function for disaster recovery

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Proposed toast info extraction function for disaster recovery
Date: 2005-06-07 21:48:31
Message-ID: 21430.1118180911@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I was just helping out some Red Hat colleagues who were trying to deal
with a corrupted database in which pg_dump was failing like so:

pg_dump: Error message from server: ERROR: missing chunk number 3 for toast value 205026

Frequently the best recovery action for this involves finding and
deleting the row that references the TOAST value ... but there is no
good way to find that row. AFAIK you have to engage in a very tedious
binary search to see where you get the error and where you don't. On
a large table this is just not fun at all; especially if you have or
think you may have multiple corrupted rows.

It strikes me that it'd be worth defining a function that could extract
the toast OID of any toasted datum, along the lines of

function pg_get_toast_id(anyelement) returns oid

When faced with such a problem, you could do

select ctid from my_giant_table
where pg_get_toast_id(a_toastable_column) = 205026
or pg_get_toast_id(another_toastable_column) = 205026
...;

This would involve a seqscan since there'd be no way to index it,
but at least it'd be only one seqscan rather than repeated trials.

I'd envision making the thing return NULL if given a varlena value
that happened not to be toasted out-of-line. If given a non-varlena
data type, it could either return NULL or raise an error, depending
on whether you think that represents pilot error or not.

Comments? Anyone else ever wished they had this?

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Victor Y. Yegorov 2005-06-07 21:50:28 Re: adding new pages bulky way
Previous Message Alvaro Herrera 2005-06-07 21:35:14 Re: adding new pages bulky way