diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index 9facc198e4e176638e98993ce1183ead18eeb930..9a943d049f1ea4e9c8a1c7a82abea822960dc85f 100644
--- a/src/bin/pg_basebackup/pg_receivexlog.c
+++ b/src/bin/pg_basebackup/pg_receivexlog.c
@@ -270,6 +270,8 @@ StreamLog(void)
 	ReceiveXlogStream(conn, startpos, timeline, NULL, basedir,
 					  segment_callback, continue_streaming,
 					  standby_message_timeout);
+
+	PQfinish(conn);
 }
 
 /*