Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit19bfa15

Browse files
committed
Disable timeouts when running pg_rewind with online source cluster
In this case, the transfer uses a libpq connection, which is subject tothe timeout parameters set at system level, and this can make the rewindoperation suddenly canceled which is not good for automation. Oneworkaround to such issues would be to use PGOPTIONS to enforce thewanted timeout parameters, but that's annoying, and for example pg_dump,which can run potentially long-running queries disables all types oftimeouts.lock_timeout and statement_timeout are the ones which can cause problemsnow. Note that pg_rewind does not use transactions, so disablingidle_in_transaction_session_timeout is optional, but it feels safer todo so for the future.This is back-patched down to 9.5. idle_in_transaction_session_timeoutis only present since 9.6.Author: Alexander KukushkinDiscussion:https://postgr.es/m/CAFh8B=krcVXksxiwVQh1SoY+ziJ-JC=6FcuoBL3yce_40Es5_g@mail.gmail.comBackpatch-through: 9.5
1 parente872432 commit19bfa15

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

‎src/bin/pg_rewind/libpq_fetch.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static PGconn *conn = NULL;
4444
staticvoidreceiveFileChunks(constchar*sql);
4545
staticvoidexecute_pagemap(datapagemap_t*pagemap,constchar*path);
4646
staticchar*run_simple_query(constchar*sql);
47+
staticvoidrun_simple_command(constchar*sql);
4748

4849
void
4950
libpqConnect(constchar*connstr)
@@ -58,6 +59,11 @@ libpqConnect(const char *connstr)
5859

5960
pg_log(PG_PROGRESS,"connected to server\n");
6061

62+
/* disable all types of timeouts */
63+
run_simple_command("SET statement_timeout = 0");
64+
run_simple_command("SET lock_timeout = 0");
65+
run_simple_command("SET idle_in_transaction_session_timeout = 0");
66+
6167
res=PQexec(conn,ALWAYS_SECURE_SEARCH_PATH_SQL);
6268
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
6369
pg_fatal("could not clear search_path: %s",
@@ -92,11 +98,7 @@ libpqConnect(const char *connstr)
9298
* replication, and replication isn't working for some reason, we don't
9399
* want to get stuck, waiting for it to start working again.
94100
*/
95-
res=PQexec(conn,"SET synchronous_commit = off");
96-
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
97-
pg_fatal("could not set up connection context: %s",
98-
PQresultErrorMessage(res));
99-
PQclear(res);
101+
run_simple_command("SET synchronous_commit = off");
100102
}
101103

102104
/*
@@ -126,6 +128,24 @@ run_simple_query(const char *sql)
126128
returnresult;
127129
}
128130

131+
/*
132+
* Runs a command.
133+
* In the event of a failure, exit immediately.
134+
*/
135+
staticvoid
136+
run_simple_command(constchar*sql)
137+
{
138+
PGresult*res;
139+
140+
res=PQexec(conn,sql);
141+
142+
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
143+
pg_fatal("error running query (%s) in source server: %s",
144+
sql,PQresultErrorMessage(res));
145+
146+
PQclear(res);
147+
}
148+
129149
/*
130150
* Calls pg_current_wal_insert_lsn() function
131151
*/
@@ -460,12 +480,7 @@ libpq_executeFileMap(filemap_t *map)
460480
* need to fetch.
461481
*/
462482
sql="CREATE TEMPORARY TABLE fetchchunks(path text, begin int8, len int4);";
463-
res=PQexec(conn,sql);
464-
465-
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
466-
pg_fatal("could not create temporary table: %s",
467-
PQresultErrorMessage(res));
468-
PQclear(res);
483+
run_simple_command(sql);
469484

470485
sql="COPY fetchchunks FROM STDIN";
471486
res=PQexec(conn,sql);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp