Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e68e43

Browse files
committed
Add system view pg_wait_events
This new view, wrapped around a SRF, shows some information known aboutwait events, as of:- Name.- Type (Activity, I/O, Extension, etc.).- Description.All the information retrieved comes from wait_event_names.txt, and thedescription is the same as the documentation with filters applied toremove any XML markups. This view is useful when joined withpg_stat_activity to get the description of a wait event reported.Custom wait events for extensions are included in the view.Original idea by Yves Colin.Author: Bertrand DrouvotReviewed-by: Kyotaro Horiguchi, Masahiro Ikeda, Tom Lane, MichaelPaquierDiscussion:https://postgr.es/m/0e2ae164-dc89-03c3-cf7f-de86378053ac@gmail.com
1 parenta2a6249 commit1e68e43

File tree

19 files changed

+317
-11
lines changed

19 files changed

+317
-11
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
11031103
&wait_event_types;
11041104

11051105
<para>
1106-
Hereis an example of how wait events can be viewed:
1106+
Hereare examples of how wait events can be viewed:
11071107

11081108
<programlisting>
11091109
SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
@@ -1112,6 +1112,18 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
11121112
2540 | Lock | relation
11131113
6644 | LWLock | ProcArray
11141114
(2 rows)
1115+
</programlisting>
1116+
1117+
<programlisting>
1118+
SELECT a.pid, a.wait_event, w.description
1119+
FROM pg_stat_activity a JOIN
1120+
pg_wait_events w ON (a.wait_event_type = w.type AND
1121+
a.wait_event = w.name)
1122+
WHERE wait_event is NOT NULL and a.state = 'active';
1123+
-[ RECORD 1 ]------------------------------------------------------------------
1124+
pid | 686674
1125+
wait_event | WALInitSync
1126+
description | Waiting for a newly initialized WAL file to reach durable storage
11151127
</programlisting>
11161128
</para>
11171129

‎doc/src/sgml/system-views.sgml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
<entry>views</entry>
222222
</row>
223223

224+
<row>
225+
<entry><link linkend="view-pg-wait-events"><structname>pg_wait_events</structname></link></entry>
226+
<entry>wait events</entry>
227+
</row>
228+
224229
</tbody>
225230
</tgroup>
226231
</table>
@@ -4825,4 +4830,63 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
48254830
</table>
48264831
</sect1>
48274832

4833+
4834+
<sect1 id="view-pg-wait-events">
4835+
<title><structname>pg_wait_events</structname></title>
4836+
4837+
<indexterm zone="view-pg-wait-events">
4838+
<primary>pg_wait_events</primary>
4839+
</indexterm>
4840+
4841+
<para>
4842+
The view <structname>pg_wait_events</structname> provides description about the
4843+
wait events.
4844+
</para>
4845+
4846+
<table>
4847+
<title><structname>pg_wait_events</structname> Columns</title>
4848+
<tgroup cols="1">
4849+
<thead>
4850+
<row>
4851+
<entry role="catalog_table_entry"><para role="column_definition">
4852+
Column Type
4853+
</para>
4854+
<para>
4855+
Description
4856+
</para></entry>
4857+
</row>
4858+
</thead>
4859+
4860+
<tbody>
4861+
<row>
4862+
<entry role="catalog_table_entry"><para role="column_definition">
4863+
<structfield>type</structfield> <type>text</type>
4864+
</para>
4865+
<para>
4866+
Wait event type
4867+
</para></entry>
4868+
</row>
4869+
4870+
<row>
4871+
<entry role="catalog_table_entry"><para role="column_definition">
4872+
<structfield>name</structfield> <type>text</type>
4873+
</para>
4874+
<para>
4875+
Wait event name
4876+
</para></entry>
4877+
</row>
4878+
4879+
<row>
4880+
<entry role="catalog_table_entry"><para role="column_definition">
4881+
<structfield>description</structfield> <type>text</type>
4882+
</para>
4883+
<para>
4884+
Wait event description
4885+
</para></entry>
4886+
</row>
4887+
</tbody>
4888+
</tgroup>
4889+
</table>
4890+
</sect1>
4891+
48284892
</chapter>

