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

Commitbe182e4

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 parentb1907d6 commitbe182e4

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
@@ -39,6 +39,7 @@ static PGconn *conn = NULL;
3939
staticvoidreceiveFileChunks(constchar*sql);
4040
staticvoidexecute_pagemap(datapagemap_t*pagemap,constchar*path);
4141
staticchar*run_simple_query(constchar*sql);
42+
staticvoidrun_simple_command(constchar*sql);
4243

4344
void
4445
libpqConnect(constchar*connstr)
@@ -54,6 +55,11 @@ libpqConnect(const char *connstr)
5455
if (showprogress)
5556
pg_log_info("connected to server");
5657

58+
/* disable all types of timeouts */
59+
run_simple_command("SET statement_timeout = 0");
60+
run_simple_command("SET lock_timeout = 0");
61+
run_simple_command("SET idle_in_transaction_session_timeout = 0");
62+
5763
res=PQexec(conn,ALWAYS_SECURE_SEARCH_PATH_SQL);
5864
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
5965
pg_fatal("could not clear search_path: %s",
@@ -88,11 +94,7 @@ libpqConnect(const char *connstr)
8894
* replication, and replication isn't working for some reason, we don't
8995
* want to get stuck, waiting for it to start working again.
9096
*/
91-
res=PQexec(conn,"SET synchronous_commit = off");
92-
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
93-
pg_fatal("could not set up connection context: %s",
94-
PQresultErrorMessage(res));
95-
PQclear(res);
97+
run_simple_command("SET synchronous_commit = off");
9698
}
9799

98100
/*
@@ -122,6 +124,24 @@ run_simple_query(const char *sql)
122124
returnresult;
123125
}
124126

127+
/*
128+
* Runs a command.
129+
* In the event of a failure, exit immediately.
130+
*/
131+
staticvoid
132+
run_simple_command(constchar*sql)
133+
{
134+
PGresult*res;
135+
136+
res=PQexec(conn,sql);
137+
138+
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
139+
pg_fatal("error running query (%s) in source server: %s",
140+
sql,PQresultErrorMessage(res));
141+
142+
PQclear(res);
143+
}
144+
125145
/*
126146
* Calls pg_current_wal_insert_lsn() function
127147
*/
@@ -427,12 +447,7 @@ libpq_executeFileMap(filemap_t *map)
427447
* need to fetch.
428448
*/
429449
sql="CREATE TEMPORARY TABLE fetchchunks(path text, begin int8, len int4);";
430-
res=PQexec(conn,sql);
431-
432-
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
433-
pg_fatal("could not create temporary table: %s",
434-
PQresultErrorMessage(res));
435-
PQclear(res);
450+
run_simple_command(sql);
436451

437452
sql="COPY fetchchunks FROM STDIN";
438453
res=PQexec(conn,sql);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp