Add wal_sender_shutdown_timeout GUC to limit shutdown wait for replication Previously, during shutdown, walsenders always waited until all pending data was replicated to receivers. This ensures sender and receiver stay in sync after shutdown, which is important for physical replication switchovers, but it can significantly delay shutdown. For example, in logical replication, if apply workers are blocked on locks, walsenders may wait until those locks are released, preventing shutdown from completing for a long time.
This commit introduces a new GUC, wal_sender_shutdown_timeout, which specifies the maximum time a walsender waits during shutdown for all pending data to be replicated. When set, shutdown completes once all data is replicated or the timeout expires. A value of -1 (the default) disables the timeout. This can reduce shutdown time when replication is slow or stalled. However, if the timeout is reached, the sender and receiver may be left out of sync, which can be problematic for physical replication switchovers. Author: Andrey Silitskiy <[email protected]> Author: Hayato Kuroda <[email protected]> Reviewed-by: Ashutosh Bapat <[email protected]> Reviewed-by: Kyotaro Horiguchi <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Reviewed-by: Dilip Kumar <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Reviewed-by: Andres Freund <[email protected]> Reviewed-by: Takamichi Osumi <[email protected]> Reviewed-by: Peter Smith <[email protected]> Reviewed-by: Greg Sabino Mullane <[email protected]> Reviewed-by: Alexander Korotkov <[email protected]> Reviewed-by: Vitaly Davydov <[email protected]> Reviewed-by: Ronan Dunklau <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Reviewed-by: Japin Li <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/tyapr01mb586668e50fc2447ad7f92491f5...@tyapr01mb5866.jpnprd01.prod.outlook.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/a8f45dee91768cf1447ffaf2527e499e75a194c3 Modified Files -------------- doc/src/sgml/config.sgml | 42 +++++ doc/src/sgml/high-availability.sgml | 10 +- src/backend/replication/walsender.c | 135 +++++++++++++- src/backend/utils/misc/guc_parameters.dat | 10 + src/backend/utils/misc/postgresql.conf.sample | 1 + src/include/replication/walsender.h | 1 + src/test/subscription/meson.build | 1 + .../subscription/t/038_walsnd_shutdown_timeout.pl | 201 +++++++++++++++++++++ 8 files changed, 395 insertions(+), 6 deletions(-)
