Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 75BCA632CBC for ; Sun, 14 Feb 2010 16:49:27 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 30625-04 for ; Sun, 14 Feb 2010 20:49:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.anarazel.de (mail.anarazel.de [217.115.131.40]) by mail.postgresql.org (Postfix) with ESMTP id EF74F632951 for ; Sun, 14 Feb 2010 16:49:16 -0400 (AST) Received: from alap2.localnet (e178192155.adsl.alicedsl.de [85.178.192.155]) by mail.anarazel.de (Postfix) with ESMTPSA id 3E2D344800A; Sun, 14 Feb 2010 21:49:14 +0100 (CET) From: Andres Freund To: pgsql-hackers@postgresql.org Subject: Re: Re: Faster CREATE DATABASE by delaying fsync Date: Sun, 14 Feb 2010 21:49:09 +0100 User-Agent: KMail/1.13.0 (Linux/2.6.33-rc7-andres-00124-g828206f; KDE/4.4.0; x86_64; ; ) Cc: Mark Mielke , Florian Weimer , Tom Lane , Greg Stark , Robert Haas References: <4427a97a0912101235x3ade510blcc00d5ce9883c6b6@mail.gmail.com> <87wryfpnuv.fsf@mid.deneb.enyo.de> <4B785FDE.8040308@mark.mielke.cc> In-Reply-To: <4B785FDE.8040308@mark.mielke.cc> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201002142149.12786.andres@anarazel.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/1162 X-Sequence-Number: 157505 On Sunday 14 February 2010 21:41:02 Mark Mielke wrote: > On 02/14/2010 03:24 PM, Florian Weimer wrote: > > * Tom Lane: > >>> Which options would that be? I am not aware that there any for any of > >>> the recent linux filesystems. > >> > >> Shouldn't journaling of metadata be sufficient? > > > > You also need to enforce ordering between the directory update and the > > file update. The file metadata is flushed with fsync(), but the > > directory isn't. On some systems, all directory operations are > > synchronous, but not on Linux. > > dirsync > All directory updates within the filesystem should be > done syn- > chronously. This affects the following system calls: > creat, > link, unlink, symlink, mkdir, rmdir, mknod and rename. > > The widely reported problems, though, did not tend to be a problem with > directory changes written too late - but directory changes being written > too early. That is, the directory change is written to disk, but the > file content is not. This is likely because of the "ordered journal" > mode widely used in ext3/ext4 where metadata changes are journalled, but > file pages are not journalled. Therefore, it is important for some > operations, that the file pages are pushed to disk using fsync(file), > before the metadata changes are journalled. Well, but thats not a problem with pg as it fsyncs the file contents. > In theory there is some open hole where directory updates need to be > synchronized with file updates, as POSIX doesn't enforce this ordering, > and we can't trust that all file systems implicitly order things > correctly, but in practice, I don't see this sort of problem happening. I can try to reproduce it if you want... > If you are concerned, enable dirsync. If the filesystem already behaves that way a fsync on it should be fairly cheap. If it doesnt behave that way doing it is correct... Besides there is no reason to fsync the directory before the checkpoint, so dirsync would require a higher cost than doing it correctly. Andres