diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_rewind/libpq_fetch.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/bin/pg_rewind/libpq_fetch.c b/src/bin/pg_rewind/libpq_fetch.c index 8d969057747..99e587f7476 100644 --- a/src/bin/pg_rewind/libpq_fetch.c +++ b/src/bin/pg_rewind/libpq_fetch.c @@ -45,6 +45,7 @@ static PGconn *conn = NULL; static void receiveFileChunks(const char *sql); static void execute_pagemap(datapagemap_t *pagemap, const char *path); static char *run_simple_query(const char *sql); +static void run_simple_command(const char *sql); void libpqConnect(const char *connstr) @@ -59,6 +60,10 @@ libpqConnect(const char *connstr) pg_log(PG_PROGRESS, "connected to server\n"); + /* disable all types of timeouts */ + run_simple_command("SET statement_timeout = 0"); + run_simple_command("SET lock_timeout = 0"); + res = PQexec(conn, ALWAYS_SECURE_SEARCH_PATH_SQL); if (PQresultStatus(res) != PGRES_TUPLES_OK) pg_fatal("could not clear search_path: %s", @@ -93,11 +98,7 @@ libpqConnect(const char *connstr) * replication, and replication isn't working for some reason, we don't * want to get stuck, waiting for it to start working again. */ - res = PQexec(conn, "SET synchronous_commit = off"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) - pg_fatal("could not set up connection context: %s", - PQresultErrorMessage(res)); - PQclear(res); + run_simple_command("SET synchronous_commit = off"); } /* @@ -128,6 +129,24 @@ run_simple_query(const char *sql) } /* + * Runs a command. + * In the event of a failure, exit immediately. + */ +static void +run_simple_command(const char *sql) +{ + PGresult *res; + + res = PQexec(conn, sql); + + if (PQresultStatus(res) != PGRES_COMMAND_OK) + pg_fatal("error running query (%s) in source server: %s", + sql, PQresultErrorMessage(res)); + + PQclear(res); +} + +/* * Calls pg_current_xlog_insert_location() function */ XLogRecPtr @@ -461,12 +480,7 @@ libpq_executeFileMap(filemap_t *map) * need to fetch. */ sql = "CREATE TEMPORARY TABLE fetchchunks(path text, begin int8, len int4);"; - res = PQexec(conn, sql); - - if (PQresultStatus(res) != PGRES_COMMAND_OK) - pg_fatal("could not create temporary table: %s", - PQresultErrorMessage(res)); - PQclear(res); + run_simple_command(sql); sql = "COPY fetchchunks FROM STDIN"; res = PQexec(conn, sql); |