@@ -41,8 +41,8 @@ static PGresult *HandleCopyStream(PGconn *conn, StreamCtl *stream,
4141XLogRecPtr * stoppos );
4242static int CopyStreamPoll (PGconn * conn ,long timeout_ms );
4343static int CopyStreamReceive (PGconn * conn ,long timeout ,char * * buffer );
44- static bool ProcessKeepaliveMsg (PGconn * conn ,char * copybuf , int len ,
45- XLogRecPtr blockpos ,int64 * last_status );
44+ static bool ProcessKeepaliveMsg (PGconn * conn ,StreamCtl * stream , char * copybuf ,
45+ int len , XLogRecPtr blockpos ,int64 * last_status );
4646static bool ProcessXLogDataMsg (PGconn * conn ,StreamCtl * stream ,char * copybuf ,int len ,
4747XLogRecPtr * blockpos );
4848static PGresult * HandleEndOfCopyStream (PGconn * conn ,StreamCtl * stream ,char * copybuf ,
@@ -56,7 +56,7 @@ static bool ReadEndOfStreamingResult(PGresult *res, XLogRecPtr *startpos,
5656uint32 * timeline );
5757
5858static bool
59- mark_file_as_archived (const char * basedir ,const char * fname )
59+ mark_file_as_archived (const char * basedir ,const char * fname , bool do_sync )
6060{
6161int fd ;
6262static char tmppath [MAXPGPATH ];
@@ -74,10 +74,10 @@ mark_file_as_archived(const char *basedir, const char *fname)
7474
7575close (fd );
7676
77- if (fsync_fname (tmppath , false,progname )!= 0 )
77+ if (do_sync && fsync_fname (tmppath , false,progname )!= 0 )
7878return false;
7979
80- if (fsync_parent_path (tmppath ,progname )!= 0 )
80+ if (do_sync && fsync_parent_path (tmppath ,progname )!= 0 )
8181return false;
8282
8383return true;
@@ -134,9 +134,9 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
134134 * fsync, in case of a previous crash between padding and fsyncing the
135135 * file.
136136 */
137- if (fsync_fname (fn , false,progname )!= 0 )
137+ if (stream -> do_sync && fsync_fname (fn , false,progname )!= 0 )
138138return false;
139- if (fsync_parent_path (fn ,progname )!= 0 )
139+ if (stream -> do_sync && fsync_parent_path (fn ,progname )!= 0 )
140140return false;
141141
142142return true;
@@ -173,9 +173,9 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
173173 * using synchronous mode, where the file is modified and fsynced
174174 * in-place, without a directory fsync.
175175 */
176- if (fsync_fname (fn , false,progname )!= 0 )
176+ if (stream -> do_sync && fsync_fname (fn , false,progname )!= 0 )
177177return false;
178- if (fsync_parent_path (fn ,progname )!= 0 )
178+ if (stream -> do_sync && fsync_parent_path (fn ,progname )!= 0 )
179179return false;
180180
181181if (lseek (f ,SEEK_SET ,0 )!= 0 )
@@ -212,7 +212,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
212212return false;
213213}
214214
215- if (fsync (walfile )!= 0 )
215+ if (stream -> do_sync && fsync (walfile )!= 0 )
216216{
217217fprintf (stderr ,_ ("%s: could not fsync file \"%s\": %s\n" ),
218218progname ,current_walfile_name ,strerror (errno ));
@@ -258,7 +258,8 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
258258if (currpos == XLOG_SEG_SIZE && stream -> mark_done )
259259{
260260/* writes error message if failed */
261- if (!mark_file_as_archived (stream -> basedir ,current_walfile_name ))
261+ if (!mark_file_as_archived (stream -> basedir ,current_walfile_name ,
262+ stream -> do_sync ))
262263return false;
263264}
264265
@@ -378,7 +379,8 @@ writeTimeLineHistoryFile(StreamCtl *stream, char *filename, char *content)
378379if (stream -> mark_done )
379380{
380381/* writes error message if failed */
381- if (!mark_file_as_archived (stream -> basedir ,histfname ))
382+ if (!mark_file_as_archived (stream -> basedir ,histfname ,
383+ stream -> do_sync ))
382384return false;
383385}
384386
@@ -836,7 +838,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
836838 */
837839if (stream -> synchronous && lastFlushPosition < blockpos && walfile != -1 )
838840{
839- if (fsync (walfile )!= 0 )
841+ if (stream -> do_sync && fsync (walfile )!= 0 )
840842{
841843fprintf (stderr ,_ ("%s: could not fsync file \"%s\": %s\n" ),
842844progname ,current_walfile_name ,strerror (errno ));
@@ -890,7 +892,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
890892/* Check the message type. */
891893if (copybuf [0 ]== 'k' )
892894{
893- if (!ProcessKeepaliveMsg (conn ,copybuf ,r ,blockpos ,
895+ if (!ProcessKeepaliveMsg (conn ,stream , copybuf ,r ,blockpos ,
894896& last_status ))
895897gotoerror ;
896898}
@@ -1043,7 +1045,7 @@ CopyStreamReceive(PGconn *conn, long timeout, char **buffer)
10431045 * Process the keepalive message.
10441046 */
10451047static bool
1046- ProcessKeepaliveMsg (PGconn * conn ,char * copybuf ,int len ,
1048+ ProcessKeepaliveMsg (PGconn * conn ,StreamCtl * stream , char * copybuf ,int len ,
10471049XLogRecPtr blockpos ,int64 * last_status )
10481050{
10491051int pos ;
@@ -1079,7 +1081,7 @@ ProcessKeepaliveMsg(PGconn *conn, char *copybuf, int len,
10791081 * data has been successfully replicated or not, at the normal
10801082 * shutdown of the server.
10811083 */
1082- if (fsync (walfile )!= 0 )
1084+ if (stream -> do_sync && fsync (walfile )!= 0 )
10831085{
10841086fprintf (stderr ,_ ("%s: could not fsync file \"%s\": %s\n" ),
10851087progname ,current_walfile_name ,strerror (errno ));