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

Commit885496f

Browse files
committed
Fixes after review
- Rename some columns in code and in GUC allowed values- Change client_addr type to inet as in pg_stat_activity- event value for dimension GUC now turn both wait_event and wait_event_type on and off; event_type not supported- README formatting- Hide leader_pid for leader process- Reset profile and history after reloading configuration, but only if dimensions have changed- Disallow passing empty string as dimensions- pid and queryid are NULL now if are not in dimenstions- empty client_hostname is now NULL like in pg_stat_activity- empty appname is now shown as empty string as in pg_stat_activity
1 parent01c45a4 commit885496f

File tree

5 files changed

+96
-72
lines changed

5 files changed

+96
-72
lines changed

‎README.md‎

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ all processes including background workers.
107107
| queryid| int8| Id of query|
108108
| role_id| int4| Id of role|
109109
| database_id| int4| Id of database|
110-
|parallel_leader_pid| int4| Id of parallel query leader|
110+
|leader_pid| int4| Id of parallel query leader|
111111
| backend_type| text| Name of backend type|
112112
| backend_state| text| Name of backend state|
113-
|proc_start| timestamptz| Timestamp of process start|
114-
| client_addr|text| Client address|
113+
|backend_start| timestamptz| Timestamp of process start|
114+
| client_addr|inet| Client address|
115115
| client_hostname| text| Client hostname|
116-
|appname| text| Application name|
116+
|application_name| text| Application name|
117117

118118
`pg_wait_sampling_get_current(pid int4)` returns the same table for single given
119119
process.
@@ -129,13 +129,13 @@ in-memory ring buffer.
129129
| queryid| int8| Id of query|
130130
| role_id| int4| Id of role|
131131
| database_id| int4| Id of database|
132-
|parallel_leader_pid| int4| Id of parallel query leader|
132+
|leader_pid| int4| Id of parallel query leader|
133133
| backend_type| text| Name of backend type|
134134
| backend_state| text| Name of backend state|
135-
|proc_start| timestamptz| Timestamp of process start|
136-
| client_addr|text| Client address|
135+
|backend_start| timestamptz| Timestamp of process start|
136+
| client_addr|inet| Client address|
137137
| client_hostname| text| Client hostname|
138-
|appname| text| Application name|
138+
|application_name| text| Application name|
139139
| ts| timestamptz| Sample timestamp|
140140

141141
`pg_wait_sampling_reset_history()` function resets the history.
@@ -151,30 +151,30 @@ in-memory hash table.
151151
| queryid| int8| Id of query|
152152
| role_id| int4| Id of role|
153153
| database_id| int4| Id of database|
154-
|parallel_leader_pid| int4| Id of parallel query leader|
154+
|leader_pid| int4| Id of parallel query leader|
155155
| backend_type| text| Name of backend type|
156156
| backend_state| text| Name of backend state|
157-
|proc_start| timestamptz| Timestamp of process start|
158-
| client_addr|text| Client address|
157+
|backend_start| timestamptz| Timestamp of process start|
158+
| client_addr|inet| Client address|
159159
| client_hostname| text| Client hostname|
160-
|appname| text| Application name|
160+
|application_name| text| Application name|
161161
| count| int8| Count of samples|
162162

163163
`pg_wait_sampling_reset_profile()` function resets the profile.
164164

165165
The work of wait event statistics collector worker is controlled by following
166166
GUCs.
167167

168-
| Parameter name| Data type| Description| Default value|
169-
|-------------------------------------| ---------|---------------------------------------------|----------------------------------------------|
170-
| pg_wait_sampling.history_size| int4| Size of history in-memory ring buffer|5000|
171-
| pg_wait_sampling.history_period| int4| Period for history sampling in milliseconds|10|
172-
| pg_wait_sampling.profile_period| int4| Period for profile sampling in milliseconds|10|
173-
| pg_wait_sampling.profile_pid| bool| Whether profile should be per pid|true|
174-
| pg_wait_sampling.profile_queries| enum| Whether profile should be per query|top|
175-
| pg_wait_sampling.sample_cpu| bool| Whether on CPU backends should be sampled|true|
176-
| pg_wait_sampling.history_dimensions| text| Additional columns in extended history view| 'pid,wait_event_type, wait_event, query_id'|
177-
| pg_wait_sampling.profile_dimensions| text| Additional columns in extended profile view| 'pid,wait_event_type, wait_event, query_id'|
168+
| Parameter name| Data type| Description| Default value|
169+
|-------------------------------------| ---------|---------------------------------------------|-----------------------|
170+
| pg_wait_sampling.history_size| int4| Size of history in-memory ring buffer| 5000|
171+
| pg_wait_sampling.history_period| int4| Period for history sampling in milliseconds| 10|
172+
| pg_wait_sampling.profile_period| int4| Period for profile sampling in milliseconds| 10|
173+
| pg_wait_sampling.profile_pid| bool| Whether profile should be per pid| true|
174+
| pg_wait_sampling.profile_queries| enum| Whether profile should be per query| top|
175+
| pg_wait_sampling.sample_cpu| bool| Whether on CPU backends should be sampled| true|
176+
| pg_wait_sampling.history_dimensions| text| Additional columns in extended history view| 'pid,event, queryid'|
177+
| pg_wait_sampling.profile_dimensions| text| Additional columns in extended profile view| 'pid,event, queryid'|
178178

