diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/heap/heapam.c | 8 | ||||
-rw-r--r-- | src/backend/replication/logical/decode.c | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 6861ae0a7f2..35f9404ff41 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -2515,6 +2515,14 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples, info |= XLOG_HEAP_INIT_PAGE; } + /* + * Signal that this is the last xl_heap_multi_insert record + * emitted by this call to heap_multi_insert(). Needed for logical + * decoding so it knows when to cleanup temporary data. + */ + if (ndone + nthispage == ntuples) + xlrec->flags |= XLOG_HEAP_LAST_MULTI_INSERT; + recptr = XLogInsert(RM_HEAP2_ID, info, rdata); PageSetLSN(page, recptr); diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c index 1734ec96599..8f8732afdce 100644 --- a/src/backend/replication/logical/decode.c +++ b/src/backend/replication/logical/decode.c @@ -802,8 +802,16 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf) tuple->header.t_hoff = xlhdr->t_hoff; } - /* reset toast reassembly only after the last chunk */ - change->data.tp.clear_toast_afterwards = (i + 1) == xlrec->ntuples; + /* + * Reset toast reassembly state only after the last row in the last + * xl_multi_insert_tuple record emitted by one heap_multi_insert() + * call. + */ + if (xlrec->flags & XLOG_HEAP_LAST_MULTI_INSERT && + (i + 1) == xlrec->ntuples) + change->data.tp.clear_toast_afterwards = true; + else + change->data.tp.clear_toast_afterwards = false; ReorderBufferQueueChange(ctx->reorder, r->xl_xid, buf->origptr, change); |