On Tue, Oct 7, 2014 at 2:58 PM, Fujii Masao <masao.fu...@gmail.com> wrote:
> On Tue, Oct 7, 2014 at 2:55 PM, Andres Freund <and...@anarazel.de> wrote:
>> On 2014-10-07 14:51:59 +0900, Fujii Masao wrote:
>>> >> *** a/src/bin/pg_basebackup/pg_receivexlog.c
>>> >> --- b/src/bin/pg_basebackup/pg_receivexlog.c
>>> >> ***************
>>> >> *** 591,596 **** main(int argc, char **argv)
>>> >> --- 591,598 ----
>>> >>                       disconnect_and_exit(1);
>>> >>       }
>>> >>
>>> >> +     PQfinish(conn);
>>> >> +
>>> >>       while (true)
>>> >>       {
>>> >>               StreamLog();
>>> >
>>> > But wouldn't it be better to simply pass in the connection to
>>> > StreamLog()?
>>>
>>> ISTM that the idea would make the code in StreamLog() somewhat complicated,
>>> i.e., StreamLog() needs to always check whether the conn is valid or not 
>>> before
>>> trying to create new connection. We cannot remove the code to create new
>>> connection in StreamLog() because it needs to reconnect to the server when
>>> the connection is terminated (of course in the case where --no-loop is
>>> not specified).
>>
>> Not that much imo.
>>
>> if (conn == NULL)
>>    conn = GetConnection();
>>
>> if (!conn)
>>         /* Error message already written in GetConnection() */
>>         return;
>>
>> ...
>>
>> PQfinish(conn);
>> conn = NULL;
>
> I'm OK with that.

Attached patch does what Andres suggested. Barring any objection, I
will apply it.

Regards,

-- 
Fujii Masao
*** a/src/bin/pg_basebackup/pg_receivexlog.c
--- b/src/bin/pg_basebackup/pg_receivexlog.c
***************
*** 293,299 **** StreamLog(void)
  	/*
  	 * Connect in replication mode to the server
  	 */
! 	conn = GetConnection();
  	if (!conn)
  		/* Error message already written in GetConnection() */
  		return;
--- 293,300 ----
  	/*
  	 * Connect in replication mode to the server
  	 */
! 	if (conn == NULL)
! 		conn = GetConnection();
  	if (!conn)
  		/* Error message already written in GetConnection() */
  		return;
***************
*** 345,350 **** StreamLog(void)
--- 346,352 ----
  					  fsync_interval);
  
  	PQfinish(conn);
+ 	conn = NULL;
  }
  
  /*
***************
*** 591,596 **** main(int argc, char **argv)
--- 593,603 ----
  			disconnect_and_exit(1);
  	}
  
+ 	/*
+ 	 * Don't close the connection here so that subsequent StreamLog()
+ 	 * can reuse it.
+ 	 */
+ 
  	while (true)
  	{
  		StreamLog();
-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

Reply via email to