Avoid ERROR in recovery target GUC assign hooks

Recovery target parameters are postmaster-startup GUCs, but their
assign hooks previously did more than assign individual parameter
values. They also updated the global recoveryTarget state and raised
ERROR if more than one recovery target appeared to be set.

This was not a good fit for GUC assign hooks. Assign hooks should not
throw ERROR, and deriving cross-parameter state while individual GUCs
are still being assigned makes the result depend on assignment order
rather than the final configuration.

For example, setting one recovery target and then setting another
recovery_target_* parameter to an empty string could clear
recoveryTarget, causing recovery to proceed with no target even
though a valid target remained configured.

Fix this by having the assign hooks only store their own parameter
values. The effective recoveryTarget is now derived once from the
final recovery_target* settings in
validateRecoveryParameters(), which also rejects configurations that
specify more than one recovery target with FATAL. This preserves the
expected behavior for repeated assignments of the same GUC, treats empty
values as "not set", and removes cross-GUC validation from the assign
hooks.

Author: JoongHyuk Shin <[email protected]>
Reviewed-by: Greg Lamberson <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Scott Ray <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Reviewed-by: Henson Choi <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: 
https://postgr.es/m/cacsdjfpua4uvkjadgoerxoxnymcg2mqqiqkkijk6mx6e4qg...@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/access/transam/xlogrecovery.c   | 140 ++++++++++------------------
src/backend/utils/misc/guc_parameters.dat   |   5 +-
src/backend/utils/misc/guc_tables.c         |   1 -
src/include/access/xlogrecovery.h           |   2 +-
src/include/utils/guc_hooks.h               |   3 -
src/test/recovery/t/003_recovery_targets.pl | 123 ++++++++++++++++++------
6 files changed, 145 insertions(+), 129 deletions(-)

Reply via email to