Incorrect CONTEXT reported for errors during REPACK CONCURRENTLY

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: vignesh C <vignesh21(at)gmail(dot)com>, Zhijie Hou <houzhijie22(at)gmail(dot)com>, "ah(at)cybertec(dot)at" <ah(at)cybertec(dot)at>
Subject: Incorrect CONTEXT reported for errors during REPACK CONCURRENTLY
Date: 2026-11-17 08:52:44
Message-ID: OS7PR01MB1831779706CC16A63AC2A4782F57B2@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
(CC: who were in the original thread and the original author of REPACK CONCURRENTLY)

This is a fork thread from [1]. Here I want to discuss the mixture logging during
the REPACK CONCURRENTLY. Let me describe from the beginning to make
the issue clearer.

Background & Found issue
========
When a repack worker raises an ERROR, the corresponding backend process would
re-throw the same error in ProcessRepackMessage(). This mostly works well, but
the backend outputs the unrelated error messages when it also pushes an error
context to the error stack.

001_repack_error_context reproduced the issue. A functional index is defined with
the injection point. While the backend waits at the point the repack worker does
the error out (also by the injection point). In this case the backend re-throws
the propagated from the repack worker, so the unrelated context can be printed.
Below is the obtained result, lines after the "SQL statement..." is not
propagated from the repack worker.

```
ERROR: error triggered for injection point repack-worker-error-context
CONTEXT: REPACK decoding worker
SQL statement "SELECT public.injection_points_run('repack-leader-error-context')"
PL/pgSQL function public.repack_error_context(integer) line 3 at PERFORM
```

Existing codes
=========
IIUC, two features, parallel query and parallel apply, had the similar issue,
and they handled it with the different way. REPACK can follow either of them.

Regarding the parallel query, it preserves an error context before starting the
parallel query and restores it before re-throwing the error. This means error
contexts pushed during the REPACK do not include in the message.

As for the parallel apply, the leader worker does not re-throw the error in the
first place. When the leader detects the error message from parallel apply workers,
it raises the different error message and exit. This was fixed recently, see 952bab8.

Proposal
======
Since both parallel query and REPACK is handled by normal backend processes,
I think we should follow the parallel query's manner.
DecodingWorker now stores an error context when REPACK CONCURRENTLY starts, and
it's restored and used when the backend detects messages from the repack worker.

[1]: https://www.postgresql.org/message-id/OS7PR01MB1831790F7F8DF277B2558DF92F5932%40OS7PR01MB18317.jpnprd01.prod.outlook.com

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Browse pgsql-hackers by date

  From Date Subject
Next Message Koshino Taiki 2026-11-17 08:58:51 Re: Proposal: Include CHECK constraint expression in violation error DETAIL
Previous Message Bertrand Drouvot 2026-11-17 08:45:52 Re: Assertion failure in update_local_synced_slot(), slotsync.c:364