aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/file/fd.c
diff options
context:
space:
mode:
authorGreg Stark <stark@mit.edu>2010-02-15 00:50:57 +0000
committerGreg Stark <stark@mit.edu>2010-02-15 00:50:57 +0000
commitf8c183a1ac02aef14832c1f29946ef2bcb5866b7 (patch)
treefcbeac8862b585b58786fead156a43022d015224 /src/backend/storage/file/fd.c
parente26c539e9f326ea843c0ed005af093b56b55cd4d (diff)
downloadpostgresql-f8c183a1ac02aef14832c1f29946ef2bcb5866b7.tar.gz
postgresql-f8c183a1ac02aef14832c1f29946ef2bcb5866b7.zip
Speed up CREATE DATABASE by deferring the fsyncs until after copying
all the data and using posix_fadvise to nudge the OS into flushing it earlier. This also hopefully makes CREATE DATABASE avoid spamming the cache. Tests show a big speedup on Linux at least on some filesystems. Idea and patch from Andres Freund.
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r--src/backend/storage/file/fd.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index ec27859e606..adea849ab05 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.153 2010/01/12 02:42:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.154 2010/02/15 00:50:57 stark Exp $
*
* NOTES:
*
@@ -320,6 +320,22 @@ pg_fdatasync(int fd)
}
/*
+ * pg_flush_data --- advise OS that the data described won't be needed soon
+ *
+ * Not all platforms have posix_fadvise; treat as noop if not available.
+ */
+int
+pg_flush_data(int fd, off_t offset, off_t amount)
+{
+#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
+ return posix_fadvise(fd, offset, amount, POSIX_FADV_DONTNEED);
+#else
+ return 0;
+#endif
+}
+
+
+/*
* InitFileAccess --- initialize this module during backend startup
*
* This is called during either normal or standalone backend start.