ERROR: missing chunk number 0 for toast value

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Subject: ERROR: missing chunk number 0 for toast value
Date: 2014-01-02 12:24:07
Message-ID: CAGPqQf2bG_u8reY3ehL5pcWzw+4C6c7Kn0OsfHnOvHs3hDsihw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

Test case:

drop table if exists t;
create table t(c text);
insert into t values ('x'), (repeat(md5('abcdefghijklmnop'), 10000));
select pg_column_size(c), pg_column_size(c || '') FROM t;

CREATE OR REPLACE FUNCTION copy_toast_out() RETURNS VOID AS $$
declare
v text;
BEGIN
SELECT c INTO v FROM t WHERE c <> 'x';
Select 1/0;
Exception
When Others Then
PERFORM pg_sleep(30); -- go run "TRUNCATE t" in a 2nd session

raise notice 'length :%', length(v || ''); -- force detoast

END;
$$ language plpgsql;

postgres=# select copy_toast_out();
ERROR: missing chunk number 0 for toast value 16390 in pg_toast_16384
CONTEXT: PL/pgSQL function copy_toast_out() line 10 at RAISE

Analysis:

The basic problem here is that if the lock is released on table before
extracting toasted value, and in meantime someone truncates the table,
this error can occur. Here error coming with PL block contains an Exception
block (as incase there is an exception block, it calls
RollbackAndReleaseCurrentSubTransaction).

Do you think we should detoast the local variable before
RollbackAndReleaseCurrentSubTransaction ? Or any other options ?

Regards,
Rushabh Lathia
www.EnterpriseDB.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2014-01-02 12:35:11 Re: preserving forensic information when we freeze
Previous Message Magnus Hagander 2014-01-02 12:23:29 Re: Fixing pg_basebackup with tablespaces found in $PGDATA