RE: Lock timeouts and unusual spikes in replication lag with logical parallel transaction streaming
Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
From: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
To: 'Zane Duffield' <duffieldzane@gmail.com>
Cc: "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>, Amit
Kapila <amit.kapila16@gmail.com>, "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>
Date: 2025-08-20T09:58:59Z
Lists: pgsql-bugs
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix LOCK_TIMEOUT handling during parallel apply.
- e41d954da6aa 19 (unreleased) landed
- 37fc5de438b4 18.1 landed
- 2f6e1a49066f 17.7 landed
- a54c7a1133a4 16.11 landed
Attachments
- v1-PG16-PG17-0001-Make-parallel-apply-worker-accept-lock-timeo.patch (application/octet-stream) patch v1-0001
- v1-PG18-master-0001-Make-parallel-apply-worker-accept-lock-timeout.patch (application/octet-stream) patch v1-0001
Dear Zane, While analyzing your post and code, I found that parallel apply worker could not accept the lock timeout. IIUC that's why lock timeout rarely reported and parallel apply worker exits automatically. Lock timeout is implemented by sending a SIGINT to the process. Backends set a signal hander to StatementCancelHandler, which the process will error out while waiting something. See CHECK_FOR_INTERRUPTS->ProcessInterrupts. The error message would be: "canceling statement due to lock timeout". Regarding the parallel apply worker, however, it overwrites the signal hander for SIGINT; it is used to detect the shutdown request from the leader process. When parallel apply worker receives, it will exit when it reaches the main loop. Apart from above case, the process does not exit while waiting the lock, it does after becoming idle or receives next chunks. The message is same as normal shutdown case. IIUC, lock timeout should be enabled for all the processes which accesses and modifies database objects, hence current state should be fixed. My idea is to use different signal to request shutdown to parallel apply workers. Since checkpointer and walsender use SIGUSR2 for the similar purpose, this patch also uses it for parallel apply worker. This issue has existed since PG16. Note that this does not actually solve the issue what initially reported; this allows pa worker to report and exit the lock timeout. The replication lag cannot be resolved only by this. Per document [1], it is not recommended to set lock_timeout globally. [1]: https://www.postgresql.org/docs/17/runtime-config-client.html#GUC-LOCK-TIMEOUT Best regards, Hayato Kuroda FUJITSU LIMITED