‎src/backend/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lw
134134
$(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
135135

136136
utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt
137-
$(MAKE) -C utils/activity wait_event_types.h pgstat_wait_event.c
137+
$(MAKE) -C utils/activity wait_event_types.h pgstat_wait_event.c wait_event_funcs_data.c
138138

139139
# run this unconditionally to avoid needing to know its dependencies here:
140140
submake-catalog-headers:
@@ -311,6 +311,7 @@ maintainer-clean: distclean
311311
storage/lmgr/lwlocknames.c\
312312
storage/lmgr/lwlocknames.h\
313313
utils/activity/pgstat_wait_event.c\
314+
utils/activity/wait_event_funcs_data.c\
314315
utils/activity/wait_event_types.h\
315316
utils/adt/jsonpath_gram.c\
316317
utils/adt/jsonpath_gram.h\

‎src/backend/catalog/system_views.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,3 +1342,6 @@ CREATE VIEW pg_stat_subscription_stats AS
13421342
ss.stats_reset
13431343
FROM pg_subscriptionas s,
13441344
pg_stat_get_subscription_stats(s.oid)as ss;
1345+
1346+
CREATEVIEWpg_wait_eventsAS
1347+
SELECT*FROM pg_get_wait_events();

‎src/backend/utils/activity/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/pgstat_wait_event.c
22
/wait_event_types.h
3+
/wait_event_funcs_data.c

‎src/backend/utils/activity/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ OBJS = \
3232
pgstat_subscription.o\
3333
pgstat_wal.o\
3434
pgstat_xact.o\
35-
wait_event.o
35+
wait_event.o\
36+
wait_event_funcs.o
3637

3738
include$(top_srcdir)/src/backend/common.mk
3839

40+
wait_event_funcs.o: wait_event_funcs_data.c
41+
wait_event_funcs_data.c: wait_event_types.h
42+
3943
wait_event.o: pgstat_wait_event.c
4044
pgstat_wait_event.c: wait_event_types.h
4145
touch$@
@@ -44,4 +48,4 @@ wait_event_types.h: $(top_srcdir)/src/backend/utils/activity/wait_event_names.tx
4448
$(PERL)$(srcdir)/generate-wait_event_types.pl --code$<
4549

4650
maintainer-clean: clean
47-
rm -f wait_event_types.h pgstat_wait_event.c
51+
rm -f wait_event_types.h pgstat_wait_event.c wait_event_funcs_data.c

‎src/backend/utils/activity/generate-wait_event_types.pl

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Generate wait events support files from wait_event_names.txt:
55
# - wait_event_types.h (if --code is passed)
66
# - pgstat_wait_event.c (if --code is passed)
7+
# - wait_event_funcs_data.c (if --code is passed)
78
# - wait_event_types.sgml (if --docs is passed)
89
#
910
# Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
@@ -98,8 +99,10 @@
9899
# multiple times.
99100
my$htmp ="$output_path/wait_event_types.h.tmp$$";
100101
my$ctmp ="$output_path/pgstat_wait_event.c.tmp$$";
102+
my$wctmp ="$output_path/wait_event_funcs_data.c.tmp$$";
101103
openmy$h,'>',$htmpordie"Could not open$htmp:$!";
102104
openmy$c,'>',$ctmpordie"Could not open$ctmp:$!";
105+
openmy$wc,'>',$wctmpordie"Could not open$wctmp:$!";
103106

104107
my$header_comment =
105108
'/*-------------------------------------------------------------------------
@@ -129,12 +132,14 @@
129132

130133
printf$c$header_comment,'pgstat_wait_event.c';
131134

135+
printf$wc$header_comment,'wait_event_funcs_data.c';
136+
137+
# Generate the pgstat_wait_event.c and wait_event_types.h files
132138
# uc() is being used to force the comparison to be case-insensitive.
133139
foreachmy$waitclass (sort {uc($a)cmpuc($b) }keys%hashwe)
134140
{
135-
136-
# Don't generate .c and .h files for Extension, LWLock and
137-
# Lock, these are handled independently.
141+
# Don't generate the pgstat_wait_event.c and wait_event_types.h files
142+
# for Extension, LWLock and Lock, these are handled independently.
138143
next
139144
if ($waitclasseq'WaitEventExtension'
140145
||$waitclasseq'WaitEventLWLock'
@@ -183,14 +188,57 @@
183188
printf$c"}\n\n";
184189
}
185190

191+
# Generate wait_event_funcs_data.c, building the contents of a static
192+
# C structure holding all the information about the wait events.
193+
# uc() is being used to force the comparison to be case-insensitive,
194+
# even though it is not required here.
195+
foreachmy$waitclass (sort {uc($a)cmpuc($b) }keys%hashwe)
196+
{
197+
my$last =$waitclass;
198+
$last =~s/^WaitEvent//;
199+
200+
foreachmy$wev (@{$hashwe{$waitclass} })
201+
{
202+
my$new_desc =substr$wev->[2], 1, -2;
203+
# Escape single quotes.
204+
$new_desc =~s/'/\\'/g;
205+
206+
# Replace the "quote" markups by real ones.
207+
$new_desc =~s/<quote>(.*?)<\/quote>/\\"$1\\"/g;
208+
209+
# Remove SGML markups.
210+
$new_desc =~s/<.*?>(.*?)<.*?>/$1/g;
211+
212+
# Tweak contents about links <xref linkend="text"/>
213+
# on GUCs,
214+
while (my ($capture) =
215+
$new_desc =~m/<xref linkend="guc-(.*?)"\/>/g)
216+
{
217+
$capture =~s/-/_/g;
218+
$new_desc =~s/<xref linkend="guc-.*?"\/>/$capture/g;
219+
}
220+
# Then remove any reference to
221+
# "see <xref linkend="text"/>".
222+
$new_desc =~s/; see.*$//;
223+
224+
# Build one element of the C structure holding the
225+
# wait event info, as of (type, name, description).
226+
printf$wc"\t{\"%s\",\"%s\",\"%s\"},\n",$last,$wev->[1],
227+
$new_desc;
228+
}
229+
}
230+
186231
printf$h"#endif /* WAIT_EVENT_TYPES_H */\n";
187232
close$h;
188233
close$c;
234+
close$wc;
189235

190236
rename($htmp,"$output_path/wait_event_types.h")
191237
||die"rename:$htmp to$output_path/wait_event_types.h:$!";
192238
rename($ctmp,"$output_path/pgstat_wait_event.c")
193239
||die"rename:$ctmp to$output_path/pgstat_wait_event.c:$!";
240+
rename($wctmp,"$output_path/wait_event_funcs_data.c")
241+
||die"rename:$wctmp to$output_path/wait_event_funcs_data.c:$!";
194242
}
195243
# Generate the .sgml file.
196244
elsif ($gen_docs)
@@ -249,7 +297,7 @@ sub usage
249297
250298
Options:
251299
--outdir Output directory (default '.')
252-
--code Generatewait_event_types.h andpgstat_wait_event.c.
300+
--code GenerateC andheader files.
253301
--sgml Generate wait_event_types.sgml.
254302
255303
generate-wait_event_types.pl generates the SGML documentation and code

‎src/backend/utils/activity/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ backend_sources += files(
2323
# seems nicer to not add that as an include path for the whole backend.
2424
waitevent_sources=files(
2525
'wait_event.c',
26+
'wait_event_funcs.c',
2627
)
2728

2829
wait_event=static_library('wait_event_names',

‎src/backend/utils/activity/wait_event.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,46 @@ GetWaitEventExtensionIdentifier(uint16 eventId)
264264
}
265265

266266

267+
/*
268+
* Returns a list of currently defined custom wait event names for extensions.
269+
* The result is a palloc'd array, with the number of elements saved in
270+
* *nwaitevents.
271+
*/
272+
char**
273+
GetWaitEventExtensionNames(int*nwaitevents)
274+
{
275+
char**waiteventnames;
276+
WaitEventExtensionEntryByName*hentry;
277+
HASH_SEQ_STATUShash_seq;
278+
intindex;
279+
intels;
280+
281+
LWLockAcquire(WaitEventExtensionLock,LW_SHARED);
282+
283+
/* Now we can safely count the number of entries */
284+
els=hash_get_num_entries(WaitEventExtensionHashByName);
285+
286+
/* Allocate enough space for all entries */
287+
waiteventnames=palloc(els*sizeof(char*));
288+
289+
/* Now scan the hash table to copy the data */
290+
hash_seq_init(&hash_seq,WaitEventExtensionHashByName);
291+
292+
index=0;
293+
while ((hentry= (WaitEventExtensionEntryByName*)hash_seq_search(&hash_seq))!=NULL)
294+
{
295+
waiteventnames[index]=pstrdup(hentry->wait_event_name);
296+
index++;
297+
}
298+
299+
LWLockRelease(WaitEventExtensionLock);
300+
301+
Assert(index==els);
302+
303+
*nwaitevents=index;
304+
returnwaiteventnames;
305+
}
306+
267307
/*
268308
* Configure wait event reporting to report wait events to *wait_event_info.
269309
* *wait_event_info needs to be valid until pgstat_reset_wait_event_storage()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp