From 504c717599b20cdaf09e9d7b6ecd152cc7a3a71a Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Sat, 18 Oct 2014 03:06:34 +0900 Subject: [PATCH] Fix bug in handling of connections that pg_receivexlog creates. Previously pg_receivexlog created new connection for WAL streaming even though another connection which had been established to create or delete the replication slot was being left. This caused the unused connection to be left uselessly until pg_receivexlog exited. This bug was introduced by the commit d9f38c7. This patch changes pg_receivexlog so that the connection for the replication slot is reused for WAL streaming. Andres Freund, slightly modified by me, reviewed by Michael Paquier --- src/bin/pg_basebackup/pg_receivexlog.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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();