Commit e0090c86 authored by Michael Paquier's avatar Michael Paquier

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
parent 7b084b38
...@@ -100,6 +100,22 @@ PostgreSQL documentation ...@@ -100,6 +100,22 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-N</option></term>
<term><option>--no-sync</option></term>
<listitem>
<para>
By default, <command>pg_checksums</command> will wait for all files
to be written safely to disk. This option causes
<command>pg_checksums</command> to return without waiting, which is
faster, but means that a subsequent operating system crash can leave
the updated data folder corrupt. Generally, this option is useful
for testing but should not be used on a production installation.
This option has no effect when using <literal>--check</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-v</option></term> <term><option>-v</option></term>
<term><option>--verbose</option></term> <term><option>--verbose</option></term>
......
...@@ -35,6 +35,7 @@ static int64 badblocks = 0; ...@@ -35,6 +35,7 @@ static int64 badblocks = 0;
static ControlFileData *ControlFile; static ControlFileData *ControlFile;
static char *only_relfilenode = NULL; static char *only_relfilenode = NULL;
static bool do_sync = true;
static bool verbose = false; static bool verbose = false;
typedef enum typedef enum
...@@ -69,6 +70,7 @@ usage(void) ...@@ -69,6 +70,7 @@ usage(void)
printf(_(" -c, --check check data checksums (default)\n")); printf(_(" -c, --check check data checksums (default)\n"));
printf(_(" -d, --disable disable data checksums\n")); printf(_(" -d, --disable disable data checksums\n"));
printf(_(" -e, --enable enable data checksums\n")); printf(_(" -e, --enable enable data checksums\n"));
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
printf(_(" -v, --verbose output verbose messages\n")); printf(_(" -v, --verbose output verbose messages\n"));
printf(_(" -r RELFILENODE check only relation with specified relfilenode\n")); printf(_(" -r RELFILENODE check only relation with specified relfilenode\n"));
printf(_(" -V, --version output version information, then exit\n")); printf(_(" -V, --version output version information, then exit\n"));
...@@ -297,6 +299,7 @@ main(int argc, char *argv[]) ...@@ -297,6 +299,7 @@ main(int argc, char *argv[])
{"pgdata", required_argument, NULL, 'D'}, {"pgdata", required_argument, NULL, 'D'},
{"disable", no_argument, NULL, 'd'}, {"disable", no_argument, NULL, 'd'},
{"enable", no_argument, NULL, 'e'}, {"enable", no_argument, NULL, 'e'},
{"no-sync", no_argument, NULL, 'N'},
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -324,7 +327,7 @@ main(int argc, char *argv[]) ...@@ -324,7 +327,7 @@ main(int argc, char *argv[])
} }
} }
while ((c = getopt_long(argc, argv, "cD:der:v", long_options, &option_index)) != -1) while ((c = getopt_long(argc, argv, "cD:deNr:v", long_options, &option_index)) != -1)
{ {
switch (c) switch (c)
{ {
...@@ -337,6 +340,9 @@ main(int argc, char *argv[]) ...@@ -337,6 +340,9 @@ main(int argc, char *argv[])
case 'e': case 'e':
mode = PG_MODE_ENABLE; mode = PG_MODE_ENABLE;
break; break;
case 'N':
do_sync = false;
break;
case 'v': case 'v':
verbose = true; verbose = true;
break; break;
...@@ -472,11 +478,14 @@ main(int argc, char *argv[]) ...@@ -472,11 +478,14 @@ main(int argc, char *argv[])
ControlFile->data_checksum_version = ControlFile->data_checksum_version =
(mode == PG_MODE_ENABLE) ? PG_DATA_CHECKSUM_VERSION : 0; (mode == PG_MODE_ENABLE) ? PG_DATA_CHECKSUM_VERSION : 0;
printf(_("Syncing data directory\n")); if (do_sync)
fsync_pgdata(DataDir, progname, PG_VERSION_NUM); {
printf(_("Syncing data directory\n"));
fsync_pgdata(DataDir, progname, PG_VERSION_NUM);
}
printf(_("Updating control file\n")); printf(_("Updating control file\n"));
update_controlfile(DataDir, progname, ControlFile, true); update_controlfile(DataDir, progname, ControlFile, do_sync);
if (verbose) if (verbose)
printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version); printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);
......
...@@ -101,11 +101,11 @@ mkdir "$pgdata/global/pgsql_tmp"; ...@@ -101,11 +101,11 @@ mkdir "$pgdata/global/pgsql_tmp";
append_to_file "$pgdata/global/pgsql_tmp/1.1", "foo"; append_to_file "$pgdata/global/pgsql_tmp/1.1", "foo";
# Enable checksums. # Enable checksums.
command_ok(['pg_checksums', '--enable', '-D', $pgdata], command_ok(['pg_checksums', '--enable', '--no-sync', '-D', $pgdata],
"checksums successfully enabled in cluster"); "checksums successfully enabled in cluster");
# Successive attempt to enable checksums fails. # Successive attempt to enable checksums fails.
command_fails(['pg_checksums', '--enable', '-D', $pgdata], command_fails(['pg_checksums', '--enable', '--no-sync', '-D', $pgdata],
"enabling checksums fails if already enabled"); "enabling checksums fails if already enabled");
# Control file should know that checksums are enabled. # Control file should know that checksums are enabled.
...@@ -113,12 +113,12 @@ command_like(['pg_controldata', $pgdata], ...@@ -113,12 +113,12 @@ command_like(['pg_controldata', $pgdata],
qr/Data page checksum version:.*1/, qr/Data page checksum version:.*1/,
'checksums enabled in control file'); 'checksums enabled in control file');
# Disable checksums again. # Disable checksums again. Flush result here as that should be cheap.
command_ok(['pg_checksums', '--disable', '-D', $pgdata], command_ok(['pg_checksums', '--disable', '-D', $pgdata],
"checksums successfully disabled in cluster"); "checksums successfully disabled in cluster");
# Successive attempt to disable checksums fails. # Successive attempt to disable checksums fails.
command_fails(['pg_checksums', '--disable', '-D', $pgdata], command_fails(['pg_checksums', '--disable', '--no-sync', '-D', $pgdata],
"disabling checksums fails if already disabled"); "disabling checksums fails if already disabled");
# Control file should know that checksums are disabled. # Control file should know that checksums are disabled.
...@@ -127,7 +127,7 @@ command_like(['pg_controldata', $pgdata], ...@@ -127,7 +127,7 @@ command_like(['pg_controldata', $pgdata],
'checksums disabled in control file'); 'checksums disabled in control file');
# Enable checksums again for follow-up tests. # Enable checksums again for follow-up tests.
command_ok(['pg_checksums', '--enable', '-D', $pgdata], command_ok(['pg_checksums', '--enable', '--no-sync', '-D', $pgdata],
"checksums successfully enabled in cluster"); "checksums successfully enabled in cluster");
# Control file should know that checksums are enabled. # Control file should know that checksums are enabled.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment