/* * Start the log streaming */ static void StreamLog(void) { PGresult *res; uint32 timeline; XLogRecPtr startpos; int minServerMajor, maxServerMajor; int serverMajor; /* * Connect in replication mode to the server */ conn = GetConnection(); if (!conn) /* Error message already written in GetConnection() */ 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 * position. */ 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 fields\n"), progname, PQntuples(res), PQnfields(res), 1, 3); disconnect_and_exit(1); } timeline = atoi(PQgetvalue(res, 0, 1)); if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &startpos.xlogid, &startpos.xrecoff) != 2) { fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"), progname, PQgetvalue(res, 0, 2)); disconnect_and_exit(1); } PQclear(res); /* * Figure out where to start streaming. */ startpos = FindStreamingStart(startpos, timeline); /* * Always start streaming at the beginning of a segment */ startpos.xrecoff -= startpos.xrecoff % XLOG_SEG_SIZE; /* * Start the replication */ if (verbose) fprintf(stderr, _("%s: starting log streaming at %X/%X (timeline %u)\n"), progname, startpos.xlogid, startpos.xrecoff, timeline); ReceiveXlogStream(conn, startpos, timeline, NULL, basedir, stop_streaming, standby_message_timeout, false); PQfinish(conn); }
/* * Start the log streaming */ static void StreamLog(void) { PGresult *res; uint32 timeline; XLogRecPtr startpos; /* * Connect in replication mode to the server */ conn = GetConnection(); if (!conn) /* Error message already written in GetConnection() */ return; /* * Run IDENTIFY_SYSTEM so we can get the timeline and current xlog * position. */ res = PQexec(conn, "IDENTIFY_SYSTEM"); if (PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr, _("%s: could not identify system: %s\n"), progname, 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\n"), progname, PQntuples(res), PQnfields(res)); disconnect_and_exit(1); } timeline = atoi(PQgetvalue(res, 0, 1)); if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &startpos.xlogid, &startpos.xrecoff) != 2) { fprintf(stderr, _("%s: could not parse log start position from value \"%s\"\n"), progname, PQgetvalue(res, 0, 2)); disconnect_and_exit(1); } PQclear(res); /* * Figure out where to start streaming. */ startpos = FindStreamingStart(startpos, timeline); /* * Always start streaming at the beginning of a segment */ startpos.xrecoff -= startpos.xrecoff % XLOG_SEG_SIZE; /* * Start the replication */ if (verbose) fprintf(stderr, _("%s: starting log streaming at %X/%X (timeline %u)\n"), progname, startpos.xlogid, startpos.xrecoff, timeline); ReceiveXlogStream(conn, startpos, timeline, NULL, basedir, stop_streaming, standby_message_timeout, false); PQfinish(conn); }