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

Commit2c8514d

Browse files
author
dmitry
committed
initial commit
add fields isregularbackend, databaseid, roleid to _history view
1 parent3c1046c commit2c8514d

5 files changed

+59
-19
lines changed

‎collector.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ probe_waits(History *observations, HTAB *profile_hash,
175175
item.queryId=0;
176176

177177
item.ts=ts;
178+
item.isRegularBackend= !(proc->isBackgroundWorker);
179+
item.databaseId=proc->databaseId;
180+
item.roleId=proc->roleId;
178181

179182
/* Write to the history if needed */
180183
if (write_history)

‎pg_wait_sampling--1.0--1.1.sql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ DROP FUNCTION pg_wait_sampling_get_profile (
2222
) CASCADE;
2323

2424
CREATEFUNCTIONpg_wait_sampling_get_current (
25-
pid int4,
26-
OUT pid int4,
27-
OUT event_typetext,
28-
OUT eventtext,
29-
OUT queryid int8
25+
pid int4,
26+
OUT pid int4,
27+
OUT event_typetext,
28+
OUT eventtext,
29+
OUT queryid int8,
30+
OUT isregularbackendboolean,
31+
OUT databaseidoid,
32+
OUT roleidoid
3033
)
3134
RETURNS SETOF record
3235
AS'MODULE_PATHNAME'

‎pg_wait_sampling--1.1.sql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
\echo Use"CREATE EXTENSION pg_wait_sampling" to load this file. \quit
55

66
CREATEFUNCTIONpg_wait_sampling_get_current (
7-
pid int4,
8-
OUT pid int4,
9-
OUT event_typetext,
10-
OUT eventtext,
11-
OUT queryid int8
7+
pid int4,
8+
OUT pid int4,
9+
OUT event_typetext,
10+
OUT eventtext,
11+
OUT queryid int8,
12+
OUT isregularbackendboolean,
13+
OUT databaseidoid,
14+
OUT roleidoid
1215
)
1316
RETURNS SETOF record
1417
AS'MODULE_PATHNAME'
@@ -24,7 +27,10 @@ CREATE FUNCTION pg_wait_sampling_get_history (
2427
OUT tstimestamptz,
2528
OUT event_typetext,
2629
OUT eventtext,
27-
OUT queryid int8
30+
OUT queryid int8,
31+
OUT isregularbackendboolean,
32+
OUT databaseidoid,
33+
OUT roleidoid
2834
)
2935
RETURNS SETOF record
3036
AS'MODULE_PATHNAME'

‎pg_wait_sampling.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
514514
params->ts=GetCurrentTimestamp();
515515

516516
funcctx->user_fctx=params;
517-
tupdesc=CreateTemplateTupleDesc(4);
517+
tupdesc=CreateTemplateTupleDesc(7);
518518
TupleDescInitEntry(tupdesc, (AttrNumber)1,"pid",
519519
INT4OID,-1,0);
520520
TupleDescInitEntry(tupdesc, (AttrNumber)2,"type",
@@ -523,6 +523,12 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
523523
TEXTOID,-1,0);
524524
TupleDescInitEntry(tupdesc, (AttrNumber)4,"queryid",
525525
INT8OID,-1,0);
526+
TupleDescInitEntry(tupdesc, (AttrNumber)5,"isregularbackend",
527+
BOOLOID,-1,0);
528+
TupleDescInitEntry(tupdesc, (AttrNumber)6,"databaseid",
529+
OIDOID,-1,0);
530+
TupleDescInitEntry(tupdesc, (AttrNumber)7,"roleid",
531+
OIDOID,-1,0);
526532

527533
funcctx->tuple_desc=BlessTupleDesc(tupdesc);
528534

@@ -540,6 +546,9 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
540546
item->pid=proc->pid;
541547
item->wait_event_info=proc->wait_event_info;
542548
item->queryId=pgws_proc_queryids[proc-ProcGlobal->allProcs];
549+
item->isRegularBackend= !(proc->isBackgroundWorker);
550+
item->databaseId=proc->databaseId;
551+
item->roleId=proc->roleId;
543552
funcctx->max_calls=1;
544553
}
545554
else
@@ -562,6 +571,9 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
562571
params->items[j].pid=proc->pid;
563572
params->items[j].wait_event_info=proc->wait_event_info;
564573
params->items[j].queryId=pgws_proc_queryids[i];
574+
params->items[j].isRegularBackend= !(proc->isBackgroundWorker);
575+
params->items[j].databaseId=proc->databaseId;
576+
params->items[j].roleId=proc->roleId;
565577
j++;
566578
}
567579
funcctx->max_calls=j;
@@ -579,8 +591,8 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
579591
if (funcctx->call_cntr<funcctx->max_calls)
580592
{
581593
HeapTupletuple;
582-
Datumvalues[4];
583-
boolnulls[4];
594+
Datumvalues[7];
595+
boolnulls[7];
584596
constchar*event_type,
585597
*event;
586598
HistoryItem*item;
@@ -604,6 +616,9 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
604616
nulls[2]= true;
605617

606618
values[3]=UInt64GetDatum(item->queryId);
619+
values[4]=BoolGetDatum(item->isRegularBackend);
620+
values[5]=ObjectIdGetDatum(item->databaseId);
621+
values[6]=ObjectIdGetDatum(item->roleId);
607622
tuple=heap_form_tuple(funcctx->tuple_desc,values,nulls);
608623

609624
SRF_RETURN_NEXT(funcctx,HeapTupleGetDatum(tuple));
@@ -858,7 +873,7 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
858873
funcctx->max_calls=history->count;
859874

860875
/* Make tuple descriptor */
861-
tupdesc=CreateTemplateTupleDesc(5);
876+
tupdesc=CreateTemplateTupleDesc(8);
862877
TupleDescInitEntry(tupdesc, (AttrNumber)1,"pid",
863878
INT4OID,-1,0);
864879
TupleDescInitEntry(tupdesc, (AttrNumber)2,"sample_ts",
@@ -869,6 +884,13 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
869884
TEXTOID,-1,0);
870885
TupleDescInitEntry(tupdesc, (AttrNumber)5,"queryid",
871886
INT8OID,-1,0);
887+
TupleDescInitEntry(tupdesc, (AttrNumber)6,"isregularbackend",
888+
BOOLOID,-1,0),
889+
TupleDescInitEntry(tupdesc, (AttrNumber)7,"databaseid",
890+
OIDOID,-1,0),
891+
TupleDescInitEntry(tupdesc, (AttrNumber)8,"roleid",
892+
OIDOID,-1,0);
893+
872894
funcctx->tuple_desc=BlessTupleDesc(tupdesc);
873895

874896
MemoryContextSwitchTo(oldcontext);
@@ -883,8 +905,8 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
883905
{
884906
HeapTupletuple;
885907
HistoryItem*item;
886-
Datumvalues[5];
887-
boolnulls[5];
908+
Datumvalues[8];
909+
boolnulls[8];
888910
constchar*event_type,
889911
*event;
890912

@@ -908,6 +930,9 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
908930
nulls[3]= true;
909931

910932
values[4]=UInt64GetDatum(item->queryId);
933+
values[5]=BoolGetDatum(item->isRegularBackend);
934+
values[6]=ObjectIdGetDatum(item->databaseId);
935+
values[7]=ObjectIdGetDatum(item->roleId);
911936
tuple=heap_form_tuple(funcctx->tuple_desc,values,nulls);
912937

913938
history->index++;
@@ -1161,4 +1186,4 @@ pgws_ProcessUtility(PlannedStmt *pstmt,
11611186
PG_RE_THROW();
11621187
}
11631188
PG_END_TRY();
1164-
}
1189+
}

‎pg_wait_sampling.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ typedef struct
3434
intpid;
3535
uint32wait_event_info;
3636
uint64queryId;
37+
boolisRegularBackend;
38+
OiddatabaseId;
39+
OidroleId;
3740
TimestampTzts;
3841
}HistoryItem;
3942

@@ -78,4 +81,4 @@ extern bool pgws_should_sample_proc(PGPROC *proc, int *pid_p, uint32 *wait_event
7881
externvoidpgws_register_wait_collector(void);
7982
externPGDLLEXPORTvoidpgws_collector_main(Datummain_arg);
8083

81-
#endif
84+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp