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

Commit 52b5568

Browse files
committed
Improve command line options for pg_waldump.
Follow-up improvements for commit 127aea2 based on discussion: * use fork name for --fork, not number * use -R, -B as short switches for --relation, --block * re-alphabetize the list of switches (code, --help and docs) Suggested-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> (fork name part) Reviewed-by: David Christensen <david.christensen@crunchydata.com> Reviewed-by: Japin Li <japinli@hotmail.com> Discussion: https://postgr.es/m/3a4c2e93-7976-2320-fc0a-32097fe148a7%40enterprisedb.com
1 parent f28bf66 commit 52b5568

File tree

2 files changed

+66
-72
lines changed

2 files changed

+66
-72
lines changed

doc/src/sgml/ref/pg_waldump.sgml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ PostgreSQL documentation
7878
</listitem>
7979
</varlistentry>
8080

81+
<varlistentry>
82+
<term><option>-B <replaceable>block</replaceable></option></term>
83+
<term><option>--block=<replaceable>block</replaceable></option></term>
84+
<listitem>
85+
<para>
86+
Only display records that modify the given block. The relation must
87+
also be provided with <option>--relation</option> or
88+
<option>-l</option>.
89+
</para>
90+
</listitem>
91+
</varlistentry>
92+
8193
<varlistentry>
8294
<term><option>-e <replaceable>end</replaceable></option></term>
8395
<term><option>--end=<replaceable>end</replaceable></option></term>
@@ -100,41 +112,16 @@ PostgreSQL documentation
100112
</listitem>
101113
</varlistentry>
102114

103-
<varlistentry>
104-
<term><option>-k <replaceable>block</replaceable></option></term>
105-
<term><option>--block=<replaceable>block</replaceable></option></term>
106-
<listitem>
107-
<para>
108-
Only display records that modify the given block. The relation must
109-
also be provided with <option>--relation</option> or
110-
<option>-l</option>.
111-
</para>
112-
</listitem>
113-
</varlistentry>
114-
115115
<varlistentry>
116116
<term><option>-F <replaceable>fork</replaceable></option></term>
117117
<term><option>--fork=<replaceable>fork</replaceable></option></term>
118118
<listitem>
119119
<para>
120120
If provided, only display records that modify blocks in the given fork.
121-
The valid values are <literal>0</literal> for the main fork,
122-
<literal>1</literal> for the free space map,
123-
<literal>2</literal> for the visibility map,
124-
and <literal>3</literal> for the init fork.
125-
</para>
126-
</listitem>
127-
</varlistentry>
128-
129-
<varlistentry>
130-
<term><option>-l <replaceable>tblspc</replaceable>/<replaceable>db</replaceable>/<replaceable>rel</replaceable></option></term>
131-
<term><option>--relation=<replaceable>tblspc</replaceable>/<replaceable>db</replaceable>/<replaceable>rel</replaceable></option></term>
132-
<listitem>
133-
<para>
134-
Only display records that modify blocks in the given relation. The
135-
relation is specified with tablespace OID, database OID, and relfilenode
136-
separated by slashes, for example <literal>1234/12345/12345</literal>.
137-
This is the same format used for relations in the program's output.
121+
The valid values are <literal>main</literal> for the main fork,
122+
<literal>fsm</literal> for the free space map,
123+
<literal>vm</literal> for the visibility map,
124+
and <literal>init</literal> for the init fork.
138125
</para>
139126
</listitem>
140127
</varlistentry>
@@ -189,6 +176,19 @@ PostgreSQL documentation
189176
</listitem>
190177
</varlistentry>
191178

179+
<varlistentry>
180+
<term><option>-R <replaceable>tblspc</replaceable>/<replaceable>db</replaceable>/<replaceable>rel</replaceable></option></term>
181+
<term><option>--relation=<replaceable>tblspc</replaceable>/<replaceable>db</replaceable>/<replaceable>rel</replaceable></option></term>
182+
<listitem>
183+
<para>
184+
Only display records that modify blocks in the given relation. The
185+
relation is specified with tablespace OID, database OID, and relfilenode
186+
separated by slashes, for example <literal>1234/12345/12345</literal>.
187+
This is the same format used for relations in the program's output.
188+
</para>
189+
</listitem>
190+
</varlistentry>
191+
192192
<varlistentry>
193193
<term><option>-s <replaceable>start</replaceable></option></term>
194194
<term><option>--start=<replaceable>start</replaceable></option></term>

src/bin/pg_waldump/pg_waldump.c

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -825,25 +825,25 @@ usage(void)
825825
printf(_(" %s [OPTION]... [STARTSEG [ENDSEG]]\n"), progname);
826826
printf(_("\nOptions:\n"));
827827
printf(_(" -b, --bkp-details output detailed information about backup blocks\n"));
828+
printf(_(" -B, --block=N with --relation, only show records that modify block N\n"));
828829
printf(_(" -e, --end=RECPTR stop reading at WAL location RECPTR\n"));
829830
printf(_(" -f, --follow keep retrying after reaching end of WAL\n"));
830-
printf(_(" -k, --block=N with --relation, only show records matching this block\n"));
831-
printf(_(" -F, --fork=N only show records matching a specific fork number\n"
832-
" (defaults to showing all)\n"));
833-
printf(_(" -l, --relation=N/N/N only show records that affect a specific relation\n"));
831+
printf(_(" -F, --fork=FORK only show records that modify blocks in fork FORK;\n"
832+
" valid names are main, fsm, vm, init\n"));
834833
printf(_(" -n, --limit=N number of records to display\n"));
835834
printf(_(" -p, --path=PATH directory in which to find log segment files or a\n"
836835
" directory with a ./pg_wal that contains such files\n"
837836
" (default: current directory, ./pg_wal, $PGDATA/pg_wal)\n"));
838837
printf(_(" -q, --quiet do not print any output, except for errors\n"));
839838
printf(_(" -r, --rmgr=RMGR only show records generated by resource manager RMGR;\n"
840839
" use --rmgr=list to list valid resource manager names\n"));
840+
printf(_(" -R, --relation=T/D/R only show records that modify blocks in relation T/D/R\n"));
841841
printf(_(" -s, --start=RECPTR start reading at WAL location RECPTR\n"));
842842
printf(_(" -t, --timeline=TLI timeline from which to read log records\n"
843843
" (default: 1 or the value used in STARTSEG)\n"));
844844
printf(_(" -V, --version output version information, then exit\n"));
845-
printf(_(" -x, --xid=XID only show records with transaction ID XID\n"));
846845
printf(_(" -w, --fullpage only show records with a full page write\n"));
846+
printf(_(" -x, --xid=XID only show records with transaction ID XID\n"));
847847
printf(_(" -z, --stats[=record] show statistics instead of records\n"
848848
" (optionally, show per-record statistics)\n"));
849849
printf(_(" -?, --help show this help, then exit\n"));
@@ -867,7 +867,7 @@ main(int argc, char **argv)
867867

868868
static struct option long_options[] = {
869869
{"bkp-details", no_argument, NULL, 'b'},
870-
{"block", required_argument, NULL, 'k'},
870+
{"block", required_argument, NULL, 'B'},
871871
{"end", required_argument, NULL, 'e'},
872872
{"follow", no_argument, NULL, 'f'},
873873
{"fork", required_argument, NULL, 'F'},
@@ -876,7 +876,7 @@ main(int argc, char **argv)
876876
{"limit", required_argument, NULL, 'n'},
877877
{"path", required_argument, NULL, 'p'},
878878
{"quiet", no_argument, NULL, 'q'},
879-
{"relation", required_argument, NULL, 'l'},
879+
{"relation", required_argument, NULL, 'R'},
880880
{"rmgr", required_argument, NULL, 'r'},
881881
{"start", required_argument, NULL, 's'},
882882
{"timeline", required_argument, NULL, 't'},
@@ -946,14 +946,24 @@ main(int argc, char **argv)
946946
goto bad_argument;
947947
}
948948

