]> granicus.if.org Git - postgresql/commitdiff
Rework options of pg_checksums options for filenode handling
authorMichael Paquier <michael@paquier.xyz>
Thu, 30 May 2019 20:58:17 +0000 (16:58 -0400)
committerMichael Paquier <michael@paquier.xyz>
Thu, 30 May 2019 20:58:17 +0000 (16:58 -0400)
This makes the tool consistent with the option set of oid2name, which
has been historically using -f for filenodes, and has more recently
gained long options and --filenode via 1aaf532.

Reported-by: Peter Eisentraut
Author: Fabien Coelho
Discussion: https://postgr.es/m/97045260-fb9e-e145-a950-cf7d28c4eaea@2ndquadrant.com

doc/src/sgml/ref/pg_checksums.sgml
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_checksums/t/002_actions.pl

index a0ffeb0ab04e0eecd958536e911d63ad28a2d832..33706d1d97acad7cb5868f061aaf43cf16a8a13d 100644 (file)
@@ -100,6 +100,17 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-f <replaceable>filenode</replaceable></option></term>
+      <term><option>--filenode=<replaceable>filenode</replaceable></option></term>
+      <listitem>
+       <para>
+        Only validate checksums in the relation with filenode
+        <replaceable>filenode</replaceable>. 
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-N</option></term>
       <term><option>--no-sync</option></term>
@@ -117,31 +128,22 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
-      <term><option>-v</option></term>
-      <term><option>--verbose</option></term>
-      <listitem>
-       <para>
-        Enable verbose output. Lists all checked files.
-       </para>
-      </listitem>
-     </varlistentry>
-
-     <varlistentry>
-      <term><option>-r <replaceable>relfilenode</replaceable></option></term>
+      <term><option>-P</option></term>
+      <term><option>--progress</option></term>
       <listitem>
        <para>
-        Only validate checksums in the relation with specified relfilenode.
+        Enable progress reporting. Turning this on will deliver a progress
+        report while checking or enabling checksums.
        </para>
       </listitem>
      </varlistentry>
 
      <varlistentry>
-      <term><option>-P</option></term>
-      <term><option>--progress</option></term>
+      <term><option>-v</option></term>
+      <term><option>--verbose</option></term>
       <listitem>
        <para>
-        Enable progress reporting. Turning this on will deliver a progress
-        report while checking or enabling checksums.
+        Enable verbose output. Lists all checked files.
        </para>
       </listitem>
      </varlistentry>
index 16cf52a3408e3e68d4210895124d853f5f464b88..1d75aa0282cc232d08b077d64bc8fd1f04835785 100644 (file)
@@ -36,7 +36,7 @@ static int64 blocks = 0;
 static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
-static char *only_relfilenode = NULL;
+static char *only_filenode = NULL;
 static bool do_sync = true;
 static bool verbose = false;
 static bool showprogress = false;
@@ -76,16 +76,16 @@ usage(void)
        printf(_("Usage:\n"));
        printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
        printf(_("\nOptions:\n"));
