pg_rewind-statement_timeout-v2.patch
text/x-patch
Filename: pg_rewind-statement_timeout-v2.patch
Type: text/x-patch
Part: 0
Message:
Re: Statement timeout in pg_rewind
Patch
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| src/bin/pg_rewind/libpq_fetch.c | 27 | 11 |
diff --git a/src/bin/pg_rewind/libpq_fetch.c b/src/bin/pg_rewind/libpq_fetch.c
index 37eccc3126..e2dbc9fdf6 100644
--- a/src/bin/pg_rewind/libpq_fetch.c
+++ b/src/bin/pg_rewind/libpq_fetch.c
@@ -39,6 +39,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)
@@ -54,6 +55,11 @@ libpqConnect(const char *connstr)
if (showprogress)
pg_log_info("connected to server");
+ /* We don't want our queries canceled */
+ run_simple_command("SET statement_timeout = 0");
+ run_simple_command("SET lock_timeout = 0");
+ run_simple_command("SET idle_in_transaction_session_timeout = 0");
+
res = PQexec(conn, ALWAYS_SECURE_SEARCH_PATH_SQL);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
pg_fatal("could not clear search_path: %s",
@@ -88,11 +94,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");
}
/*
@@ -122,6 +124,25 @@ run_simple_query(const char *sql)
return result;
}
+/*
+ * Runs a command.
+ * In case of failure pg_fatal exits with code=1.
+ */
+static void
+run_simple_command(const char *sql)
+{
+ PGresult *res;
+ char *result;
+
+ res = PQexec(conn, sql);
+
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ pg_fatal("error running command (%s) in source server: %s",
+ sql, PQresultErrorMessage(res));
+
+ PQclear(res);
+}
+
/*
* Calls pg_current_wal_insert_lsn() function
*/
@@ -427,12 +448,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);