pgsql: Add fsync capability to initdb, and use sync_file_range() if ava

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add fsync capability to initdb, and use sync_file_range() if ava
Date: 2012-07-13 21:17:10
Message-ID: E1SpnEc-0007qr-Dj@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add fsync capability to initdb, and use sync_file_range() if available.

Historically we have not worried about fsync'ing anything during initdb
(in fact, initdb intentionally passes -F to each backend launch to prevent
it from fsync'ing). But with filesystems getting more aggressive about
caching data, that's not such a good plan anymore. Make initdb do a pass
over the finished data directory tree to fsync everything. For testing
purposes, the -N/--nosync flag can be used to restore the old behavior.

Also, testing shows that on Linux, sync_file_range() is much faster than
posix_fadvise() for hinting to the kernel that an fsync is coming,
apparently because the latter blocks on a rather small request queue while
the former doesn't. So use this function if available in initdb, and also
in the backend's pg_flush_data() (where it currently will affect only the
speed of CREATE DATABASE's cloning step).

We will later make pg_regress invoke initdb with the --nosync flag
to avoid slowing down cases such as "make check" in contrib. But
let's not do so until we've shaken out any portability issues in this
patch.

Jeff Davis, reviewed by Andres Freund

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/b966dd6c4228d696b291c1cdcb5ab8c8475fefa8

Modified Files
--------------
configure | 3 +-
configure.in | 2 +-
doc/src/sgml/ref/initdb.sgml | 15 +++
src/backend/storage/file/fd.c | 7 +-
src/bin/initdb/initdb.c | 230 ++++++++++++++++++++++++++++++++++++++++-
src/include/pg_config.h.in | 3 +
src/include/pg_config.h.win32 | 3 +
7 files changed, 258 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2012-07-14 11:08:22 pgsql: Add link to PEP 394 regarding python2 vs python3 naming
Previous Message Tom Lane 2012-07-13 15:37:48 pgsql: Cosmetic cleanup of ginInsertValue().