From 813c057eba1046fa5de18c24828d0b92b8632bf9 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Thu, 5 Nov 2026 15:17:43 +0900 Subject: [PATCH v8] Fix the error context of the leader apply worker when a parallel apply worker fails. When a parallel apply worker fails, it reports the error, with the context of the transaction that failed, to the server log and to the leader apply worker. The leader apply worker then exits with an error of its own. It built that error by copying the context of the worker into it, adding a "logical replication parallel apply worker" line, and leaving the rest of the context to whatever error context callbacks were active when the message was processed. The result was misleading, as the context of the failed transaction was logged a second time, now attached to an error reported by a different process, next to the context of whatever the leader was applying, so the log read as if both belonged to the same transaction. Report only that the parallel apply worker exited due to an error, and leave the details of the worker. --- .../replication/logical/applyparallelworker.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index 96bf499e49c..151a7297813 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -1028,23 +1028,6 @@ ProcessParallelApplyMessage(StringInfo msg) { case PqMsg_ErrorResponse: { - ErrorData edata; - - /* Parse ErrorResponse. */ - pq_parse_errornotice(msg, &edata); - - /* - * If desired, add a context line to show that this is a - * message propagated from a parallel apply worker. Otherwise, - * it can sometimes be confusing to understand what actually - * happened. - */ - if (edata.context) - edata.context = psprintf("%s\n%s", edata.context, - _("logical replication parallel apply worker")); - else - edata.context = pstrdup(_("logical replication parallel apply worker")); - /* * Context beyond that should use the error context callbacks * that were in effect in LogicalRepApplyLoop(). @@ -1052,13 +1035,12 @@ ProcessParallelApplyMessage(StringInfo msg) error_context_stack = apply_error_context_stack; /* - * The actual error must have been reported by the parallel - * apply worker. + * The parallel apply worker did error-out, the leader apply + * worker must exit as well. */ ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("logical replication parallel apply worker exited due to error"), - errcontext("%s", edata.context))); + errmsg("logical replication parallel apply worker exited due to error, exiting leader as well"))); } /* -- 2.55.0