Skip to content

Commit 6980497

Browse files
committed
Add a server version check to pg_basebackup and pg_receivexlog.
These programs don't work against 9.0 or earlier servers, so check that when the connection is made. That's better than a cryptic error message you got before. Also, these programs won't work with a 9.3 server, because the WAL streaming protocol was changed in a non-backwards-compatible way. As a general rule, we don't make any guarantee that an old client will work with a new server, so check that. However, allow a 9.1 client to connect to a 9.2 server, to avoid breaking environments that currently work; a 9.1 client happens to work with a 9.2 server, even though we didn't make any great effort to ensure that. This patch is for the 9.1 and 9.2 branches, I'll commit a similar patch to master later. Although this isn't a critical bug fix, it seems safe enough to back-patch. The error message you got when connecting to a 9.3devel server without this patch was cryptic enough to warrant backpatching.
1 parent 3a003c5 commit 6980497

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,9 @@ BaseBackup(void)
947947
int i;
948948
char xlogstart[64];
949949
char xlogend[64];
950+
int minServerMajor,
951+
maxServerMajor;
952+
int serverMajor;
950953

951954
/*
952955
* Connect in replication mode to the server
@@ -956,6 +959,21 @@ BaseBackup(void)
956959
/* Error message already written in GetConnection() */
957960
exit(1);
958961

962+
/*
963+
* Check server version. BASE_BACKUP command was introduced in 9.1, so
964+
* we can't work with servers older than 9.1. And we don't support servers
965+
* newer than the client.
966+
*/
967+
minServerMajor = 901;
968+
maxServerMajor = PG_VERSION_NUM / 100;
969+
serverMajor = PQserverVersion(conn) / 100;
970+
if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
971+
{
972+
fprintf(stderr, _("%s: unsupported server version %s\n"),
973+
progname, PQparameterStatus(conn, "server_version"));
974+
disconnect_and_exit(1);
975+
}
976+
959977
/*
960978
* Run IDENTIFY_SYSTEM so we can get the timeline
961979
*/

src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ StreamLog(void)
220220
PGresult *res;
221221
uint32 timeline;
222222
XLogRecPtr startpos;
223+
int minServerMajor,
224+
maxServerMajor;
225+
int serverMajor;
223226

224227
/*
225228
* Connect in replication mode to the server
@@ -229,6 +232,21 @@ StreamLog(void)
229232
/* Error message already written in GetConnection() */
230233
return;
231234

235+
/*
236+
* Check server version. IDENTIFY_SYSTEM didn't return the current xlog
237+
* position before 9.1, so we can't work with servers older than 9.1. And
238+
* we don't support servers newer than the client.
239+
*/
240+
minServerMajor = 901;
241+
maxServerMajor = PG_VERSION_NUM / 100;
242+
serverMajor = PQserverVersion(conn) / 100;
243+
if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
244+
{
245+
fprintf(stderr, _("%s: unsupported server version %s\n"),
246+
progname, PQparameterStatus(conn, "server_version"));
247+
disconnect_and_exit(1);
248+
}
249+
232250
/*
233251
* Run IDENTIFY_SYSTEM so we can get the timeline and current xlog
234252
* position.

0 commit comments

Comments
 (0)