diff --git a/src/bin/pg_rewind/libpq_fetch.c b/src/bin/pg_rewind/libpq_fetch.c
index 9239009..4bc2bc3 100644
--- a/src/bin/pg_rewind/libpq_fetch.c
+++ b/src/bin/pg_rewind/libpq_fetch.c
@@ -403,6 +403,17 @@ libpq_executeFileMap(filemap_t *map)
 	int			i;
 
 	/*
+	 * Set up connection context, with synchronous replication enabled the
+	 * following command could stuck the connection.
+	 */
+	sql = "SET synchronous_commit = off;";
+	res = PQexec(conn, sql);
+	if (PQresultStatus(res) != PGRES_COMMAND_OK)
+		pg_fatal("could not set up connection context: %s",
+				 PQresultErrorMessage(res));
+	PQclear(res);
+
+	/*
 	 * First create a temporary table, and load it with the blocks that we
 	 * need to fetch.
 	 */
