Skip to content

Commit aa5d7d5

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 f1bd8a8 commit aa5d7d5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,33 @@ BaseBackup(void)
816816
int i;
817817
char xlogstart[64];
818818
char xlogend[64];
819+
int minServerMajor,
820+
maxServerMajor;
821+
int serverMajor;
819822

820823
/*
821824
* Connect in replication mode to the server
822825
*/
823826
conn = GetConnection();
824827

828+
/*
829+
* Check server version. BASE_BACKUP command was introduced in 9.1, so
830+
* we can't work with servers older than 9.1. We don't officially support
831+
* servers newer than the client, but the 9.1 version happens to work with
832+
* a 9.2 server. This version check was added to 9.1 branch in a minor
833+
* release, so allow connecting to a 9.2 server, to avoid breaking
834+
* environments that worked before this version check was added.
835+
*/
836+
minServerMajor = 901;
837+
maxServerMajor = 902;
838+
serverMajor = PQserverVersion(conn) / 100;
839+
if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
840+
{
841+
fprintf(stderr, _("%s: unsupported server version %s\n"),
842+
progname, PQparameterStatus(conn, "server_version"));
843+
disconnect_and_exit(1);
844+
}
845+
825846
/*
826847
* Start the actual backup
827848
*/

0 commit comments

Comments
 (0)