179179
If`pg_wait_sampling.profile_pid` is set to false, sampling profile wouldn't be
180180
collected in per-process manner. In this case the value of pid could would
@@ -190,17 +190,18 @@ will be NULL.
190190

191191
`pg_wait_sampling.history_dimenstions` and`pg_wait_sampling.profile_dimensions`
192192
determine what additional columns will be sampled in`history/profile_extended`
193-
views. Possible values are`all`,`pid`,`wait_event_type`,`wait_event`,
194-
`query_id`,`role_id`,`database_id`,`parallel_leader_pid`,`backend_type`,
195-
`backend_state`,`backend_start_time`,`client_addr`,`client_hostname`,
196-
`appname` and any combination of column names.
193+
views. Possible values are`all`,`pid`,`event`,`query_id`,`role_id`,
194+
`database_id`,`leader_pid`,`backend_type`,`backend_state`,`backend_start`,
195+
`client_addr`,`client_hostname`,`application_name`
196+
and any combination of column names.
197+
`event` turns on and off both event and event_type columns.
197198
`all` cannot be used together with any other values and must be used alone.
198199

199200
>[!WARNING]
200201
>Turning on any of the following columns:`backend_type`,`backend_state`,
201-
>`backend_start_time`,`client_addr`,`client_hostname`,`appname` will reduce
202-
>performance compared to sampling none of those due to the need to look into
203-
>BackendStatusTable. This is especially noticeable with PostgreSQL 13-16
202+
>`backend_start`,`client_addr`,`client_hostname`,`application_name` will
203+
>reduceperformance compared to sampling none of those due to the need to look
204+
>intoBackendStatusTable. This is especially noticeable with PostgreSQL 13-16
204205
205206
Values of these GUC variables can be changed only in config file or with ALTER SYSTEM.
206207
Then you need to reload server's configuration (such as with`pg_reload_conf` function)

