Reduce the amount of data loss on the standby

Started by Fujii Masaoalmost 15 years ago2 messages
#1Fujii Masao
masao.fujii@gmail.com
1 attachment(s)

Hi,

I propose the patch which reduces the amount of data loss
on the standby.

If you create the trigger file after replication is terminated,
the standby tries to replay all the WAL available in pg_xlog
and the archive. This behavior is OK, and it's helpful to reduce
the amount of data loss.

But, if you create the trigger file while walreceiver is in
progress, the standby replays only the WAL streamed from
the master. Even if there are many outstanding WAL files in
the archive or pg_xlog, they are not replayed. This might
cause much data loss, so I think we should fix it.

The attached patch changes the startup process so that
it tries to replay all the WAL available in the archive and pg_xlog
even if the trigger file is found while walreceiver is running.

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachments:

reduce_data_loss_v1.patchapplication/octet-stream; name=reduce_data_loss_v1.patchDownload
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 9460,9466 **** retry:
  					 * five seconds like in the WAL file polling case below.
  					 */
  					if (CheckForStandbyTrigger())
! 						goto triggered;
  
  					/*
  					 * Wait for more WAL to arrive, or timeout to be reached
--- 9460,9466 ----
  					 * five seconds like in the WAL file polling case below.
  					 */
  					if (CheckForStandbyTrigger())
! 						goto retry;
  
  					/*
  					 * Wait for more WAL to arrive, or timeout to be reached
***************
*** 9727,9732 **** static bool
--- 9727,9736 ----
  CheckForStandbyTrigger(void)
  {
  	struct stat stat_buf;
+ 	static bool	triggered = false;
+ 
+ 	if (triggered)
+ 		return true;
  
  	if (TriggerFile == NULL)
  		return false;
***************
*** 9737,9742 **** CheckForStandbyTrigger(void)
--- 9741,9747 ----
  				(errmsg("trigger file found: %s", TriggerFile)));
  		ShutdownWalRcv();
  		unlink(TriggerFile);
+ 		triggered = true;
  		return true;
  	}
  	return false;
#2Simon Riggs
simon@2ndQuadrant.com
In reply to: Fujii Masao (#1)
Re: Reduce the amount of data loss on the standby

On Sat, 2011-01-15 at 07:31 +0900, Fujii Masao wrote:

I propose the patch which reduces the amount of data loss
on the standby.

Committed. Well spotted.

--
Simon Riggs http://www.2ndQuadrant.com/books/
PostgreSQL Development, 24x7 Support, Training and Services