From 55a56845eddb0f3b7cb947d1971c41b86638d452 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 13 Jun 2008 02:59:47 +0000 Subject: [PATCH] Improve the various elog messages in tuptoaster.c to report which TOAST table the problem happened in. These are all supposedly can't-happen cases, but when they do happen it's useful to know where. Back-patch to 8.3, but not further because the patch doesn't apply cleanly further back. Given the lack of response to my proposal of this, there doesn't seem to be enough interest to justify much back-porting effort. --- src/backend/access/heap/tuptoaster.c | 62 +++++++++++++++++----------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index 7478f90cd8..b7923e4083 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.87 2008/04/17 21:37:28 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.88 2008/06/13 02:59:47 tgl Exp $ * * * INTERFACE ROUTINES @@ -1216,8 +1216,6 @@ toast_save_datum(Relation rel, Datum value, SET_VARSIZE(&chunk_data, chunk_size + VARHDRSZ); memcpy(VARDATA(&chunk_data), data_p, chunk_size); toasttup = heap_form_tuple(toasttupDesc, t_values, t_isnull); - if (!HeapTupleIsValid(toasttup)) - elog(ERROR, "failed to build TOAST tuple"); heap_insert(toastrel, toasttup, mycid, use_wal, use_fsm); @@ -1412,7 +1410,9 @@ toast_fetch_datum(struct varlena * attr) else { /* should never happen */ - elog(ERROR, "found toasted toast chunk"); + elog(ERROR, "found toasted toast chunk for toast value %u in %s", + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); chunksize = 0; /* keep compiler quiet */ chunkdata = NULL; } @@ -1421,31 +1421,35 @@ toast_fetch_datum(struct varlena * attr) * Some checks on the data we've found */ if (residx != nextidx) - elog(ERROR, "unexpected chunk number %d (expected %d) for toast value %u", + elog(ERROR, "unexpected chunk number %d (expected %d) for toast value %u in %s", residx, nextidx, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); if (residx < numchunks - 1) { if (chunksize != TOAST_MAX_CHUNK_SIZE) - elog(ERROR, "unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u", + elog(ERROR, "unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s", chunksize, (int) TOAST_MAX_CHUNK_SIZE, residx, numchunks, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); } else if (residx == numchunks - 1) { if ((residx * TOAST_MAX_CHUNK_SIZE + chunksize) != ressize) - elog(ERROR, "unexpected chunk size %d (expected %d) in final chunk %d for toast value %u", + elog(ERROR, "unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s", chunksize, (int) (ressize - residx * TOAST_MAX_CHUNK_SIZE), residx, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); } else - elog(ERROR, "unexpected chunk number %d for toast value %u (out of range %d..%d)", + elog(ERROR, "unexpected chunk number %d (out of range %d..%d) for toast value %u in %s", residx, + 0, numchunks - 1, toast_pointer.va_valueid, - 0, numchunks - 1); + RelationGetRelationName(toastrel)); /* * Copy the data into proper place in our result @@ -1461,9 +1465,10 @@ toast_fetch_datum(struct varlena * attr) * Final checks that we successfully fetched the datum */ if (nextidx != numchunks) - elog(ERROR, "missing chunk number %d for toast value %u", + elog(ERROR, "missing chunk number %d for toast value %u in %s", nextidx, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); /* * End scan and close relations @@ -1621,7 +1626,9 @@ toast_fetch_datum_slice(struct varlena * attr, int32 sliceoffset, int32 length) else { /* should never happen */ - elog(ERROR, "found toasted toast chunk"); + elog(ERROR, "found toasted toast chunk for toast value %u in %s", + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); chunksize = 0; /* keep compiler quiet */ chunkdata = NULL; } @@ -1630,31 +1637,35 @@ toast_fetch_datum_slice(struct varlena * attr, int32 sliceoffset, int32 length) * Some checks on the data we've found */ if ((residx != nextidx) || (residx > endchunk) || (residx < startchunk)) - elog(ERROR, "unexpected chunk number %d (expected %d) for toast value %u", + elog(ERROR, "unexpected chunk number %d (expected %d) for toast value %u in %s", residx, nextidx, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); if (residx < totalchunks - 1) { if (chunksize != TOAST_MAX_CHUNK_SIZE) - elog(ERROR, "unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u when fetching slice", + elog(ERROR, "unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s when fetching slice", chunksize, (int) TOAST_MAX_CHUNK_SIZE, residx, totalchunks, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); } else if (residx == totalchunks - 1) { if ((residx * TOAST_MAX_CHUNK_SIZE + chunksize) != attrsize) - elog(ERROR, "unexpected chunk size %d (expected %d) in final chunk %d for toast value %u when fetching slice", + elog(ERROR, "unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s when fetching slice", chunksize, (int) (attrsize - residx * TOAST_MAX_CHUNK_SIZE), residx, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); } else - elog(ERROR, "unexpected chunk number %d for toast value %u (out of range %d..%d)", + elog(ERROR, "unexpected chunk number %d (out of range %d..%d) for toast value %u in %s", residx, + 0, totalchunks - 1, toast_pointer.va_valueid, - 0, totalchunks - 1); + RelationGetRelationName(toastrel)); /* * Copy the data into proper place in our result @@ -1678,9 +1689,10 @@ toast_fetch_datum_slice(struct varlena * attr, int32 sliceoffset, int32 length) * Final checks that we successfully fetched the datum */ if (nextidx != (endchunk + 1)) - elog(ERROR, "missing chunk number %d for toast value %u", + elog(ERROR, "missing chunk number %d for toast value %u in %s", nextidx, - toast_pointer.va_valueid); + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)); /* * End scan and close relations