‎collector.c‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ fill_dimensions(SamplingDimensions *dimensions, PGPROC *proc,
195195
dimensions->database_id=database_id;
196196

197197
if (dimensions_mask&PGWS_DIMENSIONS_PARALLEL_LEADER_PID)
198-
dimensions->parallel_leader_pid= (lockGroupLeader ?
198+
dimensions->parallel_leader_pid= (lockGroupLeader&&
199+
lockGroupLeader->pid!=pid ?
199200
lockGroupLeader->pid :
200201
0);
201202

@@ -220,7 +221,7 @@ fill_dimensions(SamplingDimensions *dimensions, PGPROC *proc,
220221
dimensions->backend_state=bestatus->st_state;
221222

222223
if (dimensions_mask&PGWS_DIMENSIONS_BE_START_TIME)
223-
dimensions->proc_start=bestatus->st_proc_start_timestamp;
224+
dimensions->backend_start=bestatus->st_proc_start_timestamp;
224225

225226
if (dimensions_mask&PGWS_DIMENSIONS_CLIENT_ADDR)
226227
dimensions->client_addr=bestatus->st_clientaddr;
@@ -248,7 +249,7 @@ copy_dimensions (SamplingDimensions *dst, SamplingDimensions *src,
248249
if (dst_dimensions_mask&PGWD_DIMENSIONS_QUERY_ID)
249250
dst->queryId=src->queryId;
250251

251-
if (dst_dimensions_mask&PGWD_DIMENSIONS_QUERY_ID)
252+
if (dst_dimensions_mask&PGWS_DIMENSIONS_ROLE_ID)
252253
dst->role_id=src->role_id;
253254

254255
if (dst_dimensions_mask&PGWS_DIMENSIONS_DB_ID)
@@ -267,7 +268,7 @@ copy_dimensions (SamplingDimensions *dst, SamplingDimensions *src,
267268
dst->backend_state=src->backend_state;
268269

269270
if (dst_dimensions_mask&PGWS_DIMENSIONS_BE_START_TIME)
270-
dst->proc_start=src->proc_start;
271+
dst->backend_start=src->backend_start;
271272

272273
if (dst_dimensions_mask&PGWS_DIMENSIONS_CLIENT_ADDR)
273274
dst->client_addr=src->client_addr;
@@ -305,7 +306,7 @@ get_serialized_size(int dimensions_mask, bool need_last_field)
305306
if (dimensions_mask&PGWS_DIMENSIONS_BE_STATE)
306307
serialized_size+=sizeof(dimensions.backend_state);
307308
if (dimensions_mask&PGWS_DIMENSIONS_BE_START_TIME)
308-
serialized_size+=sizeof(dimensions.proc_start);
309+
serialized_size+=sizeof(dimensions.backend_start);
309310
if (dimensions_mask&PGWS_DIMENSIONS_CLIENT_ADDR)
310311
serialized_size+=sizeof(dimensions.client_addr);
311312
if (dimensions_mask&PGWS_DIMENSIONS_CLIENT_HOSTNAME)
@@ -393,9 +394,9 @@ serialize_item(SamplingDimensions dimensions, int dimensions_mask,
393394

394395
if (dimensions_mask&PGWS_DIMENSIONS_BE_START_TIME)
395396
{
396-
memcpy(dummy_array+*serialized_size,&dimensions.proc_start,
397-
sizeof(dimensions.proc_start));
398-
*serialized_size+=sizeof(dimensions.proc_start);
397+
memcpy(dummy_array+*serialized_size,&dimensions.backend_start,
398+
sizeof(dimensions.backend_start));
399+
*serialized_size+=sizeof(dimensions.backend_start);
399400
}
400401

401402
if (dimensions_mask&PGWS_DIMENSIONS_CLIENT_ADDR)
@@ -515,9 +516,9 @@ deserialize_item(SamplingDimensions *dimensions, char *serialized_item,
515516

516517
if (dimensions_mask&PGWS_DIMENSIONS_BE_START_TIME)
517518
{
518-
memcpy(&dimensions->proc_start,serialized_item+idx,
519-
sizeof(dimensions->proc_start));
520-
idx+=sizeof(dimensions->proc_start);
519+
memcpy(&dimensions->backend_start,serialized_item+idx,
520+
sizeof(dimensions->backend_start));
521+
idx+=sizeof(dimensions->backend_start);
521522
}
522523

523524
if (dimensions_mask&PGWS_DIMENSIONS_CLIENT_ADDR)
@@ -862,6 +863,18 @@ pgws_collector_main(Datum main_arg)
862863
{
863864
ConfigReloadPending= false;
864865
ProcessConfigFile(PGC_SIGHUP);
866+
867+
/* Reset profile and history if needed */
868+
if (pgws_history_dimensions!=saved_history_dimensions)
869+
{
870+
pfree(observations.items);
871+
alloc_history(&observations,pgws_historySize);
872+
}
873+
if (pgws_profile_dimensions!=saved_profile_dimensions)
874+
{
875+
hash_destroy(profile_hash);
876+
profile_hash=make_profile_hash();
877+
}
865878
}
866879

867880
/* Calculate time to next sample for history or profile */

‎pg_wait_sampling--1.1--1.2.sql‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ CREATE FUNCTION pg_wait_sampling_get_current (
3232
OUT queryid int8,
3333
OUT role_id int8,
3434
OUT database_id int8,
35-
OUTparallel_leader_pid int4,
35+
OUTleader_pid int4,
3636
OUT is_regular_backend bool,
3737
OUT backend_typetext,
3838
OUT backend_statetext,
39-
OUTproc_starttimestamptz,
40-
OUT client_addrtext,
39+
OUTbackend_starttimestamptz,
40+
OUT client_addrinet,
4141
OUT client_hostnametext,
42-
OUTappnametext
42+
OUTapplication_nametext
4343
)
4444
RETURNS SETOF record
4545
AS'MODULE_PATHNAME','pg_wait_sampling_get_current_1_2'
@@ -57,14 +57,14 @@ CREATE FUNCTION pg_wait_sampling_get_history (
5757
OUT queryid int8,
5858
OUT role_id int8,
5959
OUT database_id int8,
60-
OUTparallel_leader_pid int4,
60+
OUTleader_pid int4,
6161
OUT is_regular_backend bool,
6262
OUT backend_typetext,
6363
OUT backend_statetext,
64-
OUTproc_starttimestamptz,
65-
OUT client_addrtext,
64+
OUTbackend_starttimestamptz,
65+
OUT client_addrinet,
6666
OUT client_hostnametext,
67-
OUTappnametext,
67+
OUTapplication_nametext,
6868
OUT tstimestamptz
6969
)
7070
RETURNS SETOF record
@@ -83,14 +83,14 @@ CREATE FUNCTION pg_wait_sampling_get_profile (
8383
OUT queryid int8,
8484
OUT role_id int8,
8585
OUT database_id int8,
86-
OUTparallel_leader_pid int4,
86+
OUTleader_pid int4,
8787
OUT is_regular_backend bool,
8888
OUT backend_typetext,
8989
OUT backend_statetext,
90-
OUTproc_starttimestamptz,
91-
OUT client_addrtext,
90+
OUTbackend_starttimestamptz,
91+
OUT client_addrinet,
9292
OUT client_hostnametext,
93-
OUTappnametext,
93+
OUTapplication_nametext,
9494
OUT count int8
9595
)
9696
RETURNS SETOF record

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp