v23-0003-Add-version-check-for-standby-server.patch
application/octet-stream
Filename: v23-0003-Add-version-check-for-standby-server.patch
Type: application/octet-stream
Part: 4
Message:
Re: speed up a logical replica setup
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v23-0003
Subject: Add version check for standby server
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pg_createsubscriber.sgml | 6 | 0 |
| src/bin/pg_basebackup/pg_createsubscriber.c | 28 | 0 |
From 84bb55feeceb82e3354488dd088b88ccae6d5b89 Mon Sep 17 00:00:00 2001
From: Shlok Kyal <shlok.kyal.oss@gmail.com>
Date: Wed, 14 Feb 2024 16:27:15 +0530
Subject: [PATCH v23 03/13] Add version check for standby server
Add version check for standby server
---
doc/src/sgml/ref/pg_createsubscriber.sgml | 6 +++++
src/bin/pg_basebackup/pg_createsubscriber.c | 28 +++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/doc/src/sgml/ref/pg_createsubscriber.sgml b/doc/src/sgml/ref/pg_createsubscriber.sgml
index 7cdd047d67..9d0c6c764c 100644
--- a/doc/src/sgml/ref/pg_createsubscriber.sgml
+++ b/doc/src/sgml/ref/pg_createsubscriber.sgml
@@ -125,6 +125,12 @@ PostgreSQL documentation
databases and walsenders.
</para>
</listitem>
+ <listitem>
+ <para>
+ Both the target and source instances must have same major versions with
+ <application>pg_createsubscriber</application>.
+ </para>
+ </listitem>
</itemizedlist>
<note>
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 205a835d36..b15769c75b 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -23,6 +23,7 @@
#include "common/file_perm.h"
#include "common/logging.h"
#include "common/restricted_token.h"
+#include "common/string.h"
#include "fe_utils/recovery_gen.h"
#include "fe_utils/simple_list.h"
#include "getopt_long.h"
@@ -294,6 +295,8 @@ check_data_directory(const char *datadir)
{
struct stat statbuf;
char versionfile[MAXPGPATH];
+ FILE *ver_fd;
+ char rawline[64];
pg_log_info("checking if directory \"%s\" is a cluster data directory",
datadir);
@@ -317,6 +320,31 @@ check_data_directory(const char *datadir)
return false;
}
+ /* Check standby server version */
+ if ((ver_fd = fopen(versionfile, "r")) == NULL)
+ pg_fatal("could not open file \"%s\" for reading: %m", versionfile);
+
+ /* Version number has to be the first line read */
+ if (!fgets(rawline, sizeof(rawline), ver_fd))
+ {
+ if (!ferror(ver_fd))
+ pg_fatal("unexpected empty file \"%s\"", versionfile);
+ else
+ pg_fatal("could not read file \"%s\": %m", versionfile);
+ }
+
+ /* Strip trailing newline and carriage return */
+ (void) pg_strip_crlf(rawline);
+
+ if (strcmp(rawline, PG_MAJORVERSION) != 0)
+ {
+ pg_log_error("standby server is of wrong version");
+ pg_log_error_detail("File \"%s\" contains \"%s\", which is not compatible with this program's version \"%s\".",
+ versionfile, rawline, PG_MAJORVERSION);
+ exit(1);
+ }
+
+ fclose(ver_fd);
return true;
}
--
2.41.0.windows.3