Subject: Re: WIP: new system catalog pg_wait_event

From: "Drouvot, Bertrand" <[email-masked]>
Date: Tue, 8 Aug 2023 07:37:42 +0200

Hi,

On 8/8/23 5:05 AM, Michael Paquier wrote:
> On Tue, Aug 08, 2023 at 11:53:32AM +0900, Kyotaro Horiguchi wrote:
>> As I mentioned in another thread, I'm uncertain about our stance on
>> the class id of the wait event. If a class acts as a namespace, we
>> should include it in the view. Otherwise, if the class id is just an
>> attribute of the wait event, we should make the event name unique.
> 
> Including the class name in the view makes the most sense to me, FWIW,
> as it could be also possible that one reuses an event name in the
> existing in-core list, but for extensions.  That's of course not
> something I would recommend.

Thanks Kyotaro-san and Michael for the feedback. I do agree and will
add the class name.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

---

From: "Drouvot, Bertrand" <[email-masked]>
Date: Tue, 8 Aug 2023 10:16:37 +0200

Hi,

> Thanks Kyotaro-san and Michael for the feedback. I do agree and will

Please find attached v3 adding the wait event types.

Regards,

From b54aa2dd33835a83bfe08a99338874200512fdf0 Mon Sep 17 00:00:00 2001
From: bdrouvotAWS <[email-masked]>
Date: Sat, 5 Aug 2023 12:39:42 +0000
Subject: [PATCH v3] pg_wait_event

Adding a new system view, namely pg_wait_event, that describes the wait events.
---
 doc/src/sgml/system-views.sgml                | 64 +++++++++++++++
 src/backend/catalog/system_views.sql          |  3 +
 src/backend/utils/activity/.gitignore         |  1 +
 src/backend/utils/activity/Makefile           |  6 +-
 .../activity/generate-wait_event_types.pl     | 77 +++++++++++++------
 src/backend/utils/activity/meson.build        |  1 +
 src/backend/utils/activity/pg_wait_event.c    | 41 ++++++++++
 src/include/catalog/pg_proc.dat               |  6 ++
 src/include/utils/meson.build                 |  4 +-
 src/test/regress/expected/rules.out           |  4 +
 src/test/regress/expected/sysviews.out        | 11 +++
 src/test/regress/sql/sysviews.sql             |  7 ++
 src/tools/msvc/clean.bat                      |  1 +
 13 files changed, 200 insertions(+), 26 deletions(-)
  21.6% doc/src/sgml/
  56.7% src/backend/utils/activity/
   5.2% src/include/catalog/
   7.4% src/test/regress/expected/
   4.0% src/test/regress/sql/
   4.9% src/

diff --git a/doc/src/sgml/system-views.sgml b/doc/src/sgml/system-views.sgml
index 57b228076e..ed26c8326f 100644
--- a/doc/src/sgml/system-views.sgml
+++ b/doc/src/sgml/system-views.sgml
@@ -221,6 +221,11 @@
       <entry>views</entry>
      </row>
 
+     <row>
+      <entry><link linkend="view-pg-wait-event"><structname>pg_wait_event</structname></link></entry>
+      <entry>wait events</entry>
+     </row>
+
     </tbody>
    </tgroup>
   </table>
@@ -4825,4 +4830,63 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
   </table>
  </sect1>
 
+
+ <sect1 id="view-pg-wait-event">
+  <title><structname>pg_wait_event</structname></title>
+
+  <indexterm zone="view-pg-wait-event">
+   <primary>pg_wait_event</primary>
+  </indexterm>
+
+  <para>
+   The view <structname>pg_wait_event</structname> provides description about the
+   wait events.
+  </para>
+
+  <table>
+   <title><structname>pg_wait_event</structname> Columns</title>
+   <tgroup cols="1">
+    <thead>
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       Column Type
+      </para>
+      <para>
+       Description
+      </para></entry>
+     </row>
+    </thead>
+
+    <tbody>
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>wait_event_type</structfield> <type>text</type>
+      </para>
+      <para>
+       Wait event type
+      </para></entry>
+     </row>
+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>wait_event_name</structfield> <type>text</type>
+      </para>
+      <para>
+       Wait event name
+      </para></entry>
+     </row>
+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>description</structfield> <type>texte</type>
+      </para>
+      <para>
+       Wait event description
+      </para></entry>
+     </row>
+    </tbody>
+   </tgroup>
+  </table>
+ </sect1>
+
 </chapter>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index af65af6bdd..f86a4dd770 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1342,3 +1342,6 @@ CREATE VIEW pg_stat_subscription_stats AS
         ss.stats_reset
     FROM pg_subscription as s,
          pg_stat_get_subscription_stats(s.oid) as ss;
+
+CREATE VIEW pg_wait_event AS
+    SELECT * FROM pg_get_wait_events() AS we;
diff --git a/src/backend/utils/activity/.gitignore b/src/backend/utils/activity/.gitignore
index d77079285b..ad089a0b63 100644
--- a/src/backend/utils/activity/.gitignore
+++ b/src/backend/utils/activity/.gitignore
@@ -1,2 +1,3 @@
 /pgstat_wait_event.c
 /wait_event_types.h
+/pg_wait_event_insert.c
diff --git a/src/backend/utils/activity/Makefile b/src/backend/utils/activity/Makefile
index f1117745d4..8595e6ea77 100644
--- a/src/backend/utils/activity/Makefile
+++ b/src/backend/utils/activity/Makefile
@@ -32,10 +32,14 @@ OBJS = \
 	pgstat_subscription.o \
 	pgstat_wal.o \
 	pgstat_xact.o \
+	pg_wait_event.o \
 	wait_event.o
 
 include $(top_srcdir)/src/backend/common.mk
 
+pg_wait_event.o: pg_wait_event_insert.c
+pg_wait_event_insert.c: wait_event_types.h
+
 wait_event.o: pgstat_wait_event.c
 pgstat_wait_event.c: wait_event_types.h
 	touch $@
@@ -44,4 +48,4 @@ wait_event_types.h: $(top_srcdir)/src/backend/utils/activity/wait_event_names.tx
 	$(PERL) $(srcdir)/generate-wait_event_types.pl --code $<
 
 maintainer-clean: clean
