diff --git a/src/port/copydir.c b/src/port/copydir.c
index 72fbf36..b057ffa 100644
*** a/src/port/copydir.c
--- b/src/port/copydir.c
*************** copydir(char *fromdir, char *todir, bool
*** 50,55 ****
--- 50,56 ----
  {
  	DIR		   *xldir;
  	struct dirent *xlde;
+ 	int         dirfd;
  	char		fromfile[MAXPGPATH];
  	char		tofile[MAXPGPATH];
  
*************** copydir(char *fromdir, char *todir, bool
*** 91,96 ****
--- 92,116 ----
  	}
  
  	FreeDir(xldir);
+ 
+ 	/*
+ 	 * fsync the directory to make sure data has reached the
+ 	 * disk. While needed by most filesystems, the window got bigger
+ 	 * with newer ones like ext4.
+ 	 */
+ 	dirfd = BasicOpenFile(todir,
+ 	                      O_RDONLY | PG_BINARY,
+ 	                      S_IRUSR | S_IWUSR);
+ 	if(dirfd == -1)
+ 		ereport(ERROR,
+ 		        (errcode_for_file_access(),
+ 		         errmsg("could not open directory for fsync \"%s\": %m", todir)));
+ 
+ 	if(pg_fsync(dirfd) == -1)
+ 		ereport(ERROR,
+ 				(errcode_for_file_access(),
+ 				 errmsg("could not fsync directory \"%s\": %m", todir)));
+ 	close(dirfd);
  }
  
  /*
