mirror of
https://github.com/postgres/postgres.git
synced 2025-08-05 07:41:25 +03:00
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.
This commit is contained in:
@@ -947,6 +947,9 @@ BaseBackup(void)
|
|||||||
int i;
|
int i;
|
||||||
char xlogstart[64];
|
char xlogstart[64];
|
||||||
char xlogend[64];
|
char xlogend[64];
|
||||||
|
int minServerMajor,
|
||||||
|
maxServerMajor;
|
||||||
|
int serverMajor;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Connect in replication mode to the server
|
* Connect in replication mode to the server
|
||||||
@@ -956,6 +959,21 @@ BaseBackup(void)
|
|||||||
/* Error message already written in GetConnection() */
|
/* Error message already written in GetConnection() */
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check server version. BASE_BACKUP command was introduced in 9.1, so
|
||||||
|
* we can't work with servers older than 9.1. And we don't support servers
|
||||||
|
* newer than the client.
|
||||||
|
*/
|
||||||
|
minServerMajor = 901;
|
||||||
|
maxServerMajor = PG_VERSION_NUM / 100;
|
||||||
|
serverMajor = PQserverVersion(conn) / 100;
|
||||||
|
if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: unsupported server version %s\n"),
|
||||||
|
progname, PQparameterStatus(conn, "server_version"));
|
||||||
|
disconnect_and_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run IDENTIFY_SYSTEM so we can get the timeline
|
* Run IDENTIFY_SYSTEM so we can get the timeline
|
||||||
*/
|
*/
|
||||||
|
@@ -220,6 +220,9 @@ StreamLog(void)
|
|||||||
PGresult *res;
|
PGresult *res;
|
||||||
uint32 timeline;
|
uint32 timeline;
|
||||||
XLogRecPtr startpos;
|
XLogRecPtr startpos;
|
||||||
|
int minServerMajor,
|
||||||
|
maxServerMajor;
|
||||||
|
int serverMajor;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Connect in replication mode to the server
|
* Connect in replication mode to the server
|
||||||
@@ -229,6 +232,21 @@ StreamLog(void)
|
|||||||
/* Error message already written in GetConnection() */
|
/* Error message already written in GetConnection() */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check server version. IDENTIFY_SYSTEM didn't return the current xlog
|
||||||
|
* position before 9.1, so we can't work with servers older than 9.1. And
|
||||||
|
* we don't support servers newer than the client.
|
||||||
|
*/
|
||||||
|
minServerMajor = 901;
|
||||||
|
maxServerMajor = PG_VERSION_NUM / 100;
|
||||||
|
serverMajor = PQserverVersion(conn) / 100;
|
||||||
|
if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: unsupported server version %s\n"),
|
||||||
|
progname, PQparameterStatus(conn, "server_version"));
|
||||||
|
disconnect_and_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run IDENTIFY_SYSTEM so we can get the timeline and current xlog
|
* Run IDENTIFY_SYSTEM so we can get the timeline and current xlog
|
||||||
* position.
|
* position.
|
||||||
|
Reference in New Issue
Block a user