-	rm -f wait_event_types.h pgstat_wait_event.c
+	rm -f wait_event_types.h pgstat_wait_event.c pg_wait_event_insert.c
diff --git a/src/backend/utils/activity/generate-wait_event_types.pl b/src/backend/utils/activity/generate-wait_event_types.pl
index 56335e8730..c3f58acb4b 100644
--- a/src/backend/utils/activity/generate-wait_event_types.pl
+++ b/src/backend/utils/activity/generate-wait_event_types.pl
@@ -4,6 +4,7 @@
 # Generate wait events support files from wait_event_names.txt:
 # - wait_event_types.h (if --code is passed)
 # - pgstat_wait_event.c (if --code is passed)
+# - pg_wait_event_insert.c (if --code is passed)
 # - wait_event_types.sgml (if --docs is passed)
 #
 # Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
@@ -98,8 +99,10 @@ if ($gen_code)
 	# multiple times.
 	my $htmp = "$output_path/wait_event_types.h.tmp$$";
 	my $ctmp = "$output_path/pgstat_wait_event.c.tmp$$";
+	my $ictmp = "$output_path/pg_wait_event_insert.c.tmp$$";
 	open my $h, '>', $htmp or die "Could not open $htmp: $!";
 	open my $c, '>', $ctmp or die "Could not open $ctmp: $!";
+	open my $ic, '>', $ictmp or die "Could not open $ictmp: $!";
 
 	my $header_comment =
 	  '/*-------------------------------------------------------------------------
@@ -129,16 +132,17 @@ if ($gen_code)
 
 	printf $c $header_comment, 'pgstat_wait_event.c';
 
+	printf $ic $header_comment, 'pg_wait_event_insert.c';
+
 	# uc() is being used to force the comparison to be case-insensitive.
 	foreach my $waitclass (sort { uc($a) cmp uc($b) } keys %hashwe)
 	{
 
-		# Don't generate .c and .h files for Extension, LWLock and
-		# Lock, these are handled independently.
-		next
-		  if ( $waitclass eq 'WaitEventExtension'
-			|| $waitclass eq 'WaitEventLWLock'
-			|| $waitclass eq 'WaitEventLock');
+		# Don't generate .c (except pg_wait_event_insert.c) and .h files for
+		# Extension, LWLock and Lock, these are handled independently.
+		my $is_exception = $waitclass eq 'WaitEventExtension' ||
+						   $waitclass eq 'WaitEventLWLock' ||
+						   $waitclass eq 'WaitEventLock';
 
 		my $last = $waitclass;
 		$last =~ s/^WaitEvent//;
@@ -147,50 +151,77 @@ if ($gen_code)
 		my $firstpass = 1;
 		my $pg_wait_class;
 
-		printf $c
-		  "static const char *\npgstat_get_wait_$lastlc($waitclass w)\n{\n";
-		printf $c "\tconst char *event_name = \"unknown wait event\";\n\n";
-		printf $c "\tswitch (w)\n\t{\n";
+		if (!$is_exception)
+		{
+			printf $c
+			  "static const char *\npgstat_get_wait_$lastlc($waitclass w)\n{\n";
+			printf $c "\tconst char *event_name = \"unknown wait event\";\n\n";
+			printf $c "\tswitch (w)\n\t{\n";
+		}
 
 		foreach my $wev (@{ $hashwe{$waitclass} })
 		{
-			if ($firstpass)
+			if ($firstpass && !$is_exception)
 			{
 				printf $h "typedef enum\n{\n";
 				$pg_wait_class = "PG_WAIT_" . $lastuc;
 				printf $h "\t%s = %s", $wev->[0], $pg_wait_class;
 				$continue = ",\n";
 			}
-			else
+			elsif (!$is_exception)
 			{
 				printf $h "%s\t%s", $continue, $wev->[0];
 				$continue = ",\n";
 			}
-			$firstpass = 0;
 
-			printf $c "\t\t case %s:\n", $wev->[0];
-			# Apply quotes to the wait event name string.
-			printf $c "\t\t\t event_name = \"%s\";\n\t\t\t break;\n",
-			  $wev->[1];
+			if (!$is_exception)
+			{
+				$firstpass = 0;
+
+				printf $c "\t\t case %s:\n", $wev->[0];
+				# Apply quotes to the wait event name string.
+				printf $c "\t\t\t event_name = \"%s\";\n\t\t\t break;\n",
+				$wev->[1];
+			}
+
+			my $new_desc = substr $wev->[2], 1, -2;
+			$new_desc =~ s/'/\\'/g;
+			$new_desc =~ s/<.*>(.*?)<.*>/$1/g;
+			$new_desc =~ s/<xref linkend="guc-(.*?)"\/>/$1/g;
+			$new_desc =~ s/; see.*$//;
+
+			printf $ic "\tmemset(values, 0, sizeof(values));\n";
+			printf $ic "\tmemset(nulls, 0, sizeof(nulls));\n\n";
+			printf $ic "\tvalues[0] = CStringGetTextDatum(\"%s\");\n", $last;
+			printf $ic "\tvalues[1] = CStringGetTextDatum(\"%s\");\n", $wev->[1];
+			printf $ic "\tvalues[2] = CStringGetTextDatum(\"%s\");\n\n", $new_desc;
+
+			printf $ic "\ttuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);\n\n";
 		}
 
-		printf $h "\n} $waitclass;\n\n";
+		if (!$is_exception)
+		{
+			printf $h "\n} $waitclass;\n\n";
 
-		printf $c
-		  "\t\t\t /* no default case, so that compiler will warn */\n";
-		printf $c "\t}\n\n";
-		printf $c "\treturn event_name;\n";
-		printf $c "}\n\n";
+			printf $c
+			  "\t\t\t /* no default case, so that compiler will warn */\n";
+			printf $c "\t}\n\n";
+			printf $c "\treturn event_name;\n";
+			printf $c "}\n\n";
+		}
 	}
 
 	printf $h "#endif                          /* WAIT_EVENT_TYPES_H */\n";
 	close $h;
 	close $c;
+	close $ic;
 
 	rename($htmp, "$output_path/wait_event_types.h")
 	  || die "rename: $htmp to $output_path/wait_event_types.h: $!";
 	rename($ctmp, "$output_path/pgstat_wait_event.c")
 	  || die "rename: $ctmp to $output_path/pgstat_wait_event.c: $!";
+	rename($ictmp, "$output_path/pg_wait_event_insert.c")
+	  || die "rename: $ictmp to $output_path/pg_wait_event_insert.c: $!";
 }
 # Generate the .sgml file.
 elsif ($gen_docs)
diff --git a/src/backend/utils/activity/meson.build b/src/backend/utils/activity/meson.build
index 9633f3623c..774e0bd348 100644
--- a/src/backend/utils/activity/meson.build
+++ b/src/backend/utils/activity/meson.build
@@ -23,6 +23,7 @@ backend_sources += files(
 # seems nicer to not add that as an include path for the whole backend.
 waitevent_sources = files(
   'wait_event.c',
+  'pg_wait_event.c',
 )
 
 wait_event = static_library('wait_event_names',
diff --git a/src/backend/utils/activity/pg_wait_event.c b/src/backend/utils/activity/pg_wait_event.c
new file mode 100644
index 0000000000..e6bfe36d4d
--- /dev/null
+++ b/src/backend/utils/activity/pg_wait_event.c
@@ -0,0 +1,41 @@
+/* ----------
+ * pg_wait_event.c
+ *    Wait event reporting infrastructure.
+ *
+ * Copyright (c) 2001-2023, PostgreSQL Global Development Group
+ *
+ *
+ * IDENTIFICATION
+ *    src/backend/utils/activity/pg_wait_event.c
+ *
+ * NOTES
+ *
+ * The "pg_wait_event_insert.c" included in this file is generated by
+ *                    src/backend/utils/activity/generate-wait_event_types.pl
+ *
+ */
+#include "postgres.h"
+
+#include "funcapi.h"
+#include "utils/builtins.h"
+
+/*
+ * This function lists the wait events and their descriptions.
+ *
+ * The system view pg_wait_event provides a user interface to this
+ * SRF.
+ */
+Datum
+pg_get_wait_events(PG_FUNCTION_ARGS)
+{
+#define NUM_WAIT_EVENT_TABLES_ELEM 3
+	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
+	Datum       values[NUM_WAIT_EVENT_TABLES_ELEM];
+	bool        nulls[NUM_WAIT_EVENT_TABLES_ELEM];
+
+	/* Build tuplestore to hold the result rows */
+	InitMaterializedSRF(fcinfo, 0);
+
+	#include "pg_wait_event_insert.c"
+	return (Datum) 0;
+}
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 6996073989..6d10d2e5be 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5417,6 +5417,12 @@
   proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{pid,datid,pid,usesysid,application_name,state,query,wait_event_type,wait_event,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,backend_xid,backend_xmin,backend_type,ssl,sslversion,sslcipher,sslbits,ssl_client_dn,ssl_client_serial,ssl_issuer_dn,gss_auth,gss_princ,gss_enc,gss_delegation,leader_pid,query_id}',
   prosrc => 'pg_stat_get_activity' },
+{ oid => '8403', descr => 'describe wait events',
+  proname => 'pg_get_wait_events', procost => '10', prorows => '100',
+  proretset => 't', provolatile => 's', prorettype => 'record',
+  proargtypes => '', proallargtypes => '{text,text,text}',
+  proargmodes => '{o,o,o}', proargnames => '{wait_event_type,wait_event_name,description}',
+  prosrc => 'pg_get_wait_events' },
 { oid => '3318',
   descr => 'statistics: information about progress of backends running maintenance command',
   proname => 'pg_stat_get_progress_info', prorows => '100', proretset => 't',
diff --git a/src/include/utils/meson.build b/src/include/utils/meson.build
index 6de5d93799..4f14f770ef 100644
--- a/src/include/utils/meson.build
+++ b/src/include/utils/meson.build
@@ -1,6 +1,6 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-wait_event_output = ['wait_event_types.h', 'pgstat_wait_event.c']
+wait_event_output = ['wait_event_types.h', 'pgstat_wait_event.c', 'pg_wait_event_insert.c']
 wait_event_target = custom_target('wait_event_names',
   input: files('../../backend/utils/activity/wait_event_names.txt'),
   output: wait_event_output,
@@ -11,7 +11,7 @@ wait_event_target = custom_target('wait_event_names',
   ],
   build_by_default: true,
   install: true,
-  install_dir: [dir_include_server / 'utils', false],
+  install_dir: [dir_include_server / 'utils', false, false],
 )
 
 wait_event_types_h = wait_event_target[0]
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index e07afcd4aa..f160cb5642 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2631,6 +2631,10 @@ pg_views| SELECT n.nspname AS schemaname,
    FROM (pg_class c
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
   WHERE (c.relkind = 'v'::"char");
+pg_wait_event| SELECT wait_event_type,
+    wait_event_name,
+    description
+   FROM pg_get_wait_events() we(wait_event_type, wait_event_name, description);
 SELECT tablename, rulename, definition FROM pg_rules
 WHERE schemaname = 'pg_catalog'
 ORDER BY tablename, rulename;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 001c6e7eb9..bcf251c0c8 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -134,6 +134,17 @@ select name, setting from pg_settings where name like 'enable%';
  enable_tidscan                 | on
 (21 rows)
 
+-- There will surely be at least 9 wait event types, 240 wait events and at
+-- least 27 related to WAL
+select count(distinct(wait_event_type)) > 8 as ok_type,
+       count(*) > 239 as ok,
+       count(*) FILTER (WHERE description like '%WAL%') > 26 AS ok_wal_desc
+from pg_wait_event;
+ ok_type | ok | ok_wal_desc 
+---------+----+-------------
+ t       | t  | t
+(1 row)
+
 -- Test that the pg_timezone_names and pg_timezone_abbrevs views are
 -- more-or-less working.  We can't test their contents in any great detail
 -- without the outputs changing anytime IANA updates the underlying data,
diff --git a/src/test/regress/sql/sysviews.sql b/src/test/regress/sql/sysviews.sql
index 351e469c77..7a9dc6021d 100644
--- a/src/test/regress/sql/sysviews.sql
+++ b/src/test/regress/sql/sysviews.sql
@@ -55,6 +55,13 @@ select count(*) = 0 as ok from pg_stat_wal_receiver;
 -- a regression test run.
 select name, setting from pg_settings where name like 'enable%';
 
+-- There will surely be at least 9 wait event types, 240 wait events and at
+-- least 27 related to WAL
+select count(distinct(wait_event_type)) > 8 as ok_type,
+       count(*) > 239 as ok,
+       count(*) FILTER (WHERE description like '%WAL%') > 26 AS ok_wal_desc
+from pg_wait_event;
+
 -- Test that the pg_timezone_names and pg_timezone_abbrevs views are
 -- more-or-less working.  We can't test their contents in any great detail
 -- without the outputs changing anytime IANA updates the underlying data,
diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat
index 7cb23ea894..028d174d87 100755
--- a/src/tools/msvc/clean.bat
+++ b/src/tools/msvc/clean.bat
@@ -55,6 +55,7 @@ if exist src\include\catalog\header-stamp del /q src\include\catalog\header-stam
 if exist doc\src\sgml\version.sgml del /q doc\src\sgml\version.sgml
 
 if %DIST%==1 if exist src\backend\utils\activity\pgstat_wait_event.c del /q src\backend\utils\activity\pgstat_wait_event.c
+if %DIST%==1 if exist src\backend\utils\activity\pg_wait_event_insert.c del /q src\backend\utils\activity\pg_wait_event_insert.c
 if %DIST%==1 if exist src\backend\utils\activity\wait_event_types.h del /q src\backend\utils\activity\wait_event_types.h
 if %DIST%==1 if exist src\backend\utils\fmgroids.h del /q src\backend\utils\fmgroids.h
 if %DIST%==1 if exist src\backend\utils\fmgrprotos.h del /q src\backend\utils\fmgrprotos.h
-- 
2.34.1

---

From: Michael Paquier <[email-masked]>
Date: Wed, 9 Aug 2023 16:56:27 +0900

+-- There will surely be at least 9 wait event types, 240 wait events and at
+-- least 27 related to WAL
+select count(distinct(wait_event_type)) > 8 as ok_type,
+       count(*) > 239 as ok,
+       count(*) FILTER (WHERE description like '%WAL%') > 26 AS ok_wal_desc
+from pg_wait_event;
The point is to check the execution of this function, so this could be
simpler, like that or a GROUP BY clause with the event type:
SELECT count(*) > 0 FROM pg_wait_event;
SELECT wait_event_type, count(*) > 0 AS has_data FROM pg_wait_event
  GROUP BY wait_event_type ORDER BY wait_event_type;

That's overcomplicated for some code generated.  Wouldn't it be
simpler to generate a list of elements, with the code inserting the
tuples materialized looping over it?

Better to document what this does, the contents produced look good.

This could use a name referring to SQL functions, say
wait_event_funcs.c, with a wait_event_data.c or a
wait_event_funcs_data.c?

Perhaps it would be cleaner to use a separate loop?
--
Michael

---

From: "Drouvot, Bertrand" <[email-masked]>
Date: Thu, 10 Aug 2023 20:09:34 +0200

Hi,

>    GROUP BY wait_event_type ORDER BY wait_event_type;

Thanks for looking at it!
Right, so v4 attached is just testing "SELECT count(*) > 0 FROM pg_wait_event;",
that does look enough to test.

> tuples materialized looping over it?

Yeah, agree thanks!
In v4, the perl script now appends the wait events in a List that way:

"
             printf $ic "\telement = (wait_event_element *) palloc(sizeof(wait_event_element));\n";

             printf $ic "\telement->wait_event_type = \"%s\";\n", $last;
             printf $ic "\telement->wait_event_name = \"%s\";\n", $wev->[1];
             printf $ic "\telement->wait_event_description = \"%s\";\n\n", $new_desc;

             printf $ic "\twait_event = lappend(wait_event, element);\n\n";
"

And the C function pg_get_wait_events() now iterates over this List.

> Better to document what this does,

good idea...

I had to turn them "on" one by one to recall why they are there...;-)
Done in v4.

> the contents produced look good.

yeap

> wait_event_funcs.c, with a wait_event_data.c or a

That sounds better indeed, thanks! v4 is using wait_event_funcs.c and
wait_event_funcs_data.c.

> Perhaps it would be cleaner to use a separate loop?

Agree that's worth it given the fact that iterating one more time is not that
costly here.

Regards,

From aa3e81810daaba7b1b2e05219ef662f2fd0607f8 Mon Sep 17 00:00:00 2001
From: bdrouvotAWS <[email-masked]>
Date: Sat, 5 Aug 2023 12:39:42 +0000
Subject: [PATCH v4] pg_wait_event

Adding a new system view, namely pg_wait_event, that describes the wait events.
---
 doc/src/sgml/system-views.sgml                | 64 +++++++++++++++++
 src/backend/catalog/system_views.sql          |  3 +
 src/backend/utils/activity/.gitignore         |  1 +
 src/backend/utils/activity/Makefile           |  6 +-
 .../activity/generate-wait_event_types.pl     | 46 ++++++++++++-
 src/backend/utils/activity/meson.build        |  1 +
 src/backend/utils/activity/wait_event_funcs.c | 69 +++++++++++++++++++
 src/include/catalog/pg_proc.dat               |  6 ++
 src/include/utils/meson.build                 |  4 +-
 src/test/regress/expected/rules.out           |  4 ++
 src/test/regress/expected/sysviews.out        |  7 ++
 src/test/regress/sql/sysviews.sql             |  3 +
 src/tools/msvc/clean.bat                      |  1 +
 13 files changed, 209 insertions(+), 6 deletions(-)
  24.4% doc/src/sgml/
  58.5% src/backend/utils/activity/
   5.9% src/include/catalog/
   4.1% src/test/regress/expected/
   6.9% src/

+     <row>
 
+
index d77079285b..bd0c0c7772 100644
+/wait_event_funcs_data.c
index f1117745d4..289afe7c2d 100644
+	wait_event_funcs.o \
 	wait_event.o

+wait_event_funcs.o: wait_event_funcs_data.c
+wait_event_funcs_data.c: wait_event_types.h
+
 wait_event.o: pgstat_wait_event.c
 pgstat_wait_event.c: wait_event_types.h
 	touch $@
@@ -44,4 +48,4 @@ wait_event_types.h: $(top_srcdir)/src/backend/utils/activity/wait_event_names.tx
 	$(PERL) $(srcdir)/generate-wait_event_types.pl --code $<
 
 maintainer-clean: clean
-	rm -f wait_event_types.h pgstat_wait_event.c
+	rm -f wait_event_types.h pgstat_wait_event.c wait_event_funcs_data.c
diff --git a/src/backend/utils/activity/generate-wait_event_types.pl b/src/backend/utils/activity/generate-wait_event_types.pl
index 56335e8730..6f4fcd22d2 100644
--- a/src/backend/utils/activity/generate-wait_event_types.pl
+++ b/src/backend/utils/activity/generate-wait_event_types.pl
@@ -4,6 +4,7 @@
 # Generate wait events support files from wait_event_names.txt:
 # - wait_event_types.h (if --code is passed)
 # - pgstat_wait_event.c (if --code is passed)
+# - wait_event_funcs_data.c (if --code is passed)
 # - wait_event_types.sgml (if --docs is passed)
 #
 # Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
@@ -98,8 +99,10 @@ if ($gen_code)
 	# multiple times.
 	my $htmp = "$output_path/wait_event_types.h.tmp$$";
 	my $ctmp = "$output_path/pgstat_wait_event.c.tmp$$";
+	my $wctmp = "$output_path/wait_event_funcs_data.c.tmp$$";
 	open my $h, '>', $htmp or die "Could not open $htmp: $!";
 	open my $c, '>', $ctmp or die "Could not open $ctmp: $!";
+	open my $wc, '>', $wctmp or die "Could not open $wctmp: $!";
 
 	my $header_comment =
 	  '/*-------------------------------------------------------------------------
@@ -129,12 +132,14 @@ if ($gen_code)

+	printf $wc $header_comment, 'wait_event_funcs_data.c';
+
+	# Generate the pgstat_wait_event.c and wait_event_types.h files
 	# uc() is being used to force the comparison to be case-insensitive.
 	foreach my $waitclass (sort { uc($a) cmp uc($b) } keys %hashwe)
 	{
-
-		# Don't generate .c and .h files for Extension, LWLock and
-		# Lock, these are handled independently.
+		# Don't generate the pgstat_wait_event.c and wait_event_types.h files
+		# for Extension, LWLock and Lock, these are handled independently.
 		next
 		  if ( $waitclass eq 'WaitEventExtension'
 			|| $waitclass eq 'WaitEventLWLock'
@@ -183,14 +188,49 @@ if ($gen_code)
 		printf $c "}\n\n";
 	}
 
+	# Generate the wait_event_funcs_data.c file
+	# uc() is being used to force the comparison to be case-insensitive.
+	foreach my $waitclass (sort { uc($a) cmp uc($b) } keys %hashwe)
+	{
+		my $last = $waitclass;
+		$last =~ s/^WaitEvent//;
+
+		foreach my $wev (@{ $hashwe{$waitclass} })
+		{
+			my $new_desc = substr $wev->[2], 1, -2;
+			# put an escape \ in front of '
+			$new_desc =~ s/'/\\'/g;
+
+			# just keep text from <whatever>text</wahtever>
+			$new_desc =~ s/<.*>(.*?)<.*>/$1/g;
+
+			# just keep text from <xref linkend="text"/>
+			$new_desc =~ s/<xref linkend="guc-(.*?)"\/>/$1/g;
+
+			# remove any "see <xref linkend="text"/>"
+			$new_desc =~ s/; see.*$//;
+
+			printf $wc "\telement = (wait_event_element *) palloc(sizeof(wait_event_element));\n";
+
+			printf $wc "\telement->wait_event_type = \"%s\";\n", $last;
+			printf $wc "\telement->wait_event_name = \"%s\";\n", $wev->[1];
+			printf $wc "\telement->wait_event_description = \"%s\";\n\n", $new_desc;
+
+			printf $wc "\twait_event = lappend(wait_event, element);\n\n";
+		}
+	}
+
 	printf $h "#endif                          /* WAIT_EVENT_TYPES_H */\n";
 	close $h;
 	close $c;
+	close $wc;
 
 	rename($htmp, "$output_path/wait_event_types.h")
 	  || die "rename: $htmp to $output_path/wait_event_types.h: $!";
 	rename($ctmp, "$output_path/pgstat_wait_event.c")
 	  || die "rename: $ctmp to $output_path/pgstat_wait_event.c: $!";
+	rename($wctmp, "$output_path/wait_event_funcs_data.c")
+	  || die "rename: $ctmp to $output_path/wait_event_funcs_data.c: $!";
 }
 # Generate the .sgml file.
 elsif ($gen_docs)
diff --git a/src/backend/utils/activity/meson.build b/src/backend/utils/activity/meson.build
index 9633f3623c..46a27e7548 100644
--- a/src/backend/utils/activity/meson.build
+++ b/src/backend/utils/activity/meson.build
@@ -23,6 +23,7 @@ backend_sources += files(
 # seems nicer to not add that as an include path for the whole backend.
 waitevent_sources = files(
   'wait_event.c',
+  'wait_event_funcs.c',
 )
 
 wait_event = static_library('wait_event_names',
diff --git a/src/backend/utils/activity/wait_event_funcs.c b/src/backend/utils/activity/wait_event_funcs.c
new file mode 100644
index 0000000000..3e27a637e9
--- /dev/null
+++ b/src/backend/utils/activity/wait_event_funcs.c
@@ -0,0 +1,69 @@
+/* ----------
+ * wait_event_funcs.c
+ *    Wait event reporting infrastructure.
+ *
+ * Copyright (c) 2001-2023, PostgreSQL Global Development Group
+ *
+ *
+ * IDENTIFICATION
+ *    src/backend/utils/activity/wait_event_funcs.c
+ *
+ * NOTES
+ *
+ * The "wait_event_funcs_data.c" included in this file is generated by
+ *                      src/backend/utils/activity/generate-wait_event_types.pl
+ *
+ */
+#include "postgres.h"
+
+#include "funcapi.h"
+#include "utils/builtins.h"
+
+/*
+ * This function lists the wait events and their descriptions.
+ *
+ * The system view pg_wait_event provides a user interface to this
+ * SRF.
+ */
+Datum
+pg_get_wait_events(PG_FUNCTION_ARGS)
+{
+#define NUM_WAIT_EVENT_TABLES_ELEM 3
+	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
+	Datum       values[NUM_WAIT_EVENT_TABLES_ELEM];
+	bool        nulls[NUM_WAIT_EVENT_TABLES_ELEM];
+	List *wait_event = NIL;
+	ListCell   *cell;
+
+	typedef struct
+	{
+		char *wait_event_type;
+		char *wait_event_name;
+		char *wait_event_description;
+	} wait_event_element;
+
+	wait_event_element *element = NULL;
+	/* Build tuplestore to hold the result rows */
+	InitMaterializedSRF(fcinfo, 0);
+
+	/* Populate the wait_event List */
+	#include "wait_event_funcs_data.c"
+
+	/* Iterate over the list of wait events */
+	foreach(cell, wait_event)
+	{
+
+		wait_event_element *elem = lfirst(cell);
+
+		memset(values, 0, sizeof(values));
+		memset(nulls, 0, sizeof(nulls));
+
+		values[0] = CStringGetTextDatum(elem->wait_event_type);
+		values[1] = CStringGetTextDatum(elem->wait_event_name);
+		values[2] = CStringGetTextDatum(elem->wait_event_description);
+
+		tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
+	}
+
+	return (Datum) 0;
+}
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 6996073989..6d10d2e5be 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5417,6 +5417,12 @@
   proargmodes => '{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
   proargnames => '{pid,datid,pid,usesysid,application_name,state,query,wait_event_type,wait_event,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,backend_xid,backend_xmin,backend_type,ssl,sslversion,sslcipher,sslbits,ssl_client_dn,ssl_client_serial,ssl_issuer_dn,gss_auth,gss_princ,gss_enc,gss_delegation,leader_pid,query_id}',
   prosrc => 'pg_stat_get_activity' },
+{ oid => '8403', descr => 'describe wait events',
+  proname => 'pg_get_wait_events', procost => '10', prorows => '100',
+  proretset => 't', provolatile => 's', prorettype => 'record',
+  proargtypes => '', proallargtypes => '{text,text,text}',
+  proargmodes => '{o,o,o}', proargnames => '{wait_event_type,wait_event_name,description}',
+  prosrc => 'pg_get_wait_events' },
 { oid => '3318',
   descr => 'statistics: information about progress of backends running maintenance command',
   proname => 'pg_stat_get_progress_info', prorows => '100', proretset => 't',
diff --git a/src/include/utils/meson.build b/src/include/utils/meson.build
index 6de5d93799..c179478611 100644
--- a/src/include/utils/meson.build
+++ b/src/include/utils/meson.build
@@ -1,6 +1,6 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
+wait_event_output = ['wait_event_types.h', 'pgstat_wait_event.c', 'wait_event_funcs_data.c']
 
index 001c6e7eb9..7ace77d714 100644
@@ -134,6 +134,13 @@ select name, setting from pg_settings where name like 'enable%';
  enable_tidscan                 | on
 (21 rows)
 
+-- There is wait event descriptions
+select count(*) > 0 as ok  FROM pg_wait_event;
+ ok 
+----
+ t
+(1 row)
+
 -- Test that the pg_timezone_names and pg_timezone_abbrevs views are
 -- more-or-less working.  We can't test their contents in any great detail
 -- without the outputs changing anytime IANA updates the underlying data,
diff --git a/src/test/regress/sql/sysviews.sql b/src/test/regress/sql/sysviews.sql
index 351e469c77..643dfcc1d3 100644
--- a/src/test/regress/sql/sysviews.sql
+++ b/src/test/regress/sql/sysviews.sql
@@ -55,6 +55,9 @@ select count(*) = 0 as ok from pg_stat_wal_receiver;
 -- a regression test run.
 select name, setting from pg_settings where name like 'enable%';
 
+-- There is wait event descriptions
+select count(*) > 0 as ok  FROM pg_wait_event;
+
 -- Test that the pg_timezone_names and pg_timezone_abbrevs views are
 -- more-or-less working.  We can't test their contents in any great detail
 -- without the outputs changing anytime IANA updates the underlying data,
diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat
index 7cb23ea894..ac8da581e4 100755
--- a/src/tools/msvc/clean.bat
+++ b/src/tools/msvc/clean.bat
@@ -55,6 +55,7 @@ if exist src\include\catalog\header-stamp del /q src\include\catalog\header-stam
 if exist doc\src\sgml\version.sgml del /q doc\src\sgml\version.sgml
 
+if %DIST%==1 if exist src\backend\utils\activity\wait_event_funcs_data.c del /q src\backend\utils\activity\wait_event_funcs_data.c

---

From: Michael Paquier <[email-masked]>
Date: Mon, 14 Aug 2023 13:37:14 +0900

> Agree that's worth it given the fact that iterating one more time is not that

I have reviewed v4, and finished by putting my hands on it to see what
I could do.

This is simpler than the previous versions, still I am not much a fan
of implying the use of a list and these pallocs.  There are two things
that we could do:
- Hide that behind a macro defined in wait_event_funcs.c.
- Feed the data generated here into a static structure, like:
+static const struct
+{
+   const char *type;
+   const char *name;
+   const char *description;
+}

After experimenting with both, I've found the latter a tad cleaner, so
the attached version does that.

+       <structfield>description</structfield> <type>texte</type>
This one was difficult to see..

I am not sure that "pg_wait_event" is a good idea for the name if the
new view.  How about "pg_wait_events" instead, in plural form?  There
is more than one wait event listed.

One log entry in Solution.pm has missed the addition of a reference to
wait_event_funcs_data.c.

And..  src/backend/Makefile missed two updates for maintainer-clean & co,
no?

One thing that the patch is still missing is the handling of custom
wait events for extensions.  So this still requires more code.  I was
thinking about listed these events as:
- Type: "Extension"
- Name: What a module has registered.
- Description: "Custom wait event \"%Name%\" defined by extension".

For now I am attaching a v5.
--
Michael
From 4f0172e216bfa7b929b9ca3465d66088b2ac1566 Mon Sep 17 00:00:00 2001
From: bdrouvotAWS <[email-masked]>
Date: Sat, 5 Aug 2023 12:39:42 +0000
Subject: [PATCH v5] Add catalog pg_wait_events

Adding a new system view, namely pg_wait_event, that describes the wait
events.
---
 src/include/catalog/pg_proc.dat               |  6 ++
 src/include/utils/meson.build                 |  4 +-
 src/backend/Makefile                          |  3 +-
 src/backend/catalog/system_views.sql          |  3 +
 src/backend/utils/activity/.gitignore         |  1 +
 src/backend/utils/activity/Makefile           |  8 ++-
 .../activity/generate-wait_event_types.pl     | 46 +++++++++++--
 src/backend/utils/activity/meson.build        |  1 +
 src/backend/utils/activity/wait_event_funcs.c | 69 +++++++++++++++++++
 src/test/regress/expected/rules.out           |  4 ++
 src/test/regress/expected/sysviews.out        | 16 +++++
 src/test/regress/sql/sysviews.sql             |  4 ++
 doc/src/sgml/system-views.sgml                | 64 +++++++++++++++++
 src/tools/msvc/Solution.pm                    |  3 +-
 src/tools/msvc/clean.bat                      |  1 +
 15 files changed, 223 insertions(+), 10 deletions(-)
 create mode 100644 src/backend/utils/activity/wait_event_funcs.c

index 6996073989..1a942c678c 100644
+  proargmodes => '{o,o,o}', proargnames => '{type,name,description}',

 wait_event_types_h = wait_event_target[0]
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 1c929383c4..3e275ac759 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -134,7 +134,7 @@ storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lw
 	$(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
 
 utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt
-	$(MAKE) -C utils/activity wait_event_types.h pgstat_wait_event.c
+	$(MAKE) -C utils/activity wait_event_types.h pgstat_wait_event.c wait_event_funcs_data.c
 
 # run this unconditionally to avoid needing to know its dependencies here:
 submake-catalog-headers:
@@ -311,6 +311,7 @@ maintainer-clean: distclean
 	      storage/lmgr/lwlocknames.c \
 	      storage/lmgr/lwlocknames.h \
 	      utils/activity/pgstat_wait_event.c \
+	      utils/activity/wait_event_funcs_data.c \
 	      utils/activity/wait_event_types.h \
 	      utils/adt/jsonpath_gram.c \
 	      utils/adt/jsonpath_gram.h \
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index af65af6bdd..362b1ea8d5 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1342,3 +1342,6 @@ CREATE VIEW pg_stat_subscription_stats AS
         ss.stats_reset
     FROM pg_subscription as s,
          pg_stat_get_subscription_stats(s.oid) as ss;
+
+CREATE VIEW pg_wait_events AS
+    SELECT * FROM pg_get_wait_events() AS we;
diff --git a/src/backend/utils/activity/.gitignore b/src/backend/utils/activity/.gitignore
index d77079285b..bd0c0c7772 100644
--- a/src/backend/utils/activity/.gitignore
+++ b/src/backend/utils/activity/.gitignore
@@ -1,2 +1,3 @@
 /pgstat_wait_event.c
 /wait_event_types.h
+/wait_event_funcs_data.c
diff --git a/src/backend/utils/activity/Makefile b/src/backend/utils/activity/Makefile
index f1117745d4..f57cf3958c 100644
--- a/src/backend/utils/activity/Makefile
+++ b/src/backend/utils/activity/Makefile
@@ -32,10 +32,14 @@ OBJS = \
 	pgstat_subscription.o \
 	pgstat_wal.o \
 	pgstat_xact.o \
-	wait_event.o
+	wait_event.o \
+	wait_event_funcs.o

 
 maintainer-clean: clean
index 56335e8730..6483966c6a 100644
 
 	my $header_comment =

@@ -183,14 +188,47 @@ if ($gen_code)
 		printf $c "}\n\n";
 	}
 
+	# Generate wait_event_funcs_data.c, for the contents of static C
+	# structure holding all the information about the wait events.
+	# uc() is being used to force the comparison to be case-insensitive,
+	# even though it is not strictly mandatory here.
+	foreach my $waitclass (sort { uc($a) cmp uc($b) } keys %hashwe)
+	{
+		my $last = $waitclass;
+		$last =~ s/^WaitEvent//;
+
+		foreach my $wev (@{ $hashwe{$waitclass} })
+		{
+			my $new_desc = substr $wev->[2], 1, -2;
+			# Escape single quotes.
+			$new_desc =~ s/'/\\'/g;
+
+			# Remove SGML markups
+			$new_desc =~ s/<.*>(.*?)<.*>/$1/g;
+
+			# Tweak contents about links <xref linkend="text"/> on GUCs,
+			# then remove any reference to "see <xref linkend="text"/>".
+			$new_desc =~ s/<xref linkend="guc-(.*?)"\/>/$1/g;
+			$new_desc =~ s/; see.*$//;
+
+			# One element to the C structure holding the wait event
+			# info, as of (type, name, description).
+			printf $wc "\t{\"%s\", \"%s\", \"%s\"},\n", $last, $wev->[1],
+			  $new_desc;
+		}
+	}
+
 	printf $h "#endif                          /* WAIT_EVENT_TYPES_H */\n";
 	close $h;
 	close $c;
+	close $wc;
 
@@ -249,7 +287,7 @@ Usage: perl  [--output <path>] [--code ] [ --sgml ] input_file
 
 Options:
     --outdir         Output directory (default '.')
-    --code           Generate wait_event_types.h and pgstat_wait_event.c.
+    --code           Generate C and header files.
     --sgml           Generate wait_event_types.sgml.
 
 generate-wait_event_types.pl generates the SGML documentation and code
 
 wait_event = static_library('wait_event_names',
diff --git a/src/backend/utils/activity/wait_event_funcs.c b/src/backend/utils/activity/wait_event_funcs.c
new file mode 100644
index 0000000000..19d13c0dcd
--- /dev/null
+++ b/src/backend/utils/activity/wait_event_funcs.c
@@ -0,0 +1,69 @@
+/*------------------------------------------------------------------------
+ *
+ * wait_event_funcs.c
+ *	  Functions for accessing wait event data.
+ *
+ * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ *	  src/backend/utils/activity/wait_event_funcs.c
+ *
+ *------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "funcapi.h"
+#include "utils/builtins.h"
+
+/*
+ * Each wait event has one corresponding entry in this structure, fed to
+ * the SQL function of this file.
+ */
+static const struct
+{
+	const char *type;
+	const char *name;
+	const char *description;
+}
+
+			waitEventData[] =
+{
+#include "wait_event_funcs_data.c"
+	/* end of list */
+	{NULL, NULL, NULL}
+};
+
+
+/*
+ * pg_get_wait_events
+ *
+ * List all the wait events (type, name) and their descriptions.
+ */
+Datum
+pg_get_wait_events(PG_FUNCTION_ARGS)
+{
+#define PG_GET_WAIT_EVENTS_COLS 3
+	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
+
+	/* Build tuplestore to hold the result rows */
+	InitMaterializedSRF(fcinfo, 0);
+
+	/* Iterate over the list of wait events */
+	for (int idx = 0; waitEventData[idx].type != NULL; idx++)
+	{
+		Datum		values[PG_GET_WAIT_EVENTS_COLS] = {0};
+		bool		nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
+
+		values[0] = CStringGetTextDatum(waitEventData[idx].type);
+		values[1] = CStringGetTextDatum(waitEventData[idx].name);
+		values[2] = CStringGetTextDatum(waitEventData[idx].description);
+
+		tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
+	}
+
+	/* XXX: this needs to handle custom wait events, not yet in the tree */
+
+	return (Datum) 0;
+}
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index e07afcd4aa..55447d8090 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -2631,6 +2631,10 @@ pg_views| SELECT n.nspname AS schemaname,
    FROM (pg_class c
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
   WHERE (c.relkind = 'v'::"char");
+pg_wait_events| SELECT type,
+    name,
+    description
+   FROM pg_get_wait_events() we(type, name, description);
 SELECT tablename, rulename, definition FROM pg_rules
 WHERE schemaname = 'pg_catalog'
 ORDER BY tablename, rulename;
diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out
index 001c6e7eb9..f3ac8dfe94 100644
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -134,6 +134,22 @@ select name, setting from pg_settings where name like 'enable%';
  enable_tidscan                 | on
 (21 rows)
 
+-- There are always wait event descriptions for various types.
+select type, count(*) > 0 as ok FROM pg_wait_events
+  group by type order by type;
+   type    | ok 
+-----------+----
+ Activity  | t
+ BufferPin | t
+ Client    | t
+ Extension | t
+ IO        | t
+ IPC       | t
+ Lock      | t
+ LWLock    | t
+ Timeout   | t
+(9 rows)
+
 -- Test that the pg_timezone_names and pg_timezone_abbrevs views are
 -- more-or-less working.  We can't test their contents in any great detail
 -- without the outputs changing anytime IANA updates the underlying data,
diff --git a/src/test/regress/sql/sysviews.sql b/src/test/regress/sql/sysviews.sql
index 351e469c77..853daa85eb 100644
--- a/src/test/regress/sql/sysviews.sql
+++ b/src/test/regress/sql/sysviews.sql
@@ -55,6 +55,10 @@ select count(*) = 0 as ok from pg_stat_wal_receiver;
 -- a regression test run.
 select name, setting from pg_settings where name like 'enable%';
 
+-- There are always wait event descriptions for various types.
+select type, count(*) > 0 as ok FROM pg_wait_events
+  group by type order by type;
+
 -- Test that the pg_timezone_names and pg_timezone_abbrevs views are
 -- more-or-less working.  We can't test their contents in any great detail
 -- without the outputs changing anytime IANA updates the underlying data,
diff --git a/doc/src/sgml/system-views.sgml b/doc/src/sgml/system-views.sgml
index 57b228076e..2b35c2f91b 100644
--- a/doc/src/sgml/system-views.sgml
+++ b/doc/src/sgml/system-views.sgml
@@ -221,6 +221,11 @@
       <entry>views</entry>
      </row>
 
+     <row>
+      <entry><link linkend="view-pg-wait-events"><structname>pg_wait_events</structname></link></entry>
+      <entry>wait events</entry>
+     </row>
+
     </tbody>
    </tgroup>
   </table>
@@ -4825,4 +4830,63 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
   </table>
  </sect1>
 
+
+ <sect1 id="view-pg-wait-events">
+  <title><structname>pg_wait_events</structname></title>
+
+  <indexterm zone="view-pg-wait-events">
+   <primary>pg_wait_events</primary>
+  </indexterm>
+
+  <para>
+   The view <structname>pg_wait_events</structname> provides description about the
+   wait events.
+  </para>
+
+  <table>
+   <title><structname>pg_wait_events</structname> Columns</title>
+   <tgroup cols="1">
+    <thead>
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       Column Type
+      </para>
+      <para>
+       Description
+      </para></entry>
+     </row>
+    </thead>
+
+    <tbody>
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>type</structfield> <type>text</type>
+      </para>
+      <para>
+       Wait event type
+      </para></entry>
+     </row>
+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>name</structfield> <type>text</type>
+      </para>
+      <para>
+       Wait event name
+      </para></entry>
+     </row>
+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>description</structfield> <type>text</type>
+      </para>
+      <para>
+       Wait event description
+      </para></entry>
+     </row>
+    </tbody>
+   </tgroup>
+  </table>
+ </sect1>
+
 </chapter>
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index c98a1e9f9a..a50f730260 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -588,7 +588,8 @@ sub GenerateFiles
 			'src/include/utils/wait_event_types.h',
 			'src/backend/utils/activity/wait_event_names.txt'))
 	{
-		print "Generating pgstat_wait_event.c and wait_event_types.h...\n";
+		print
+		  "Generating pgstat_wait_event.c, wait_event_types.h and wait_event_funcs_data.c...\n";
 		my $activ = 'src/backend/utils/activity';
 		system(
 			"perl $activ/generate-wait_event_types.pl --outdir $activ --code $activ/wait_event_names.txt"
diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat
index 7cb23ea894..ac8da581e4 100755
--- a/src/tools/msvc/clean.bat
+++ b/src/tools/msvc/clean.bat
@@ -55,6 +55,7 @@ if exist src\include\catalog\header-stamp del /q src\include\catalog\header-stam
 if exist doc\src\sgml\version.sgml del /q doc\src\sgml\version.sgml
 
2.40.1

---

From: "Drouvot, Bertrand" <[email-masked]>
Date: Wed, 16 Aug 2023 07:04:53 +0200

Hi,

> I have reviewed v4, and finished by putting my hands on it to see what

Thanks!

> There are two things

Yeah, looking at what you've done in v5, I also agree that's better
that what has been done in v4 (I also think it will be easier to maintain).

> is more than one wait event listed.

I'd prefer the singular form. There is a lot of places where it's already used
(pg_database, pg_user, pg_namespace...to name a few) and it looks like that using
the plural form are exceptions.

> One log entry in Solution.pm has missed the addition of a reference to

Oh right, thanks for fixing it in v5.

> And..  src/backend/Makefile missed two updates for maintainer-clean & co,
Oh right, thanks for fixing it in v5.

> wait events for extensions. 

Yeah, now that af720b4c50 is done, I'll add the custom wait events handling
in v6.

> So this still requires more code.  I was

That sounds good to me, I'll do that.

Regards,