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.
From 79060adc6db3e38c1935426145115c9eed39d85f 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] 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  | 20 +++++++++++++-------
 2 files changed, 17 insertions(+), 11 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..e878c90803 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,13 +968,19 @@ main(int argc, char **argv)
 				break;
 			case 'F':
 				{
-					unsigned int forknum;
+					int			forknum = InvalidForkNumber;
 
-					if (sscanf(optarg, "%u", &forknum) != 1 ||
-						forknum > MAX_FORKNUM)
+					for (int i = 0; i <= MAX_FORKNUM; ++i)
 					{
-						pg_log_error("could not parse valid fork number (0..%d) \"%s\"",
-									 MAX_FORKNUM, optarg);
+						if (strcmp(optarg, forkNames[i]) == 0)
+						{
+							forknum = i;
+							break;
+						}
+					}
+					if (forknum == InvalidForkNumber)
+					{
+						pg_log_error("could not parse fork \"%s\"", optarg);
 						goto bad_argument;
 					}
 					config.filter_by_relation_forknum = (ForkNumber) forknum;
-- 
2.30.2

Reply via email to