mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 11:11:19 +02:00
Refactor one use of IDENTIFY_SYSTEM in WAL streaming code of pg_basebackup
0c013e0
has done a large refactoring to unify all the code paths using
replication commands, but forgot one code path doing WAL streaming that
checks the validity of a cluster connecting to with IDENTIFY_SYSTEM.
There is a generic routine able to handle that, so make use of it in
this code path. This impacts pg_receivewal and pg_basebackup.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACVKKYUMC8GE72Y7BP9g1batrrq3sEwUh+1_i2krWZC_2Q@mail.gmail.com
This commit is contained in:
parent
961dd75657
commit
99709c9b90
@ -482,36 +482,32 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
|
|||||||
|
|
||||||
if (stream->sysidentifier != NULL)
|
if (stream->sysidentifier != NULL)
|
||||||
{
|
{
|
||||||
/* Validate system identifier hasn't changed */
|
char *sysidentifier = NULL;
|
||||||
res = PQexec(conn, "IDENTIFY_SYSTEM");
|
TimeLineID servertli;
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
|
||||||
|
/*
|
||||||
|
* Get the server system identifier and timeline, and validate them.
|
||||||
|
*/
|
||||||
|
if (!RunIdentifySystem(conn, &sysidentifier, &servertli, NULL, NULL))
|
||||||
{
|
{
|
||||||
pg_log_error("could not send replication command \"%s\": %s",
|
pg_free(sysidentifier);
|
||||||
"IDENTIFY_SYSTEM", PQerrorMessage(conn));
|
|
||||||
PQclear(res);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (PQntuples(res) != 1 || PQnfields(res) < 3)
|
|
||||||
{
|
if (strcmp(stream->sysidentifier, sysidentifier) != 0)
|
||||||
pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
|
|
||||||
PQntuples(res), PQnfields(res), 1, 3);
|
|
||||||
PQclear(res);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strcmp(stream->sysidentifier, PQgetvalue(res, 0, 0)) != 0)
|
|
||||||
{
|
{
|
||||||
pg_log_error("system identifier does not match between base backup and streaming connection");
|
pg_log_error("system identifier does not match between base backup and streaming connection");
|
||||||
PQclear(res);
|
pg_free(sysidentifier);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (stream->timeline > atoi(PQgetvalue(res, 0, 1)))
|
pg_free(sysidentifier);
|
||||||
|
|
||||||
|
if (stream->timeline > servertli)
|
||||||
{
|
{
|
||||||
pg_log_error("starting timeline %u is not present in the server",
|
pg_log_error("starting timeline %u is not present in the server",
|
||||||
stream->timeline);
|
stream->timeline);
|
||||||
PQclear(res);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PQclear(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user