aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_basebackup/pg_basebackup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_basebackup/pg_basebackup.c')
-rw-r--r--src/bin/pg_basebackup/pg_basebackup.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index eacb5922a2a..45585069a5e 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1223,12 +1223,16 @@ BaseBackup(void)
{
PGresult *res;
char *sysidentifier;
+ uint32 latesttli;
uint32 starttli;
char current_path[MAXPGPATH];
char escaped_label[MAXPGPATH];
int i;
char xlogstart[64];
char xlogend[64];
+ int minServerMajor,
+ maxServerMajor;
+ int serverMajor;
/*
* Connect in replication mode to the server
@@ -1239,6 +1243,31 @@ BaseBackup(void)
exit(1);
/*
+ * Check server version. BASE_BACKUP command was introduced in 9.1, so
+ * we can't work with servers older than 9.1.
+ */
+ minServerMajor = 901;
+ maxServerMajor = PG_VERSION_NUM / 100;
+ serverMajor = PQserverVersion(conn) / 100;
+ if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
+ {
+ const char *serverver = PQparameterStatus(conn, "server_version");
+ fprintf(stderr, _("%s: incompatible server version %s\n"),
+ progname, serverver ? serverver : "'unknown'");
+ disconnect_and_exit(1);
+ }
+
+ /*
+ * If WAL streaming was requested, also check that the server is new
+ * enough for that.
+ */
+ if (streamwal && !CheckServerVersionForStreaming(conn))
+ {
+ /* Error message already written in CheckServerVersionForStreaming() */
+ disconnect_and_exit(1);
+ }
+
+ /*
* Build contents of recovery.conf if requested
*/
if (writerecoveryconf)
@@ -1262,6 +1291,7 @@ BaseBackup(void)
disconnect_and_exit(1);
}
sysidentifier = pg_strdup(PQgetvalue(res, 0, 0));
+ latesttli = atoi(PQgetvalue(res, 0, 1));
PQclear(res);
/*
@@ -1293,7 +1323,7 @@ BaseBackup(void)
progname, PQerrorMessage(conn));
disconnect_and_exit(1);
}
- if (PQntuples(res) != 1 || PQnfields(res) < 2)
+ if (PQntuples(res) != 1)
{
fprintf(stderr,
_("%s: server returned unexpected response to BASE_BACKUP command; got %d rows and %d fields, expected %d rows and %d fields\n"),
@@ -1302,8 +1332,14 @@ BaseBackup(void)
}
strcpy(xlogstart, PQgetvalue(res, 0, 0));
- starttli = atoi(PQgetvalue(res, 0, 1));
-
+ /*
+ * 9.3 and later sends the TLI of the starting point. With older servers,
+ * assume it's the same as the latest timeline reported by IDENTIFY_SYSTEM.
+ */
+ if (PQnfields(res) >= 2)
+ starttli = atoi(PQgetvalue(res, 0, 1));
+ else
+ starttli = latesttli;
PQclear(res);
MemSet(xlogend, 0, sizeof(xlogend));