diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2013-03-22 13:02:59 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2013-03-25 19:44:11 +0200 |
commit | d298b50a3b469c088bb40a4d36d38111b4cd574d (patch) | |
tree | bbb327e9d755e00abf0b74478a58e3f8667624b6 /src/bin/pg_basebackup/receivelog.c | |
parent | ea988ee8c8b191615e730f930bcde6144a598688 (diff) | |
download | postgresql-d298b50a3b469c088bb40a4d36d38111b4cd574d.tar.gz postgresql-d298b50a3b469c088bb40a4d36d38111b4cd574d.zip |
Make pg_basebackup work with pre-9.3 servers, and add server version check.
A new 'starttli' field was added to the response of BASE_BACKUP command.
Make pg_basebackup tolerate the case that it's missing, so that it still
works with older servers.
Add an explicit check for the server version, so that you get a nicer error
message if you try to use it with a pre-9.1 server.
The streaming protocol message format changed in 9.3, so -X stream still won't
work with pre-9.3 servers. I added a version check to ReceiveXLogStream()
earlier, but write that slightly differently, so that in 9.4, it will still
work with a 9.3 server. (In 9.4, the error message needs to be adjusted to
"9.3 or above", though). Also, if the version check fails, don't retry.
Diffstat (limited to 'src/bin/pg_basebackup/receivelog.c')
-rw-r--r-- | src/bin/pg_basebackup/receivelog.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index 1f7611f4440..2bf4df961ea 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -437,6 +437,40 @@ sendFeedback(PGconn *conn, XLogRecPtr blockpos, int64 now, bool replyRequested) } /* + * Check that the server version we're connected to is supported by + * ReceiveXlogStream(). + * + * If it's not, an error message is printed to stderr, and false is returned. + */ +bool +CheckServerVersionForStreaming(PGconn *conn) +{ + int minServerMajor, + maxServerMajor; + int serverMajor; + + /* + * The message format used in streaming replication changed in 9.3, so we + * cannot stream from older servers. And we don't support servers newer + * than the client; it might work, but we don't know, so err on the safe + * side. + */ + minServerMajor = 903; + 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; streaming is only supported with server version %s\n"), + progname, + serverver ? serverver : "'unknown'", + "9.3"); + return false; + } + return true; +} + +/* * Receive a log stream starting at the specified position. * * If sysidentifier is specified, validate that both the system @@ -476,19 +510,11 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, XLogRecPtr stoppos; /* - * The message format used in streaming replication changed in 9.3, so we - * cannot stream from older servers. Don't know if we would work with - * newer versions, but let's not take the risk. + * The caller should've checked the server version already, but doesn't do + * any harm to check it here too. */ - if (PQserverVersion(conn) / 100 != PG_VERSION_NUM / 100) - { - const char *serverver = PQparameterStatus(conn, "server_version"); - fprintf(stderr, _("%s: incompatible server version %s; streaming is only supported with server version %s\n"), - progname, - serverver ? serverver : "'unknown'", - PG_MAJORVERSION); + if (!CheckServerVersionForStreaming(conn)) return false; - } if (sysidentifier != NULL) { |