Skip to content

Commit fc115d0

Browse files
committed
Rework options of pg_checksums options for filenode handling
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
1 parent 13002bf commit fc115d0

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

doc/src/sgml/ref/pg_checksums.sgml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ PostgreSQL documentation
100100
</listitem>
101101
</varlistentry>
102102

103+
<varlistentry>
104+
<term><option>-f <replaceable>filenode</replaceable></option></term>
105+
<term><option>--filenode=<replaceable>filenode</replaceable></option></term>
106+
<listitem>
107+
<para>
108+
Only validate checksums in the relation with filenode
109+
<replaceable>filenode</replaceable>.
110+
</para>
111+
</listitem>
112+
</varlistentry>
113+
103114
<varlistentry>
104115
<term><option>-N</option></term>
105116
<term><option>--no-sync</option></term>
@@ -117,31 +128,22 @@ PostgreSQL documentation
117128
</varlistentry>
118129

119130
<varlistentry>
120-
<term><option>-v</option></term>
121-
<term><option>--verbose</option></term>
122-
<listitem>
123-
<para>
124-
Enable verbose output. Lists all checked files.
125-
</para>
126-
</listitem>
127-
</varlistentry>
128-
129-
<varlistentry>
130-
<term><option>-r <replaceable>relfilenode</replaceable></option></term>
131+
<term><option>-P</option></term>
132+
<term><option>--progress</option></term>
131133
<listitem>
132134
<para>
133-
Only validate checksums in the relation with specified relfilenode.
135+
Enable progress reporting. Turning this on will deliver a progress
136+
report while checking or enabling checksums.
134137
</para>
135138
</listitem>
136139
</varlistentry>
137140

138141
<varlistentry>
139-
<term><option>-P</option></term>
140-
<term><option>--progress</option></term>
142+
<term><option>-v</option></term>
143+
<term><option>--verbose</option></term>
141144
<listitem>
142145
<para>
143-
Enable progress reporting. Turning this on will deliver a progress
144-
report while checking or enabling checksums.
146+
Enable verbose output. Lists all checked files.
145147
</para>
146148
</listitem>
147149
</varlistentry>

src/bin/pg_checksums/pg_checksums.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int64 blocks = 0;
3636
static int64 badblocks = 0;
3737
static ControlFileData *ControlFile;
3838

39-
static char *only_relfilenode = NULL;
39+
static char *only_filenode = NULL;
4040
static bool do_sync = true;
4141
static bool verbose = false;
4242
static bool showprogress = false;
@@ -76,16 +76,16 @@ usage(void)
7676
printf(_("Usage:\n"));
7777
printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
7878
printf(_("\nOptions:\n"));
79-
printf(_(" [-D, --pgdata=]DATADIR data directory\n"));
80-
printf(_(" -c, --check check data checksums (default)\n"));
81-
printf(_(" -d, --disable disable data checksums\n"));
82-
printf(_(" -e, --enable enable data checksums\n"));
83-
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
84-
printf(_(" -P, --progress show progress information\n"));
85-
printf(_(" -v, --verbose output verbose messages\n"));
86-
printf(_(" -r RELFILENODE check only relation with specified relfilenode\n"));
87-
printf(_(" -V, --version output version information, then exit\n"));
88-
printf(_(" -?, --help show this help, then exit\n"));
79+
printf(_(" [-D, --pgdata=]DATADIR data directory\n"));
80+
printf(_(" -c, --check check data checksums (default)\n"));
81+
printf(_(" -d, --disable disable data checksums\n"));
82+
printf(_(" -e, --enable enable data checksums\n"));
83+
printf(_(" -f, --filenode=FILENODE check only relation with specified filenode\n"));
84+
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
85+
printf(_(" -P, --progress show progress information\n"));
86+
printf(_(" -v, --verbose output verbose messages\n"));
87+
printf(_(" -V, --version output version information, then exit\n"));
88+
printf(_(" -?, --help show this help, then exit\n"));
8989
printf(_("\nIf no data directory (DATADIR) is specified, "
9090
"the environment variable PGDATA\nis used.\n\n"));
9191
printf(_("Report bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
@@ -318,7 +318,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
318318
/*
319319
* Cut off at the segment boundary (".") to get the segment number
320320
* in order to mix it into the checksum. Then also cut off at the
321-
* fork boundary, to get the relfilenode the file belongs to for
321+
* fork boundary, to get the filenode the file belongs to for
322322
* filtering.
323323
*/
324324
strlcpy(fnonly, de->d_name, sizeof(fnonly));
@@ -339,8 +339,8 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
339339
if (forkpath != NULL)
340340
*forkpath++ = '\0';
341341

342-
if (only_relfilenode && strcmp(only_relfilenode, fnonly) != 0)
343-
/* Relfilenode not to be included */
342+
if (only_filenode && strcmp(only_filenode, fnonly) != 0)
343+
/* filenode not to be included */
344344
continue;
345345

346346
dirsize += st.st_size;
@@ -371,6 +371,7 @@ main(int argc, char *argv[])
371371
{"pgdata", required_argument, NULL, 'D'},
372372
{"disable", no_argument, NULL, 'd'},
373373
{"enable", no_argument, NULL, 'e'},
374+
{"filenode", required_argument, NULL, 'f'},
374375
{"no-sync", no_argument, NULL, 'N'},
375376
{"progress", no_argument, NULL, 'P'},
376377
{"verbose", no_argument, NULL, 'v'},
@@ -400,7 +401,7 @@ main(int argc, char *argv[])
400401
}
401402
}
402403

