pg_recvlogical: send final feedback on SIGINT/SIGTERM shutdown

Previously, when pg_recvlogical exited due to SIGINT or SIGTERM,
it could terminate without sending final feedback for the last decoded
changes it had already written locally. So, if pg_recvlogical was
restarted afterwards, the server-side logical replication slot could
still point behind those changes, causing them to be sent again.

Make pg_recvlogical send final feedback once more during SIGINT/SIGTERM
shutdown, before sending CopyDone. This gives the server one more chance
to advance the slot far enough to avoid resending already-written data,
so users are less likely to see duplicate decoded output after stopping
and restarting pg_recvlogical.

This remains a best-effort improvement rather than a guarantee. Depending
on when the signal arrives, pg_recvlogical can already have written
decoded output that the server cannot yet safely treat as confirmed, so a
later restart can still receive duplicate data.

Author: Fujii Masao <[email protected]>
Reviewed-by: Ayush Tiwari <[email protected]>
Discussion: 
https://postgr.es/m/CAHGQGwE83z9O=x7admssa3e1eup3_ggqhjft5smpdnxzo_w...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b5a8018116c422f39de94f69f0108ff0c9224f0a

Modified Files
--------------
src/bin/pg_basebackup/pg_recvlogical.c        | 23 +++++++++
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 74 +++++++++++++++++++++++++++
2 files changed, 97 insertions(+)

Reply via email to