Thread: Problem with large tuples.

Problem with large tuples.

From
Patrik Kudo
Date:
I've noticed that some of my tables with large text tuples have
problem when these exceed some certain size. I know about the
8k tuplesize limit, but it seems the problem appears earlier
than that. This is what I've been able to recreate:

CREATE TABLE sizetest (id int, txt text);
INSERT INTO sizetest (id, txt) VALUES (1, '...'); // ... = string of
4000 chars
vacuum analyze; // <-- works nicely
INSERT INTO sizetest (id, txt) VALUES (2, '...'); // ... = string of
4100 chars
vacuum analyze;
ERROR:  Tuple is too big: size 8152, max size 8140

How come the insert works while the vacuum fails?

Setup: Postgres 6.5.2, FreeBSD 3.3

/Patrik Kudo


Re: [SQL] Problem with large tuples.

From
Dirk Lutzebaeck
Date:
Patrik Kudo writes:> I've noticed that some of my tables with large text tuples have> problem when these exceed some
certainsize. I know about the> 8k tuplesize limit, but it seems the problem appears earlier> than that. This is what
I'vebeen able to recreate:> > CREATE TABLE sizetest (id int, txt text);> INSERT INTO sizetest (id, txt) VALUES (1,
'...');// ... = string of> 4000 chars> vacuum analyze; // <-- works nicely> INSERT INTO sizetest (id, txt) VALUES (2,
'...');// ... = string of> 4100 chars> vacuum analyze;> ERROR:  Tuple is too big: size 8152, max size 8140> > How come
theinsert works while the vacuum fails?
 

It's a bug. You need this patch against 6.5.3:

*** src/backend/commands/vacuum.c.orig    Wed Aug 25 08:01:45 1999
--- src/backend/commands/vacuum.c    Tue Jan  4 12:15:17 2000
***************
*** 2405,2414 ****                     stup = heap_formtuple(sd->rd_att, values, nulls);                      /*
----------------
!                      *    insert the tuple in the relation and get the tuple's oid.                      *
----------------                     */
 
!                     heap_insert(sd, stup);                     pfree(DatumGetPointer(values[3]));
pfree(DatumGetPointer(values[4]));                    pfree(stup);
 
--- 2405,2425 ----                     stup = heap_formtuple(sd->rd_att, values, nulls);                      /*
----------------
!                      *    Watch out for oversize tuple, which can happen if
!                      *    both of the saved data values are long.
!                      *    Our fallback strategy is just to not store the
!                      *    pg_statistic tuple at all in that case.  (We could
!                      *    replace the values by NULLs and still store the
!                      *    numeric stats, but presently selfuncs.c couldn't
!                      *    do anything useful with that case anyway.)                      * ----------------
           */
 
!                     if (MAXALIGN(stup->t_len) <= MaxTupleSize)
!                     {
!                         /* OK to store tuple */
!                         heap_insert(sd, stup);
!                     }
!                      pfree(DatumGetPointer(values[3]));                     pfree(DatumGetPointer(values[4]));
            pfree(stup);
 

After patching you should remove your statistics with
'DELETE FROM pg_statistic'; 

You might also need to patch vio.c. Get it from the latest snapshot...

Go back in the pgsql-bugs archive to read more about this problem. It
was discussed some weeks ago...

Dirk




Re: [SQL] Problem with large tuples.

From
Palle Girgensohn
Date:
Dirk Lutzebaeck wrote:
> 
...
> You might also need to patch vio.c. Get it from the latest snapshot...

vio.c?  Can't find it the 6.5.3 sources. I guess that means I don't need to patch it, right? ;)

/Palle


Re: [SQL] Problem with large tuples.

From
Tom Lane
Date:
Palle Girgensohn <girgen@partitur.se> writes:
> Dirk Lutzebaeck wrote:
>> You might also need to patch vio.c. Get it from the latest snapshot...

> vio.c?  Can't find it the 6.5.3 sources. I guess that means I don't need to patch it, right? ;)

I think he meant src/backend/access/heap/hio.c; there's a patch in there
that defends against adding an oversize tuple to a relation, IIRC.
        regards, tom lane


Re: [SQL] Problem with large tuples.

From
Palle Girgensohn
Date:
Tom Lane wrote:
> 
> I think he meant src/backend/access/heap/hio.c; there's a patch in there
> that defends against adding an oversize tuple to a relation, IIRC.

Thanks. I applied the patch.

/Palle