403-
while ((c = getopt_long(argc, argv, "cD:deNPr:v", long_options, &option_index)) != -1)
404+
while ((c = getopt_long(argc, argv, "cD:deNPf:v", long_options, &option_index)) != -1)
404405
{
405406
switch (c)
406407
{
@@ -413,6 +414,14 @@ main(int argc, char *argv[])
413414
case 'e':
414415
mode = PG_MODE_ENABLE;
415416
break;
417+
case 'f':
418+
if (atoi(optarg) == 0)
419+
{
420+
pg_log_error("invalid filenode specification, must be numeric: %s", optarg);
421+
exit(1);
422+
}
423+
only_filenode = pstrdup(optarg);
424+
break;
416425
case 'N':
417426
do_sync = false;
418427
break;
@@ -422,14 +431,6 @@ main(int argc, char *argv[])
422431
case 'D':
423432
DataDir = optarg;
424433
break;
425-
case 'r':
426-
if (atoi(optarg) == 0)
427-
{
428-
pg_log_error("invalid relfilenode specification, must be numeric: %s", optarg);
429-
exit(1);
430-
}
431-
only_relfilenode = pstrdup(optarg);
432-
break;
433434
case 'P':
434435
showprogress = true;
435436
break;
@@ -465,10 +466,10 @@ main(int argc, char *argv[])
465466
exit(1);
466467
}
467468

468-
/* Relfilenode checking only works in --check mode */
469-
if (mode != PG_MODE_CHECK && only_relfilenode)
469+
/* filenode checking only works in --check mode */
470+
if (mode != PG_MODE_CHECK && only_filenode)
470471
{
471-
pg_log_error("relfilenode option only possible with --check");
472+
pg_log_error("--filenode option only possible with --check");
472473
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
473474
progname);
474475
exit(1);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ sub check_relation_corruption
4343
[
4444
'pg_checksums', '--check',
4545
'-D', $pgdata,
46-
'-r', $relfilenode_corrupted
46+
'--filenode', $relfilenode_corrupted
4747
],
4848
"succeeds for single relfilenode on tablespace $tablespace with offline cluster"
4949
);
@@ -59,7 +59,7 @@ sub check_relation_corruption
5959
[
6060
'pg_checksums', '--check',
6161
'-D', $pgdata,
62-
'-r', $relfilenode_corrupted
62+
'--filenode', $relfilenode_corrupted
6363
],
6464
1,
6565
[qr/Bad checksums:.*1/],
@@ -165,10 +165,10 @@ sub check_relation_corruption
165165
# Specific relation files cannot be requested when action is --disable
166166
# or --enable.
167167
command_fails(
168-
[ 'pg_checksums', '--disable', '-r', '1234', '-D', $pgdata ],
168+
[ 'pg_checksums', '--disable', '--filenode', '1234', '-D', $pgdata ],
169169
"fails when relfilenodes are requested and action is --disable");
170170
command_fails(
171-
[ 'pg_checksums', '--enable', '-r', '1234', '-D', $pgdata ],
171+
[ 'pg_checksums', '--enable', '--filenode', '1234', '-D', $pgdata ],
172172
"fails when relfilenodes are requested and action is --enable");
173173

174174
# Checks cannot happen with an online cluster

0 commit comments

Comments
 (0)