On Monday 08 February 2010 05:53:23 Robert Haas wrote: > On Sun, Feb 7, 2010 at 10:09 PM, Alvaro Herrera > > <alvherre@xxxxxxxxxxxxxxxxx> wrote: > > Andres Freund escribió: > >> I personally think the fsync on the directory should be added to the > >> stable branches - other opinions? > >> If wanted I can prepare patches for that. > > > > Yeah, it seems there are two patches here -- one is the addition of > > fsync_fname() and the other is the fsync_prepare stuff. > > Andres, you want to take a crack at splitting this up? I hope I didnt duplicate Gregs work, but I didnt hear back from him, so... Everything <8.1 is hopeless because cp is used there... I didnt see it worth to replace that. The patch applies cleanly for 8.1 to 8.4 and survives the regression tests Given pg's heavy commit model I didnt see a point to split the patch for 9.0 as well... Andres
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); } /*
-- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance