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

Commit630cd14

Browse files
committed
Add initdb --sync-only option to sync the data directory to durable
storage.Have pg_upgrade use it, and enable server options fsync=off andfull_page_writes=off.Document that users turning fsync from off to on should run initdb--sync-only.[ Previous commit was incorrectly applied as a git merge. ]
1 parent25d1ed0 commit630cd14

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

‎contrib/pg_upgrade/pg_upgrade.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ main(int argc, char **argv)
150150
new_cluster.pgdata);
151151
check_ok();
152152

153+
prep_status("Sync data directory to disk");
154+
exec_prog(UTILITY_LOG_FILE,NULL, true,
155+
"\"%s/initdb\" --sync-only \"%s\"",new_cluster.bindir,
156+
new_cluster.pgdata);
157+
check_ok();
158+
153159
create_script_for_cluster_analyze(&analyze_script_file_name);
154160
create_script_for_old_cluster_deletion(&deletion_script_file_name);
155161

‎contrib/pg_upgrade/server.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,19 @@ start_postmaster(ClusterInfo *cluster)
209209
* a gap of 2000000000 from the current xid counter, so autovacuum will
210210
* not touch them.
211211
*
212-
*synchronous_commit=off improves object creation speed, and we only
213-
*modify the new cluster, so only use it there. If there is a crash,
214-
*the new cluster has to be recreated anyway.
212+
* Turn off durability requirements to improve object creation speed, and
213+
* we only modify the new cluster, so only use it there. If there is a
214+
* crash, the new cluster has to be recreated anyway. fsync=off is a big
215+
* win on ext4.
215216
*/
216217
snprintf(cmd,sizeof(cmd),
217218
"\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" -o \"-p %d%s%s%s%s\" start",
218219
cluster->bindir,SERVER_LOG_FILE,cluster->pgconfig,cluster->port,
219220
(cluster->controldata.cat_ver >=
220221
BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ?" -b" :
221222
" -c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
222-
(cluster==&new_cluster) ?" -c synchronous_commit=off" :"",
223+
(cluster==&new_cluster) ?
224+
" -c synchronous_commit=off -c fsync=off -c full_page_writes=off" :"",
223225
cluster->pgopts ?cluster->pgopts :"",socket_string);
224226

225227
/*

‎doc/src/sgml/config.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,15 @@ include 'filename'
16961696
turning off <varname>fsync</varname>.
16971697
</para>
16981698

1699+
<para>
1700+
For reliable recovery when changing <varname>fsync</varname>
1701+
off to on, it is necessary to force all modified buffers in the
1702+
kernel to durable storage. This can be done while the cluster
1703+
is shutdown or while fsync is on by running <command>initdb
1704+
--sync-only</command>, running <command>sync</>, unmounting the
1705+
file system, or rebooting the server.
1706+
</para>
1707+
16991708
<para>
17001709
In many situations, turning off <xref linkend="guc-synchronous-commit">
17011710
for noncritical transactions can provide much of the potential

‎doc/src/sgml/ref/initdb.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ PostgreSQL documentation
244244
</listitem>
245245
</varlistentry>
246246

247+
<varlistentry>
248+
<term><option>-S</option></term>
249+
<term><option>--sync-only</option></term>
250+
<listitem>
251+
<para>
252+
Safely write all database files to disk and exit. This does not
253+
perform any of the normal <application>initdb</> operations.
254+
</para>
255+
</listitem>
256+
</varlistentry>
257+
247258
<varlistentry>
248259
<term><option>-T <replaceable>CFG</></option></term>
249260
<term><option>--text-search-config=<replaceable>CFG</></option></term>

‎src/bin/initdb/initdb.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static const char *authmethodlocal = "";
118118
staticbooldebug= false;
119119
staticboolnoclean= false;
120120
staticbooldo_sync= true;
121+
staticboolsync_only= false;
121122
staticboolshow_setting= false;
122123
staticchar*xlog_dir="";
123124

@@ -2796,6 +2797,7 @@ usage(const char *progname)
27962797
printf(_(" -n, --noclean do not clean up after errors\n"));
27972798
printf(_(" -N, --nosync do not wait for changes to be written safely to disk\n"));
27982799
printf(_(" -s, --show show internal settings\n"));
2800+
printf(_(" -S, --sync-only only sync data directory\n"));
27992801
printf(_("\nOther options:\n"));
28002802
printf(_(" -V, --version output version information, then exit\n"));
28012803
printf(_(" -?, --help show this help, then exit\n"));
@@ -3445,6 +3447,7 @@ main(int argc, char *argv[])
34453447
{"show",no_argument,NULL,'s'},
34463448
{"noclean",no_argument,NULL,'n'},
34473449
{"nosync",no_argument,NULL,'N'},
3450+
{"sync-only",no_argument,NULL,'S'},
34483451
{"xlogdir",required_argument,NULL,'X'},
34493452
{NULL,0,NULL,0}
34503453
};
@@ -3476,7 +3479,7 @@ main(int argc, char *argv[])
34763479

34773480
/* process command-line options */
34783481

3479-
while ((c=getopt_long(argc,argv,"dD:E:L:nNU:WA:sT:X:",long_options,&option_index))!=-1)
3482+
while ((c=getopt_long(argc,argv,"dD:E:L:nNU:WA:sST:X:",long_options,&option_index))!=-1)
34803483
{
34813484
switch (c)
34823485
{
@@ -3522,6 +3525,9 @@ main(int argc, char *argv[])
35223525
case'N':
35233526
do_sync= false;
35243527
break;
3528+
case'S':
3529+
sync_only= true;
3530+
break;
35253531
case'L':
35263532
share_path=pg_strdup(optarg);
35273533
break;
@@ -3589,6 +3595,14 @@ main(int argc, char *argv[])
35893595
exit(1);
35903596
}
35913597

3598+
/* If we only need to fsync, just to it and exit */
3599+
if (sync_only)
3600+
{
3601+
setup_pgdata();
3602+
perform_fsync();
3603+
return0;
3604+
}
3605+
35923606
if (pwprompt&&pwfilename)
35933607
{
35943608
fprintf(stderr,_("%s: password prompt and password file cannot be specified together\n"),progname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp