HotStandbyActive() issue in postgres
Hi hackers,
When we enable hot standby, HotStandbyActive() returns true on hot standby.
Then, we promote the hot standby, the SHM variable `XLogCtl->SharedHotStandbyActive`
remains true. So, HotStandbyActive() still returns true until the next call of
`XLOGShmemInit()` even if the data node was promoted.
`XLogWalRcvSendHSFeedback()` is the only caller of HotStandbyActive,
it's probably not covered by the test cases.
Is it the expected behavior or a bug in postgres? Probably a bug.
I haven't much knowledge of hot-standby, a simple fix might be
to set XLogCtl->SharedHotStandbyActive to false when
the recovery process almost finishes. See the attachment.
Regards,
Hao Wu
Attachments:
fix-hot-standby.diffapplication/octet-stream; name=fix-hot-standby.diffDownload
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index e04250f..35edbab 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -8073,6 +8073,7 @@ StartupXLOG(void)
SpinLockAcquire(&XLogCtl->info_lck);
XLogCtl->SharedRecoveryState = RECOVERY_STATE_DONE;
+ XLogCtl->SharedHotStandbyActive = false;
SpinLockRelease(&XLogCtl->info_lck);
UpdateControlFile();
On 2021/03/12 11:14, Hao Wu wrote:
Hi hackers,
When we enable hot standby,�HotStandbyActive() returns true on hot standby.
Then, we promote the hot standby, the SHM variable `XLogCtl->SharedHotStandbyActive`
remains true. So, HotStandbyActive() still returns true until the next call of
`XLOGShmemInit()` even if the data node was promoted.
`XLogWalRcvSendHSFeedback()` is the only caller of HotStandbyActive,
it's probably not covered by the test cases.Is it the expected behavior or a bug in postgres? Probably a bug.
I haven't much knowledge of hot-standby, a simple fix might be
to set XLogCtl->SharedHotStandbyActive to false when
the recovery process almost finishes. See the attachment.
So if walreceiver is only user of HotStandbyActive(), which means that there is no user of it after recovery finishes because walreceiver exits at the end of recovery? If this understanding is right, ISTM that HotStandbyActive() doesn't need to return false after recovery finishes because there is no user of it. No?
Or you're implementing something that uses HotStandbyActive(), so want it to return false after the recovery?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Yes, I have an extension/UDF that needs to know if the server is currently
running as hot standby. For example, a UDF foo() wants to run on
both the primary and secondary and runs different behaviors for different
roles.
Promoted secondary looks the same as the primary since it's no longer
real hot standby. Does it make sense?
Regards,
Hao Wu
On 2021/03/16 12:24, Hao Wu wrote:
Yes, I have an extension/UDF that needs to know if the server is currently
running as hot standby. For example, a UDF foo() wants to run on
both the primary and secondary and runs different behaviors for different
roles.
Promoted secondary looks the same as the primary since it's no longer
real hot standby. Does it make sense?
If UDF, using RecoveryInProgress() is enough? If RecoveryInProgress() returns
false, UDF can determine that the server is working as a primary. If true is
returned, UDF can determine that the server is working as a secondary and
hot standby is active because you can connect to the server and UDF can be
called. If hot standby is not active during recovery, you cannot conect to
the server and cannot run UDF, so UDF doesn't need to handle the case where
hot standby is not active during recovery. Thought?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION