diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index 7374cc8eb4..bc0940aeaf 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -293,7 +293,8 @@ StreamLog(void) /* * Connect in replication mode to the server */ - conn = GetConnection(); + if (conn == NULL) + conn = GetConnection(); if (!conn) /* Error message already written in GetConnection() */ return; @@ -345,6 +346,7 @@ StreamLog(void) fsync_interval); PQfinish(conn); + conn = NULL; } /* @@ -591,6 +593,11 @@ main(int argc, char **argv) disconnect_and_exit(1); } + /* + * Don't close the connection here so that subsequent StreamLog() + * can reuse it. + */ + while (true) { StreamLog();