@@ -901,6 +901,7 @@ static void validateRecoveryParameters(void);
901
901
static void exitArchiveRecovery (TimeLineID endTLI , XLogRecPtr endOfLog );
902
902
static bool recoveryStopsBefore (XLogReaderState * record );
903
903
static bool recoveryStopsAfter (XLogReaderState * record );
904
+ static char * getRecoveryStopReason (void );
904
905
static void ConfirmRecoveryPaused (void );
905
906
static void recoveryPausesHere (bool endOfRecovery );
906
907
static bool recoveryApplyDelay (XLogReaderState * record );
@@ -6059,6 +6060,42 @@ recoveryStopsAfter(XLogReaderState *record)
6059
6060
return false;
6060
6061
}
6061
6062
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
+
6062
6099
/*
6063
6100
* Wait until shared recoveryPauseState is set to RECOVERY_NOT_PAUSED.
6064
6101
*
@@ -7756,7 +7793,7 @@ StartupXLOG(void)
7756
7793
PrevTimeLineID = ThisTimeLineID ;
7757
7794
if (ArchiveRecoveryRequested )
7758
7795
{
7759
- char reason [ 200 ] ;
7796
+ char * reason ;
7760
7797
char recoveryPath [MAXPGPATH ];
7761
7798
7762
7799
Assert (InArchiveRecovery );
@@ -7765,33 +7802,7 @@ StartupXLOG(void)
7765
7802
ereport (LOG ,
7766
7803
(errmsg ("selected new timeline ID: %u" , ThisTimeLineID )));
7767
7804
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 ();
7795
7806
7796
7807
/*
7797
7808
* We are now done reading the old WAL. Turn off archive fetching if
0 commit comments