|
|
|
@ -52,10 +52,10 @@ libpqConnect(const char *connstr) |
|
|
|
|
|
|
|
|
|
conn = PQconnectdb(connstr); |
|
|
|
|
if (PQstatus(conn) == CONNECTION_BAD) |
|
|
|
|
pg_fatal("could not connect to remote server: %s\n", |
|
|
|
|
pg_fatal("could not connect to server: %s", |
|
|
|
|
PQerrorMessage(conn)); |
|
|
|
|
|
|
|
|
|
pg_log(PG_PROGRESS, "connected to remote server\n"); |
|
|
|
|
pg_log(PG_PROGRESS, "connected to server\n"); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check that the server is not in hot standby mode. There is no |
|
|
|
@ -91,12 +91,12 @@ run_simple_query(const char *sql) |
|
|
|
|
res = PQexec(conn, sql); |
|
|
|
|
|
|
|
|
|
if (PQresultStatus(res) != PGRES_TUPLES_OK) |
|
|
|
|
pg_fatal("error running query (%s) in source server: %s\n", |
|
|
|
|
pg_fatal("error running query (%s) in source server: %s", |
|
|
|
|
sql, PQresultErrorMessage(res)); |
|
|
|
|
|
|
|
|
|
/* sanity check the result set */ |
|
|
|
|
if (PQnfields(res) != 1 || PQntuples(res) != 1 || PQgetisnull(res, 0, 0)) |
|
|
|
|
pg_fatal("unexpected result set while running query\n"); |
|
|
|
|
pg_fatal("unexpected result set from query\n"); |
|
|
|
|
|
|
|
|
|
result = pg_strdup(PQgetvalue(res, 0, 0)); |
|
|
|
|
|
|
|
|
@ -119,7 +119,7 @@ libpqGetCurrentXlogInsertLocation(void) |
|
|
|
|
val = run_simple_query("SELECT pg_current_xlog_insert_location()"); |
|
|
|
|
|
|
|
|
|
if (sscanf(val, "%X/%X", &hi, &lo) != 2) |
|
|
|
|
pg_fatal("unexpected result \"%s\" while fetching current XLOG insert location\n", val); |
|
|
|
|
pg_fatal("unrecognized result \"%s\" for current XLOG insert location\n", val); |
|
|
|
|
|
|
|
|
|
result = ((uint64) hi) << 32 | lo; |
|
|
|
|
|
|
|
|
@ -167,7 +167,7 @@ libpqProcessFileList(void) |
|
|
|
|
res = PQexec(conn, sql); |
|
|
|
|
|
|
|
|
|
if (PQresultStatus(res) != PGRES_TUPLES_OK) |
|
|
|
|
pg_fatal("unexpected result while fetching file list: %s\n", |
|
|
|
|
pg_fatal("could not fetch file list: %s", |
|
|
|
|
PQresultErrorMessage(res)); |
|
|
|
|
|
|
|
|
|
/* sanity check the result set */ |
|
|
|
@ -210,7 +210,7 @@ receiveFileChunks(const char *sql) |
|
|
|
|
PGresult *res; |
|
|
|
|
|
|
|
|
|
if (PQsendQueryParams(conn, sql, 0, NULL, NULL, NULL, NULL, 1) != 1) |
|
|
|
|
pg_fatal("could not send query: %s\n", PQerrorMessage(conn)); |
|
|
|
|
pg_fatal("could not send query: %s", PQerrorMessage(conn)); |
|
|
|
|
|
|
|
|
|
pg_log(PG_DEBUG, "getting file chunks"); |
|
|
|
|
|
|
|
|
@ -262,7 +262,7 @@ receiveFileChunks(const char *sql) |
|
|
|
|
PQgetisnull(res, 0, 1) || |
|
|
|
|
PQgetisnull(res, 0, 2)) |
|
|
|
|
{ |
|
|
|
|
pg_fatal("unexpected NULL result while fetching remote files\n"); |
|
|
|
|
pg_fatal("unexpected null values in result while fetching remote files\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (PQgetlength(res, 0, 1) != sizeof(int32)) |
|
|
|
@ -280,7 +280,7 @@ receiveFileChunks(const char *sql) |
|
|
|
|
|
|
|
|
|
chunk = PQgetvalue(res, 0, 2); |
|
|
|
|
|
|
|
|
|
pg_log(PG_DEBUG, "received chunk for file \"%s\", off %d, len %d\n", |
|
|
|
|
pg_log(PG_DEBUG, "received chunk for file \"%s\", offset %d, size %d\n", |
|
|
|
|
filename, chunkoff, chunksize); |
|
|
|
|
|
|
|
|
|
open_target_file(filename, false); |
|
|
|
@ -309,7 +309,7 @@ libpqGetFile(const char *filename, size_t *filesize) |
|
|
|
|
1, NULL, paramValues, NULL, NULL, 1); |
|
|
|
|
|
|
|
|
|
if (PQresultStatus(res) != PGRES_TUPLES_OK) |
|
|
|
|
pg_fatal("unexpected result while fetching remote file \"%s\": %s\n", |
|
|
|
|
pg_fatal("could not fetch remote file \"%s\": %s", |
|
|
|
|
filename, PQresultErrorMessage(res)); |
|
|
|
|
|
|
|
|
|
/* sanity check the result set */ |
|
|
|
@ -355,7 +355,7 @@ fetch_file_range(const char *path, unsigned int begin, unsigned int end) |
|
|
|
|
snprintf(linebuf, sizeof(linebuf), "%s\t%u\t%u\n", path, begin, len); |
|
|
|
|
|
|
|
|
|
if (PQputCopyData(conn, linebuf, strlen(linebuf)) != 1) |
|
|
|
|
pg_fatal("error sending COPY data: %s\n", |
|
|
|
|
pg_fatal("could not send COPY data: %s", |
|
|
|
|
PQerrorMessage(conn)); |
|
|
|
|
|
|
|
|
|
begin += len; |
|
|
|
@ -381,14 +381,14 @@ libpq_executeFileMap(filemap_t *map) |
|
|
|
|
res = PQexec(conn, sql); |
|
|
|
|
|
|
|
|
|
if (PQresultStatus(res) != PGRES_COMMAND_OK) |
|
|
|
|
pg_fatal("error creating temporary table: %s\n", |
|
|
|
|
pg_fatal("could not create temporary table: %s", |
|
|
|
|
PQresultErrorMessage(res)); |
|
|
|
|
|
|
|
|
|
sql = "COPY fetchchunks FROM STDIN"; |
|
|
|
|
res = PQexec(conn, sql); |
|
|
|
|
|
|
|
|
|
if (PQresultStatus(res) != PGRES_COPY_IN) |
|
|
|
|
pg_fatal("unexpected result while sending file list: %s\n", |
|
|
|
|
pg_fatal("could not send file list: %s", |
|
|
|
|
PQresultErrorMessage(res)); |
|
|
|
|
|
|
|
|
|
for (i = 0; i < map->narray; i++) |
|
|
|
@ -429,13 +429,13 @@ libpq_executeFileMap(filemap_t *map) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (PQputCopyEnd(conn, NULL) != 1) |
|
|
|
|
pg_fatal("error sending end-of-COPY: %s\n", |
|
|
|
|
pg_fatal("could not send end-of-COPY: %s", |
|
|
|
|
PQerrorMessage(conn)); |
|
|
|
|
|
|
|
|
|
while ((res = PQgetResult(conn)) != NULL) |
|
|
|
|
{ |
|
|
|
|
if (PQresultStatus(res) != PGRES_COMMAND_OK) |
|
|
|
|
pg_fatal("unexpected result while sending file list: %s\n", |
|
|
|
|
pg_fatal("unexpected result while sending file list: %s", |
|
|
|
|
PQresultErrorMessage(res)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|