Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e0090c8

Browse files
committed
Add option -N/--no-sync to pg_checksums
This is an option consistent with what pg_dump, pg_rewind and pg_basebackup provide which is useful for leveraging the I/O effort when testing things, not to be used in a production environment. Author: Michael Paquier Reviewed-by: Michael Banck, Fabien Coelho, Sergei Kornilov Discussion: https://postgr.es/m/20181221201616.GD4974@nighthawk.caipicrew.dd-dns.de
1 parent 7b084b3 commit e0090c8

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

doc/src/sgml/ref/pg_checksums.sgml

+16
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ PostgreSQL documentation
100100
</listitem>
101101
</varlistentry>
102102

103+
<varlistentry>
104+
<term><option>-N</option></term>
105+
<term><option>--no-sync</option></term>
106+
<listitem>
107+
<para>
108+
By default, <command>pg_checksums</command> will wait for all files
109+
to be written safely to disk. This option causes
110+
<command>pg_checksums</command> to return without waiting, which is
111+
faster, but means that a subsequent operating system crash can leave
112+
the updated data folder corrupt. Generally, this option is useful
113+
for testing but should not be used on a production installation.
114+
This option has no effect when using <literal>--check</literal>.
115+
</para>
116+
</listitem>
117+
</varlistentry>
118+
103119
<varlistentry>
104120
<term><option>-v</option></term>
105121
<term><option>--verbose</option></term>

src/bin/pg_checksums/pg_checksums.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static int64 badblocks = 0;
3535
static ControlFileData *ControlFile;
3636

3737
static char *only_relfilenode = NULL;
38+
static bool do_sync = true;
3839
static bool verbose = false;
3940

4041
typedef enum
@@ -69,6 +70,7 @@ usage(void)
6970
printf(_(" -c, --check check data checksums (default)\n"));
7071
printf(_(" -d, --disable disable data checksums\n"));
7172
printf(_(" -e, --enable enable data checksums\n"));
73+
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
7274
printf(_(" -v, --verbose output verbose messages\n"));
7375
printf(_(" -r RELFILENODE check only relation with specified relfilenode\n"));
7476
printf(_(" -V, --version output version information, then exit\n"));
@@ -297,6 +299,7 @@ main(int argc, char *argv[])
297299
{"pgdata", required_argument, NULL, 'D'},
298300
{"disable", no_argument, NULL, 'd'},
299301
{"enable", no_argument, NULL, 'e'},
302+
{"no-sync", no_argument, NULL, 'N'},
300303
{"verbose", no_argument, NULL, 'v'},
301304
{NULL, 0, NULL, 0}
302305
};
@@ -324,7 +327,7 @@ main(int argc, char *argv[])
324327
}
325328
}
326329

327-
while ((c = getopt_long(argc, argv, "cD:der:v", long_options, &option_index)) != -1)
330+
while ((c = getopt_long(argc, argv, "cD:deNr:v", long_options, &option_index)) != -1)
328331
{
329332
switch (c)
330333
{
@@ -337,6 +340,9 @@ main(int argc, char *argv[])
337340
case 'e':
338341
mode = PG_MODE_ENABLE;
339342
break;
343+
case 'N':
344+
do_sync = false;
345+
break;
340346
case 'v':
341347
verbose = true;
342348
break;
@@ -472,11 +478,14 @@ main(int argc, char *argv[])
472478
ControlFile->data_checksum_version =
473479
(mode == PG_MODE_ENABLE) ? PG_DATA_CHECKSUM_VERSION : 0;
474480

475-
printf(_("Syncing data directory\n"));
476-
fsync_pgdata(DataDir, progname, PG_VERSION_NUM);
481+
if (do_sync)
482+
{
483+
printf(_("Syncing data directory\n"));
484+
fsync_pgdata(DataDir, progname, PG_VERSION_NUM);
485+
}
477486

478487
printf(_("Updating control file\n"));
479-
update_controlfile(DataDir, progname, ControlFile, true);
488+
update_controlfile(DataDir, progname, ControlFile, do_sync);
480489

481490
if (verbose)
482491
printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);

src/bin/pg_checksums/t/002_actions.pl

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,24 @@ sub check_relation_corruption
101101
append_to_file "$pgdata/global/pgsql_tmp/1.1", "foo";
102102

103103
# Enable checksums.
104-
command_ok(['pg_checksums', '--enable', '-D', $pgdata],
104+
command_ok(['pg_checksums', '--enable', '--no-sync', '-D', $pgdata],
105105
"checksums successfully enabled in cluster");
106106

107107
# Successive attempt to enable checksums fails.
108-
command_fails(['pg_checksums', '--enable', '-D', $pgdata],
108+
command_fails(['pg_checksums', '--enable', '--no-sync', '-D', $pgdata],
109109
"enabling checksums fails if already enabled");
110110

111111
# Control file should know that checksums are enabled.
112112
command_like(['pg_controldata', $pgdata],
113113
qr/Data page checksum version:.*1/,
114114
'checksums enabled in control file');
115115

116-
# Disable checksums again.
116+
# Disable checksums again. Flush result here as that should be cheap.
117117
command_ok(['pg_checksums', '--disable', '-D', $pgdata],
118118
"checksums successfully disabled in cluster");
119119

120120
# Successive attempt to disable checksums fails.
121-
command_fails(['pg_checksums', '--disable', '-D', $pgdata],
121+
command_fails(['pg_checksums', '--disable', '--no-sync', '-D', $pgdata],
122122
"disabling checksums fails if already disabled");
123123

124124
# Control file should know that checksums are disabled.
@@ -127,7 +127,7 @@ sub check_relation_corruption
127127
'checksums disabled in control file');
128128

129129
# Enable checksums again for follow-up tests.
130-
command_ok(['pg_checksums', '--enable', '-D', $pgdata],
130+
command_ok(['pg_checksums', '--enable', '--no-sync', '-D', $pgdata],
131131
"checksums successfully enabled in cluster");
132132

133133
# Control file should know that checksums are enabled.

0 commit comments

Comments
 (0)