From 1147eccc124864fcac2967d162522e5bc75708b3 Mon Sep 17 00:00:00 2001
From: Sergey Fukanchik <s.fukanchik@postgrespro.ru>
Date: Thu, 4 May 2023 14:45:47 +0300
Subject: [PATCH] PGPRO-8081: Use XLOG_RESTORE_POINT for recovery_target_time

It is useful for pg_probackup to recover on restore point.

Tags: pg_probackup
---
 src/backend/access/transam/xlogrecovery.c | 28 +++++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 42d5b59ac25..4676937d5cb 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -2648,7 +2648,8 @@ recoveryStopsAfter(XLogReaderState *record)
 	}
 
 	if (recoveryTarget == RECOVERY_TARGET_TIME &&
-		rmid == RM_XLOG_ID && info == XLOG_BACKUP_END)
+		rmid == RM_XLOG_ID && (info == XLOG_BACKUP_END ||
+							   info == XLOG_RESTORE_POINT))
 	{
 		bool	stopsHere = false;
 
@@ -2670,11 +2671,28 @@ recoveryStopsAfter(XLogReaderState *record)
 			recoveryStopXid = InvalidTransactionId;
 			recoveryStopLSN = InvalidXLogRecPtr;
 			recoveryStopTime = recordXtime;
-			recoveryStopName[0] = '\0';
 
-			ereport(LOG,
-					(errmsg("recovery stopping at backup end at time %s",
-							timestamptz_to_str(recoveryStopTime))));
+			if (info == XLOG_BACKUP_END)
+			{
+				recoveryStopName[0] = '\0';
+
+				ereport(LOG,
+						(errmsg("recovery stopping at backup end at time %s",
+								timestamptz_to_str(recoveryStopTime))));
+			}
+			else if (info == XLOG_RESTORE_POINT)
+			{
+				xl_restore_point *recordRestorePointData;
+
+				recordRestorePointData = (xl_restore_point *) XLogRecGetData(record);
+
+				strlcpy(recoveryStopName, recordRestorePointData->rp_name, MAXFNAMELEN);
+
+				ereport(LOG,
+						(errmsg("recovery stopping at restore point \"%s\", time %s",
+								recoveryStopName,
+								timestamptz_to_str(recoveryStopTime))));
+			}
 			return true;
 		}
 	}
-- 
GitLab

