directory-fsync-8.1-to-8.4.patch

text/x-patch

Filename: directory-fsync-8.1-to-8.4.patch
Type: text/x-patch
Part: 0
Message: Re: [HACKERS] Re: Faster CREATE DATABASE by delaying fsync (was 8.4.1 ubuntu karmic slow createdb)

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/port/copydir.c 0 0
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);
  }
  
  /*