-       printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-       printf(_("  -c, --check            check data checksums (default)\n"));
-       printf(_("  -d, --disable          disable 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(_("  -P, --progress         show progress information\n"));
-       printf(_("  -v, --verbose          output verbose messages\n"));
-       printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
-       printf(_("  -V, --version          output version information, then exit\n"));
-       printf(_("  -?, --help             show this help, then exit\n"));
+       printf(_(" [-D, --pgdata=]DATADIR    data directory\n"));
+       printf(_("  -c, --check              check data checksums (default)\n"));
+       printf(_("  -d, --disable            disable data checksums\n"));
+       printf(_("  -e, --enable             enable data checksums\n"));
+       printf(_("  -f, --filenode=FILENODE  check only relation with specified filenode\n"));
+       printf(_("  -N, --no-sync            do not wait for changes to be written safely to disk\n"));
+       printf(_("  -P, --progress           show progress information\n"));
+       printf(_("  -v, --verbose            output verbose messages\n"));
+       printf(_("  -V, --version            output version information, then exit\n"));
+       printf(_("  -?, --help               show this help, then exit\n"));
        printf(_("\nIf no data directory (DATADIR) is specified, "
                         "the environment variable PGDATA\nis used.\n\n"));
        printf(_("Report bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
@@ -318,7 +318,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
                        /*
                         * Cut off at the segment boundary (".") to get the segment number
                         * in order to mix it into the checksum. Then also cut off at the
-                        * fork boundary, to get the relfilenode the file belongs to for
+                        * fork boundary, to get the filenode the file belongs to for
                         * filtering.
                         */
                        strlcpy(fnonly, de->d_name, sizeof(fnonly));
@@ -339,8 +339,8 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
                        if (forkpath != NULL)
                                *forkpath++ = '\0';
 
-                       if (only_relfilenode && strcmp(only_relfilenode, fnonly) != 0)
-                               /* Relfilenode not to be included */
+                       if (only_filenode && strcmp(only_filenode, fnonly) != 0)
+                               /* filenode not to be included */
                                continue;
 
                        dirsize += st.st_size;
@@ -371,6 +371,7 @@ main(int argc, char *argv[])
                {"pgdata", required_argument, NULL, 'D'},
                {"disable", no_argument, NULL, 'd'},
                {"enable", no_argument, NULL, 'e'},
+               {"filenode", required_argument, NULL, 'f'},
                {"no-sync", no_argument, NULL, 'N'},
                {"progress", no_argument, NULL, 'P'},
                {"verbose", no_argument, NULL, 'v'},
@@ -400,7 +401,7 @@ main(int argc, char *argv[])
                }
        }
 
-       while ((c = getopt_long(argc, argv, "cD:deNPr:v", long_options, &option_index)) != -1)
+       while ((c = getopt_long(argc, argv, "cD:deNPf:v", long_options, &option_index)) != -1)
        {
                switch (c)
                {
@@ -413,6 +414,14 @@ main(int argc, char *argv[])
                        case 'e':
                                mode = PG_MODE_ENABLE;
                                break;
+                       case 'f':
+                               if (atoi(optarg) == 0)
+                               {
+                                       pg_log_error("invalid filenode specification, must be numeric: %s", optarg);
+                                       exit(1);
+                               }
+                               only_filenode = pstrdup(optarg);
+                               break;
                        case 'N':
                                do_sync = false;
                                break;
@@ -422,14 +431,6 @@ main(int argc, char *argv[])
                        case 'D':
                                DataDir = optarg;
                                break;
-                       case 'r':
-                               if (atoi(optarg) == 0)
-                               {
-                                       pg_log_error("invalid relfilenode specification, must be numeric: %s", optarg);
-                                       exit(1);
-                               }
-                               only_relfilenode = pstrdup(optarg);
-                               break;
                        case 'P':
                                showprogress = true;
                                break;
@@ -465,10 +466,10 @@ main(int argc, char *argv[])
                exit(1);
        }
 
-       /* Relfilenode checking only works in --check mode */
-       if (mode != PG_MODE_CHECK && only_relfilenode)
+       /* filenode checking only works in --check mode */
+       if (mode != PG_MODE_CHECK && only_filenode)
        {
-               pg_log_error("relfilenode option only possible with --check");
+               pg_log_error("--filenode option only possible with --check");
                fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
                                progname);
                exit(1);
index a8f45a268a6f361a1ea9b53c60bc8aee0ce35d5d..ce24d06a10769b23d2e3f54003d5a2a5489dcdae 100644 (file)
@@ -43,7 +43,7 @@ sub check_relation_corruption
                [
                        'pg_checksums', '--check',
                        '-D',           $pgdata,
-                       '-r',           $relfilenode_corrupted
+                       '--filenode',   $relfilenode_corrupted
                ],
                "succeeds for single relfilenode on tablespace $tablespace with offline cluster"
        );
@@ -59,7 +59,7 @@ sub check_relation_corruption
                [
                        'pg_checksums', '--check',
                        '-D',           $pgdata,
-                       '-r',           $relfilenode_corrupted
+                       '--filenode',   $relfilenode_corrupted
                ],
                1,
                [qr/Bad checksums:.*1/],
@@ -165,10 +165,10 @@ command_ok(
 # Specific relation files cannot be requested when action is --disable
 # or --enable.
 command_fails(
-       [ 'pg_checksums', '--disable', '-r', '1234', '-D', $pgdata ],
+       [ 'pg_checksums', '--disable', '--filenode', '1234', '-D', $pgdata ],
        "fails when relfilenodes are requested and action is --disable");
 command_fails(
-       [ 'pg_checksums', '--enable', '-r', '1234', '-D', $pgdata ],
+       [ 'pg_checksums', '--enable', '--filenode', '1234', '-D', $pgdata ],
        "fails when relfilenodes are requested and action is --enable");
 
 # Checks cannot happen with an online cluster