949-
while ((option = getopt_long(argc, argv, "be:fF:k:l:n:p:qr:s:t:wx:z",
949+
while ((option = getopt_long(argc, argv, "bB:e:fF:n:p:qr:R:s:t:wx:z",
950950
long_options, &optindex)) != -1)
951951
{
952952
switch (option)
953953
{
954954
case 'b':
955955
config.bkp_details = true;
956956
break;
957+
case 'B':
958+
if (sscanf(optarg, "%u", &config.filter_by_relation_block) != 1 ||
959+
!BlockNumberIsValid(config.filter_by_relation_block))
960+
{
961+
pg_log_error("could not parse valid block number \"%s\"", optarg);
962+
goto bad_argument;
963+
}
964+
config.filter_by_relation_block_enabled = true;
965+
config.filter_by_extended = true;
966+
break;
957967
case 'e':
958968
if (sscanf(optarg, "%X/%X", &xlogid, &xrecoff) != 2)
959969
{
@@ -967,44 +977,12 @@ main(int argc, char **argv)
967977
config.follow = true;
968978
break;
969979
case 'F':
980+
config.filter_by_relation_forknum = forkname_to_number(optarg);
981+
if (config.filter_by_relation_forknum == InvalidForkNumber)
970982
{
971-
unsigned int forknum;
972-
973-
if (sscanf(optarg, "%u", &forknum) != 1 ||
974-
forknum > MAX_FORKNUM)
975-
{
976-
pg_log_error("could not parse valid fork number (0..%d) \"%s\"",
977-
MAX_FORKNUM, optarg);
978-
goto bad_argument;
979-
}
980-
config.filter_by_relation_forknum = (ForkNumber) forknum;
981-
config.filter_by_extended = true;
982-
}
983-
break;
984-
case 'k':
985-
if (sscanf(optarg, "%u", &config.filter_by_relation_block) != 1 ||
986-
!BlockNumberIsValid(config.filter_by_relation_block))
987-
{
988-
pg_log_error("could not parse valid block number \"%s\"", optarg);
989-
goto bad_argument;
990-
}
991-
config.filter_by_relation_block_enabled = true;
992-
config.filter_by_extended = true;
993-
break;
994-
case 'l':
995-
if (sscanf(optarg, "%u/%u/%u",
996-
&config.filter_by_relation.spcNode,
997-
&config.filter_by_relation.dbNode,
998-
&config.filter_by_relation.relNode) != 3 ||
999-
!OidIsValid(config.filter_by_relation.spcNode) ||
1000-
!OidIsValid(config.filter_by_relation.relNode))
1001-
{
1002-
pg_log_error("could not parse valid relation from \"%s\""
1003-
" (expecting \"tablespace OID/database OID/"
1004-
"relation filenode\")", optarg);
983+
pg_log_error("could not parse fork \"%s\"", optarg);
1005984
goto bad_argument;
1006985
}
1007-
config.filter_by_relation_enabled = true;
1008986
config.filter_by_extended = true;
1009987
break;
1010988
case 'n':
@@ -1047,6 +1025,22 @@ main(int argc, char **argv)
10471025
}
10481026
}
10491027
break;
1028+
case 'R':
1029+
if (sscanf(optarg, "%u/%u/%u",
1030+
&config.filter_by_relation.spcNode,
1031+
&config.filter_by_relation.dbNode,
1032+
&config.filter_by_relation.relNode) != 3 ||
1033+
!OidIsValid(config.filter_by_relation.spcNode) ||
1034+
!OidIsValid(config.filter_by_relation.relNode))
1035+
{
1036+
pg_log_error("could not parse valid relation from \"%s\""
1037+
" (expecting \"tablespace OID/database OID/"
1038+
"relation filenode\")", optarg);
1039+
goto bad_argument;
1040+
}
1041+
config.filter_by_relation_enabled = true;
1042+
config.filter_by_extended = true;
1043+
break;
10501044
case 's':
10511045
if (sscanf(optarg, "%X/%X", &xlogid, &xrecoff) != 2)
10521046
{

0 commit comments

Comments
 (0)