8000 Disable synchronous commits in pg_rewind. · postgrespro/postgres_cluster@aab8096 · GitHub
[go: up one dir, main page]

Skip to content

Commit aab8096

Browse files
committed
Disable synchronous commits in pg_rewind.
If you point pg_rewind to a server that is using synchronous replication, with "pg_rewind --source-server=...", and the replication is not working for some reason, pg_rewind will get stuck because it creates a temporary table, which needs to be replicated. You could call broken replication a pilot error, but pg_rewind is often used in special circumstances, when there are changes to the replication setup. We don't do any "real" updates, and we don't care about f 10000 syncing or replicating the operations on the temporary tables, so fix that by setting synchronous_commit off. Michael Banck, Michael Paquier. Backpatch to 9.5, where pg_rewind was introduced. Discussion: <20161005143938.GA12247@nighthawk.caipicrew.dd-dns.de>
1 parent bfcd07b commit aab8096

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/bin/pg_rewind/libpq_fetch.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void
4949
libpqConnect(const char *connstr)
5050
{
5151
char *str;
52+
PGresult *res;
5253

5354
conn = PQconnectdb(connstr);
5455
if (PQstatus(conn) == CONNECTION_BAD)
@@ -77,6 +78,19 @@ libpqConnect(const char *connstr)
7778
if (strcmp(str, "on") != 0)
7879
pg_fatal("full_page_writes must be enabled in the source server\n");
7980
pg_free(str);
81+
82+
/*
83+
* Although we don't do any "real" updates, we do work with a temporary
84+
* table. We don't care about synchronous commit for that. It doesn't
85+
* otherwise matter much, but if the server is using synchronous
86+
* replication, and replication isn't working for some reason, we don't
87+
* want to get stuck, waiting for it to start working again.
88+
*/
89+
res = PQexec(conn, "SET synchronous_commit = off");
90+
if (PQresultStatus(res) != PGRES_COMMAND_OK)
91+
pg_fatal("could not set up connection context: %s",
92+
PQresultErrorMessage(res));
93+
PQclear(res);
8094
}
8195

8296
/*

0 commit comments

Comments
 (0)
0