Hello

My fault. I thought pg_basebackup works only with same major version, sorry.
How about attached patch?

regards, Sergei
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 3d2d4cd0b9..e1aa2c1cfc 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -66,6 +66,11 @@ typedef struct TablespaceList
  */
 #define MINIMUM_VERSION_FOR_TEMP_SLOTS 100000
 
+/*
+ * recovery.conf has been moved into GUC system in version 12
+ */
+#define MINIMUM_VERSION_FOR_RECOVERY_GUC 120000
+
 /*
  * Different ways to include WAL
  */
@@ -974,6 +979,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 	bool		basetablespace = PQgetisnull(res, rownum, 0);
 	bool		in_tarhdr = true;
 	bool		skip_file = false;
+	bool		is_recovery_guc_supported = true;
 	bool		is_postgresql_auto_conf = false;
 	bool		found_postgresql_auto_conf = false;
 	int			file_padding_len = 0;
@@ -984,6 +990,9 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 	gzFile		ztarfile = NULL;
 #endif
 
+	if (PQserverVersion(conn) < MINIMUM_VERSION_FOR_RECOVERY_GUC)
+		is_recovery_guc_supported = false;
+
 	if (basetablespace)
 	{
 		/*
@@ -1130,11 +1139,15 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 			{
 				char		header[512];
 
-				if (!found_postgresql_auto_conf)
+				/*
+				 * we need write new postgresql.auto.conf if missing or
+				 * recovery.conf for old systems
+				 */
+				if (!found_postgresql_auto_conf || !is_recovery_guc_supported)
 				{
 					int			padding;
 
-					tarCreateHeader(header, "postgresql.auto.conf", NULL,
+					tarCreateHeader(header, is_recovery_guc_supported ? "postgresql.auto.conf" : "recovery.conf", NULL,
 									recoveryconfcontents->len,
 									pg_file_create_mode, 04000, 02000,
 									time(NULL));
@@ -1147,13 +1160,16 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 						WRITE_TAR_DATA(zerobuf, padding);
 				}
 
-				tarCreateHeader(header, "standby.signal", NULL,
-								0,	/* zero-length file */
-								pg_file_create_mode, 04000, 02000,
-								time(NULL));
+				if (is_recovery_guc_supported)
+				{
+					tarCreateHeader(header, "standby.signal", NULL,
+									0,	/* zero-length file */
+									pg_file_create_mode, 04000, 02000,
+									time(NULL));
 
-				WRITE_TAR_DATA(header, sizeof(header));
-				WRITE_TAR_DATA(zerobuf, 511);
+					WRITE_TAR_DATA(header, sizeof(header));
+					WRITE_TAR_DATA(zerobuf, 511);
+				}
 			}
 
 			/* 2 * 512 bytes empty data at end of file */
@@ -1253,15 +1269,25 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 						 * look at the file metadata: we may want append
 						 * recovery info into postgresql.auto.conf and skip
 						 * standby.signal file.  In both cases we must
-						 * calculate tar padding
+						 * calculate tar padding. Also we need skip
+						 * recovery.conf file for old cluster versions
 						 */
-						skip_file = (strcmp(&tarhdr[0], "standby.signal") == 0);
-						is_postgresql_auto_conf = (strcmp(&tarhdr[0], "postgresql.auto.conf") == 0);
+						if (is_recovery_guc_supported)
+						{
+							skip_file = (strcmp(&tarhdr[0], "standby.signal") == 0);
+							is_postgresql_auto_conf = (strcmp(&tarhdr[0], "postgresql.auto.conf") == 0);
+						}
+						else
+						{
+							skip_file = (strcmp(&tarhdr[0], "recovery.conf") == 0);
+						}
 
 						filesz = read_tar_number(&tarhdr[124], 12);
 						file_padding_len = ((filesz + 511) & ~511) - filesz;
 
-						if (is_postgresql_auto_conf && writerecoveryconf)
+						if (is_recovery_guc_supported &&
+							is_postgresql_auto_conf &&
+							writerecoveryconf)
 						{
 							/* replace tar header */
 							char		header[512];
@@ -1313,7 +1339,9 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 						pos += bytes2write;
 						filesz -= bytes2write;
 					}
-					else if (is_postgresql_auto_conf && writerecoveryconf)
+					else if (is_recovery_guc_supported &&
+							 is_postgresql_auto_conf &&
+							 writerecoveryconf)
 					{
 						/* append recovery config to postgresql.auto.conf */
 						int			padding;
@@ -1690,6 +1718,9 @@ GenerateRecoveryConf(PGconn *conn)
 		exit(1);
 	}
 
+	if (PQserverVersion(conn) < MINIMUM_VERSION_FOR_RECOVERY_GUC)
+		appendPQExpBufferStr(recoveryconfcontents, "standby_mode = 'on'\n");
+
 	connOptions = PQconninfo(conn);
 	if (connOptions == NULL)
 	{
@@ -1765,9 +1796,11 @@ WriteRecoveryConf(void)
 	char		filename[MAXPGPATH];
 	FILE	   *cf;
 
-	snprintf(filename, MAXPGPATH, "%s/%s", basedir, "postgresql.auto.conf");
+	snprintf(filename, MAXPGPATH, "%s/%s", basedir,
+			 PQserverVersion(conn) < MINIMUM_VERSION_FOR_RECOVERY_GUC ?
+			 "recovery.conf" : "postgresql.auto.conf");
 
-	cf = fopen(filename, "a");
+	cf = fopen(filename, PQserverVersion(conn) < MINIMUM_VERSION_FOR_RECOVERY_GUC ? "w" : "a");
 	if (cf == NULL)
 	{
 		fprintf(stderr, _("%s: could not open file \"%s\": %s\n"), progname, filename, strerror(errno));
@@ -1784,15 +1817,18 @@ WriteRecoveryConf(void)
 
 	fclose(cf);
 
-	snprintf(filename, MAXPGPATH, "%s/%s", basedir, "standby.signal");
-	cf = fopen(filename, "w");
-	if (cf == NULL)
+	if (PQserverVersion(conn) >= MINIMUM_VERSION_FOR_RECOVERY_GUC)
 	{
-		fprintf(stderr, _("%s: could not create file \"%s\": %s\n"), progname, filename, strerror(errno));
-		exit(1);
-	}
+		snprintf(filename, MAXPGPATH, "%s/%s", basedir, "standby.signal");
+		cf = fopen(filename, "w");
+		if (cf == NULL)
+		{
+			fprintf(stderr, _("%s: could not create file \"%s\": %s\n"), progname, filename, strerror(errno));
+			exit(1);
+		}
 
-	fclose(cf);
+		fclose(cf);
+	}
 }
 
 

Reply via email to