@@ -901,6 +901,7 @@ static void validateRecoveryParameters(void);
901901static void exitArchiveRecovery (TimeLineID endTLI , XLogRecPtr endOfLog );
902902static bool recoveryStopsBefore (XLogReaderState * record );
903903static bool recoveryStopsAfter (XLogReaderState * record );
904+ static char * getRecoveryStopReason (void );
904905static void ConfirmRecoveryPaused (void );
905906static void recoveryPausesHere (bool endOfRecovery );
906907static bool recoveryApplyDelay (XLogReaderState * record );
@@ -6059,6 +6060,42 @@ recoveryStopsAfter(XLogReaderState *record)
60596060 return false;
60606061}
60616062
6063+ /*
6064+ * Create a comment for the history file to explain why and where
6065+ * timeline changed.
6066+ */
6067+ static char *
6068+ getRecoveryStopReason (void )
6069+ {
6070+ char reason [200 ];
6071+
6072+ if (recoveryTarget == RECOVERY_TARGET_XID )
6073+ snprintf (reason , sizeof (reason ),
6074+ "%s transaction %u" ,
6075+ recoveryStopAfter ? "after" : "before" ,
6076+ recoveryStopXid );
6077+ else if (recoveryTarget == RECOVERY_TARGET_TIME )
6078+ snprintf (reason , sizeof (reason ),
6079+ "%s %s\n" ,
6080+ recoveryStopAfter ? "after" : "before" ,
6081+ timestamptz_to_str (recoveryStopTime ));
6082+ else if (recoveryTarget == RECOVERY_TARGET_LSN )
6083+ snprintf (reason , sizeof (reason ),
6084+ "%s LSN %X/%X\n" ,
6085+ recoveryStopAfter ? "after" : "before" ,
6086+ LSN_FORMAT_ARGS (recoveryStopLSN ));
6087+ else if (recoveryTarget == RECOVERY_TARGET_NAME )
6088+ snprintf (reason , sizeof (reason ),
6089+ "at restore point \"%s\"" ,
6090+ recoveryStopName );
6091+ else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE )
6092+ snprintf (reason , sizeof (reason ), "reached consistency" );
6093+ else
6094+ snprintf (reason , sizeof (reason ), "no recovery target specified" );
6095+
6096+ return pstrdup (reason );
6097+ }
6098+
60626099/*
60636100 * Wait until shared recoveryPauseState is set to RECOVERY_NOT_PAUSED.
60646101 *
@@ -7756,7 +7793,7 @@ StartupXLOG(void)
77567793 PrevTimeLineID = ThisTimeLineID ;
77577794 if (ArchiveRecoveryRequested )
77587795 {
7759- char reason [ 200 ] ;
7796+ char * reason ;
77607797 char recoveryPath [MAXPGPATH ];
77617798
77627799 Assert (InArchiveRecovery );
@@ -7765,33 +7802,7 @@ StartupXLOG(void)
77657802 ereport (LOG ,
77667803 (errmsg ("selected new timeline ID: %u" , ThisTimeLineID )));
77677804
7768- /*
7769- * Create a comment for the history file to explain why and where
7770- * timeline changed.
7771- */
7772- if (recoveryTarget == RECOVERY_TARGET_XID )
7773- snprintf (reason , sizeof (reason ),
7774- "%s transaction %u" ,
7775- recoveryStopAfter ? "after" : "before" ,
7776- recoveryStopXid );
7777- else if (recoveryTarget == RECOVERY_TARGET_TIME )
7778- snprintf (reason , sizeof (reason ),
7779- "%s %s\n" ,
7780- recoveryStopAfter ? "after" : "before" ,
7781- timestamptz_to_str (recoveryStopTime ));
7782- else if (recoveryTarget == RECOVERY_TARGET_LSN )
7783- snprintf (reason , sizeof (reason ),
7784- "%s LSN %X/%X\n" ,
7785- recoveryStopAfter ? "after" : "before" ,
7786- LSN_FORMAT_ARGS (recoveryStopLSN ));
7787- else if (recoveryTarget == RECOVERY_TARGET_NAME )
7788- snprintf (reason , sizeof (reason ),
7789- "at restore point \"%s\"" ,
7790- recoveryStopName );
7791- else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE )
7792- snprintf (reason , sizeof (reason ), "reached consistency" );
7793- else
7794- snprintf (reason , sizeof (reason ), "no recovery target specified" );
7805+ reason = getRecoveryStopReason ();
77957806
77967807 /*
77977808 * We are now done reading the old WAL. Turn off archive fetching if
0 commit comments