diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml
index 41e6491f59..45980e4f81 100644
--- a/doc/src/sgml/high-availability.sgml
+++ b/doc/src/sgml/high-availability.sgml
@@ -1939,8 +1939,8 @@ if (!triggered)
You can control whether a log message is produced when the startup process
is waiting longer than deadlock_timeout for recovery
- conflicts. This is controled by the
- parameter.
+ conflicts. This is controlled by the
+ parameter.
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 57f18c79e3..912e9409f4 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -296,7 +296,8 @@ ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist,
if (!VirtualTransactionIdIsValid(*waitlist))
return;
- if (report_waiting)
+ /* Set the wait start timestamp for reporting */
+ if (report_waiting && (logged_recovery_conflict || update_process_title))
waitStart = GetCurrentTimestamp();
new_status = NULL; /* we haven't changed the ps display */
@@ -308,38 +309,43 @@ ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist,
/* wait until the virtual xid is gone */
while (!VirtualXactLock(*waitlist, false))
{
- TimestampTz ts = 0;
-
- if (report_waiting && (!logged_recovery_conflict || new_status == NULL))
- ts = GetCurrentTimestamp();
-
- /*
- * Log the recovery conflict. To prevent to log the same report
- * multiple times, we log the recovery conflict only once.
- */
- if (log_recovery_conflict_waits &&
- TimestampDifferenceExceeds(waitStart, ts, DeadlockTimeout))
+ if (waitStart > 0)
{
- LogRecoveryConflict(reason, waitStart, waitlist);
- logged_recovery_conflict = true;
- }
+ TimestampTz cur_ts = 0;
+ bool maybe_log_conflict =
+ (log_recovery_conflict_waits && !logged_recovery_conflict);
+ bool maybe_update_pstitle =
+ (update_process_title && new_status == NULL);
+
+ /* Get the current timestamp if not report yet */
+ if (maybe_log_conflict || maybe_update_pstitle)
+ cur_ts = GetCurrentTimestamp();
+
+ /* Log the recovery conflict if necessary */
+ if (maybe_log_conflict &&
+ TimestampDifferenceExceeds(waitStart, cur_ts, DeadlockTimeout))
+ {
+ LogRecoveryConflict(reason, waitStart, waitlist);
+ logged_recovery_conflict = true;
+ }
- /*
- * Report via ps if we have been waiting for more than 500 msec
- * (should that be configurable?)
- */
- if (update_process_title && new_status == NULL && report_waiting &&
- TimestampDifferenceExceeds(waitStart, ts, 500))
- {
- const char *old_status;
- int len;
-
- old_status = get_ps_display(&len);
- new_status = (char *) palloc(len + 8 + 1);
- memcpy(new_status, old_status, len);
- strcpy(new_status + len, " waiting");
- set_ps_display(new_status);
- new_status[len] = '\0'; /* truncate off " waiting" */
+ /*
+ * Report via ps if we have been waiting for more than 500 msec
+ * (should that be configurable?)
+ */
+ if (maybe_update_pstitle &&
+ TimestampDifferenceExceeds(waitStart, cur_ts, 500))
+ {
+ const char *old_status;
+ int len;
+
+ old_status = get_ps_display(&len);
+ new_status = (char *) palloc(len + 8 + 1);
+ memcpy(new_status, old_status, len);
+ strcpy(new_status + len, " waiting");
+ set_ps_display(new_status);
+ new_status[len] = '\0'; /* truncate off " waiting" */
+ }
}
/* Is it time to kill it? */
@@ -522,8 +528,8 @@ ResolveRecoveryConflictWithLock(LOCKTAG locktag)
/*
* Prevent ResolveRecoveryConflictWithVirtualXIDs() from reporting
* "waiting" in PS display and logging recovery conflict by disabling
- * its argument report_waiting because the callers have already reported
- * that.
+ * its argument report_waiting because the callers may have already
+ * reported that.
*/
ResolveRecoveryConflictWithVirtualXIDs(backends,
PROCSIG_RECOVERY_CONFLICT_LOCK,