From f8c183a1ac02aef14832c1f29946ef2bcb5866b7 Mon Sep 17 00:00:00 2001 From: Greg Stark Date: Mon, 15 Feb 2010 00:50:57 +0000 Subject: 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. --- src/backend/storage/file/fd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/backend/storage/file/fd.c') 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: * @@ -319,6 +319,22 @@ pg_fdatasync(int fd) return 0; } +/* + * 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 * -- cgit v1.2.3