From 549383ae33266c586549e8c6789b51c8cfc93b2a Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Tue, 15 Apr 2025 15:22:37 +0000 Subject: [PATCH] Print toast message only for matching toast chunks When dumping toasted values in verbose mode, show "Read TOAST chunk" message only for toast chunks that matched the Oid we are looking for. --- decode.c | 6 +++--- decode.h | 1 + pg_filedump.c | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/decode.c b/decode.c index 465dd69..69d0d40 100644 --- a/decode.c +++ b/decode.c @@ -1514,6 +1514,7 @@ void ToastChunkDecode(const char *tuple_data, unsigned int tuple_size, Oid toast_oid, + Oid *read_toast_oid, uint32 *chunk_id, char *chunk_data, unsigned int *chunk_data_size) @@ -1522,14 +1523,13 @@ ToastChunkDecode(const char *tuple_data, const char *data = tuple_data + header->t_hoff; unsigned int size = tuple_size - header->t_hoff; unsigned int processed_size = 0; - Oid read_toast_oid; int ret; *chunk_data_size = 0; *chunk_id = 0; /* decode toast_id */ - ret = DecodeOidBinary(data, size, &processed_size, &read_toast_oid); + ret = DecodeOidBinary(data, size, &processed_size, read_toast_oid); if (ret < 0) { printf("Error: unable to decode a TOAST tuple toast_id, " @@ -1548,7 +1548,7 @@ ToastChunkDecode(const char *tuple_data, } /* It is not what we are looking for */ - if (toast_oid != read_toast_oid) + if (toast_oid != *read_toast_oid) return; /* decode chunk_id */ diff --git a/decode.h b/decode.h index 24ba2e6..f05f85a 100644 --- a/decode.h +++ b/decode.h @@ -19,6 +19,7 @@ void ToastChunkDecode(const char* tuple_data, unsigned int tuple_size, Oid toast_oid, + Oid *read_toast_oid, uint32 *chunk_id, char *chunk_data, unsigned int *chunk_data_size); diff --git a/pg_filedump.c b/pg_filedump.c index b82c2c0..5b4ec5b 100644 --- a/pg_filedump.c +++ b/pg_filedump.c @@ -1554,11 +1554,13 @@ FormatItemBlock(char *buffer, } else if (isToast) { + Oid read_toast_oid; + ToastChunkDecode(&buffer[itemOffset], itemSize, toastOid, - &chunkId, toastValue + *toastRead, + &read_toast_oid, &chunkId, toastValue + *toastRead, &chunkSize); - if (!isToast || verbose) + if (verbose && read_toast_oid == toastOid) printf("%s Read TOAST chunk. TOAST Oid: %d, chunk id: %d, " "chunk data size: %d\n", indent, toastOid, chunkId, chunkSize); -- 2.39.5