diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index bc251adfda0..0f981898191 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -1365,6 +1365,11 @@ ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state) dlist_delete(&change->node); dlist_push_tail(&state->old_change, &change->node); + /* + * Update the total bytes processed before releasing the current set of + * changes and restoring the new set of changes. + */ + rb->totalBytes += rb->size; if (ReorderBufferRestoreChanges(rb, entry->txn, &entry->file, &state->entries[off].segno)) { @@ -2361,6 +2366,10 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, specinsert = NULL; } + /* clean up the iterator */ + ReorderBufferIterTXNFinish(rb, iterstate); + iterstate = NULL; + /* * Update total transaction count and total transaction bytes * processed. Ensure to not count the streamed transaction multiple @@ -2371,10 +2380,6 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, rb->totalBytes += rb->size; - /* clean up the iterator */ - ReorderBufferIterTXNFinish(rb, iterstate); - iterstate = NULL; - /* * Done with current changes, send the last message for this set of * changes depending upon streaming mode.