pg_createsubscriber: Improve handling of automated recovery configuration

When repurposing a standby to a logical replica, pg_createsubscriber
uses for the new replica a set of configuration parameters saved into
postgresql.auto.conf, to force recovery patterns when the physical
replica is promoted.

While not wrong in practice, this approach can cause issues when forcing
again recovery on a logical replica or its base backup as the recovery
parameters are not reset on the target server once pg_createsubscriber
is done with the node.

This commit aims at improving the situation, by changing the way
recovery parameters are saved on the target node.  Instead of writing
all the configuration to postgresql.auto.conf, this file now uses an
include_if_exists, that points to a pg_createsubscriber.conf.  This new
file contains all the recovery configuration, and is renamed to
pg_createsubscriber.conf.disabled when pg_createsubscriber exits.  This
approach resets the recovery parameters, and offers the benefit to keep
a trace of the setup used when the target node got promoted, for
debugging purposes.  If pg_createsubscriber.conf cannot be renamed
(unlikely scenario), a warning is issued to inform users that a manual
intervention may be required to reset this configuration.

This commit includes a test case to demonstrate the problematic case: a
standby node created from a base backup of what was the target node of
pg_createsubscriber does not get confused when started.  If removing
this new logic, the test fails with the standby not able to start due
to an incorrect recovery target setup, where the startup process fails
quickly with a FATAL.

I have provided the design idea for the patch, that Alyona has written
(with some code adjustments from me).  This could be considered as a
bug, but after discussion this is put into the bucket for improvements.
Redesigning pg_createsubscriber would not be acceptable in the stable
branches anyway.

Author: Alyona Vinter <[email protected]>
Reviewed-by: Ilyasov Ian <[email protected]>
Reviewed-by: Alexander Korotkov <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Andrey Rudometov <[email protected]>
Discussion: 
https://postgr.es/m/cagwv16k6l6pzm99i1kixljfwx2bus3dvsr6yv87-yr9qo7x...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/639352d904c8a3d233989253f569cccbea0be123

Modified Files
--------------
doc/src/sgml/ref/pg_createsubscriber.sgml          | 12 +++-
src/bin/pg_basebackup/pg_createsubscriber.c        | 82 +++++++++++++++++++---
src/bin/pg_basebackup/t/040_pg_createsubscriber.pl | 46 ++++++++++++
3 files changed, 127 insertions(+), 13 deletions(-)

Reply via email to