diff options
author | Andres Freund | 2014-10-01 15:22:21 +0000 |
---|---|---|
committer | Andres Freund | 2014-10-01 15:35:56 +0000 |
commit | 0c013e08cfbebd35ec982c4df15d44b521094d52 (patch) | |
tree | 448ef218b547b1eb65a55bd2b2760b39ef7014d5 /src/bin/pg_basebackup/pg_receivexlog.c | |
parent | fdf81c9a6cf94921084e52c8d2ff903bae362620 (diff) |
Refactor replication connection code of various pg_basebackup utilities.
Move some more code to manage replication connection command to
streamutil.c. A later patch will introduce replication slot via
pg_receivexlog and this avoid duplicating relevant code between
pg_receivexlog and pg_recvlogical.
Author: Michael Paquier, with some editing by me.
Diffstat (limited to 'src/bin/pg_basebackup/pg_receivexlog.c')
-rw-r--r-- | src/bin/pg_basebackup/pg_receivexlog.c | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index a8b9ad3c05f..171cf431f57 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -253,13 +253,8 @@ FindStreamingStart(uint32 *tli) static void StreamLog(void) { - PGresult *res; - XLogRecPtr startpos; - uint32 starttli; - XLogRecPtr serverpos; - uint32 servertli; - uint32 hi, - lo; + XLogRecPtr startpos, serverpos; + TimeLineID starttli, servertli; /* * Connect in replication mode to the server @@ -280,33 +275,12 @@ StreamLog(void) } /* - * Run IDENTIFY_SYSTEM so we can get the timeline and current xlog - * position. + * Identify server, obtaining start LSN position and current timeline ID + * at the same time, necessary if not valid data can be found in the + * existing output directory. */ - res = PQexec(conn, "IDENTIFY_SYSTEM"); - if (PQresultStatus(res) != PGRES_TUPLES_OK) - { - fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), - progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn)); - disconnect_and_exit(1); - } - if (PQntuples(res) != 1 || PQnfields(res) < 3) - { - fprintf(stderr, - _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"), - progname, PQntuples(res), PQnfields(res), 1, 3); + if (!RunIdentifySystem(conn, NULL, &servertli, &serverpos, NULL)) disconnect_and_exit(1); - } - servertli = atoi(PQgetvalue(res, 0, 1)); - if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2) - { - fprintf(stderr, - _("%s: could not parse transaction log location \"%s\"\n"), - progname, PQgetvalue(res, 0, 2)); - disconnect_and_exit(1); - } - serverpos = ((uint64) hi) << 32 | lo; - PQclear(res); /* * Figure out where to start streaming. |