On Fri, Mar 25, 2022 at 12:26 AM Thomas Munro <thomas.mu...@gmail.com> wrote:
> On Fri, Mar 25, 2022 at 12:01 AM Peter Eisentraut
> <peter.eisentr...@enterprisedb.com> wrote:
> > Or even:  Why are we exposing fork *numbers* in the user interface?
> > Even low-level tools such as pageinspect use fork *names* in their
> > interface.
>
> I wondered about that but thought it seemed OK for such a low level
> tool.  It's a fair point though, especially if other low level tools
> are doing that.  Here's a patch to change it.

Oh, and there's already a name lookup function to use for this.
From e276c28414645022ead3f33e6a6bc11ae0479496 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.mu...@gmail.com>
Date: Fri, 25 Mar 2022 00:22:01 +1300
Subject: [PATCH v2] Use fork names, not numbers, in pg_waldump option.

Improvement for commit 127aea2a.

Suggested-by: Peter Eisentraut <peter.eisentr...@enterprisedb.com>
Discussion: https://postgr.es/m/3a4c2e93-7976-2320-fc0a-32097fe148a7%40enterprisedb.com
---
 doc/src/sgml/ref/pg_waldump.sgml |  8 ++++----
 src/bin/pg_waldump/pg_waldump.c  | 15 +++++++--------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/doc/src/sgml/ref/pg_waldump.sgml b/doc/src/sgml/ref/pg_waldump.sgml
index 981d3c9038..9e1b91683d 100644
--- a/doc/src/sgml/ref/pg_waldump.sgml
+++ b/doc/src/sgml/ref/pg_waldump.sgml
@@ -118,10 +118,10 @@ PostgreSQL documentation
       <listitem>
        <para>
         If provided, only display records that modify blocks in the given fork.
-        The valid values are <literal>0</literal> for the main fork,
-        <literal>1</literal> for the free space map,
-        <literal>2</literal> for the visibility map,
-        and <literal>3</literal> for the init fork.
+        The valid values are <literal>main</literal> for the main fork,
+        <literal>fsm</literal> for the free space map,
+        <literal>vm</literal> for the visibility map,
+        and <literal>init</literal> for the init fork.
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index 92238f30c9..bb6b7576fd 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -828,8 +828,8 @@ usage(void)
 	printf(_("  -e, --end=RECPTR       stop reading at WAL location RECPTR\n"));
 	printf(_("  -f, --follow           keep retrying after reaching end of WAL\n"));
 	printf(_("  -k, --block=N          with --relation, only show records matching this block\n"));
-	printf(_("  -F, --fork=N           only show records matching a specific fork number\n"
-			 "                         (defaults to showing all)\n"));
+	printf(_("  -F, --fork=FORK        only show records matching a specific fork;\n"
+			 "                         valid fork names are main, fsm, vm, init\n"));
 	printf(_("  -l, --relation=N/N/N   only show records that affect a specific relation\n"));
 	printf(_("  -n, --limit=N          number of records to display\n"));
 	printf(_("  -p, --path=PATH        directory in which to find log segment files or a\n"
@@ -968,16 +968,15 @@ main(int argc, char **argv)
 				break;
 			case 'F':
 				{
-					unsigned int forknum;
+					ForkNumber	forknum;
 
-					if (sscanf(optarg, "%u", &forknum) != 1 ||
-						forknum > MAX_FORKNUM)
+					forknum = forkname_to_number(optarg);
+					if (forknum == InvalidForkNumber)
 					{
-						pg_log_error("could not parse valid fork number (0..%d) \"%s\"",
-									 MAX_FORKNUM, optarg);
+						pg_log_error("could not parse fork \"%s\"", optarg);
 						goto bad_argument;
 					}
-					config.filter_by_relation_forknum = (ForkNumber) forknum;
+					config.filter_by_relation_forknum = forknum;
 					config.filter_by_extended = true;
 				}
 				break;
-- 
2.30.2

Reply via email to