Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1012492

Browse files
committed
Make CREATE DATABASE safe against losing whole files by fsyncing the
directory and not just the individual files.Back-patch to 8.1 -- before that we just called "cp -r" and neverfsynced anything anyways.
1 parenta05af1d commit1012492

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

‎src/port/copydir.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*as a service.
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.24 2010/01/02 16:58:13 momjian Exp $
14+
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.25 2010/02/14 17:50:52 stark Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -50,6 +50,7 @@ copydir(char *fromdir, char *todir, bool recurse)
5050
{
5151
DIR*xldir;
5252
structdirent*xlde;
53+
intdirfd;
5354
charfromfile[MAXPGPATH];
5455
chartofile[MAXPGPATH];
5556

@@ -91,6 +92,26 @@ copydir(char *fromdir, char *todir, bool recurse)
9192
}
9293

9394
FreeDir(xldir);
95+
96+
/*
97+
* fsync the directory to make sure not just the data but also the
98+
* new directory file entries have reached the disk. While needed
99+
* by most filesystems, the window got bigger with newer ones like
100+
* ext4.
101+
*/
102+
dirfd=BasicOpenFile(todir,
103+
O_RDONLY |PG_BINARY,
104+
S_IRUSR |S_IWUSR);
105+
if(dirfd==-1)
106+
ereport(ERROR,
107+
(errcode_for_file_access(),
108+
errmsg("could not open directory for fsync \"%s\": %m",todir)));
109+
110+
if(pg_fsync(dirfd)==-1)
111+
ereport(ERROR,
112+
(errcode_for_file_access(),
113+
errmsg("could not fsync directory \"%s\": %m",todir)));
114+
close(dirfd);
94115
}
95116

96117
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp