Skip to content

Commit ac44367

Browse files
committed
pg_waldump: Add a --quiet option.
The primary motivation for this change is that it will be used by the upcoming patch to add backup manifests, but it also seems to have some potential more general use. Andres Freund and Robert Haas Discussion: http://postgr.es/m/[email protected]
1 parent 7cb0a42 commit ac44367

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

doc/src/sgml/ref/pg_waldump.sgml

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ PostgreSQL documentation
125125
</listitem>
126126
</varlistentry>
127127

128+
<varlistentry>
129+
<term><option>-q</option></term>
130+
<term><option>--quiet</option></term>
131+
<listitem>
132+
<para>
133+
Do not print any output, except for errors. This option can be useful
134+
when you want to know whether a range of WAL records can be
135+
successfully parsed but don't care about the record contents.
136+
</para>
137+
</listitem>
138+
</varlistentry>
139+
128140
<varlistentry>
129141
<term><option>-r <replaceable>rmgr</replaceable></option></term>
130142
<term><option>--rmgr=<replaceable>rmgr</replaceable></option></term>

src/bin/pg_waldump/pg_waldump.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct XLogDumpPrivate
4040
typedef struct XLogDumpConfig
4141
{
4242
/* display options */
43+
bool quiet;
4344
bool bkp_details;
4445
int stop_after_records;
4546
int already_displayed_records;
@@ -720,6 +721,7 @@ usage(void)
720721
printf(_(" -p, --path=PATH directory in which to find log segment files or a\n"
721722
" directory with a ./pg_wal that contains such files\n"
722723
" (default: current directory, ./pg_wal, $PGDATA/pg_wal)\n"));
724+
printf(_(" -q, --quiet do not print any output, except for errors\n"));
723725
printf(_(" -r, --rmgr=RMGR only show records generated by resource manager RMGR;\n"
724726
" use --rmgr=list to list valid resource manager names\n"));
725727
printf(_(" -s, --start=RECPTR start reading at WAL location RECPTR\n"));
@@ -755,6 +757,7 @@ main(int argc, char **argv)
755757
{"help", no_argument, NULL, '?'},
756758
{"limit", required_argument, NULL, 'n'},
757759
{"path", required_argument, NULL, 'p'},
760+
{"quiet", no_argument, NULL, 'q'},
758761
{"rmgr", required_argument, NULL, 'r'},
759762
{"start", required_argument, NULL, 's'},
760763
{"timeline", required_argument, NULL, 't'},
@@ -794,6 +797,7 @@ main(int argc, char **argv)
794797
private.endptr = InvalidXLogRecPtr;
795798
private.endptr_reached = false;
796799

800+
config.quiet = false;
797801
config.bkp_details = false;
798802
config.stop_after_records = -1;
799803
config.already_displayed_records = 0;
@@ -810,7 +814,7 @@ main(int argc, char **argv)
810814
goto bad_argument;
811815
}
812816

813-
while ((option = getopt_long(argc, argv, "be:fn:p:r:s:t:x:z",
817+
while ((option = getopt_long(argc, argv, "be:fn:p:qr:s:t:x:z",
814818
long_options, &optindex)) != -1)
815819
{
816820
switch (option)
@@ -840,6 +844,9 @@ main(int argc, char **argv)
840844
case 'p':
841845
waldir = pg_strdup(optarg);
842846
break;
847+
case 'q':
848+
config.quiet = true;
849+
break;
843850
case 'r':
844851
{
845852
int i;
@@ -1075,11 +1082,14 @@ main(int argc, char **argv)
10751082
config.filter_by_xid != record->xl_xid)
10761083
continue;
10771084

1078-
/* process the record */
1079-
if (config.stats == true)
1080-
XLogDumpCountRecord(&config, &stats, xlogreader_state);
1081-
else
1082-
XLogDumpDisplayRecord(&config, xlogreader_state);
1085+
/* perform any per-record work */
1086+
if (!config.quiet)
1087+
{
1088+
if (config.stats == true)
1089+
XLogDumpCountRecord(&config, &stats, xlogreader_state);
1090+
else
1091+
XLogDumpDisplayRecord(&config, xlogreader_state);
1092+
}
10831093

10841094
/* check whether we printed enough */
10851095
config.already_displayed_records++;

0 commit comments

Comments
 (0)