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

Commit8e6e19d

Browse files
author
Alexander Korotkov
committed
Various fixes in GUCs, shared memory and background worker.
1 parentdf5e01d commit8e6e19d

File tree

2 files changed

+97
-19
lines changed

2 files changed

+97
-19
lines changed

‎contrib/pg_stat_wait/collector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ RegisterWaitsCollector(void)
4646
worker.bgw_flags=BGWORKER_SHMEM_ACCESS |
4747
BGWORKER_BACKEND_DATABASE_CONNECTION;
4848
worker.bgw_start_time=BgWorkerStart_ConsistentState;
49-
worker.bgw_restart_time=BGW_NEVER_RESTART;
49+
worker.bgw_restart_time=0;
5050
worker.bgw_main=collector_main;
5151
worker.bgw_notify_pid=0;
5252
snprintf(worker.bgw_name,BGW_MAXLEN,"pg_stat_wait collector");

‎contrib/pg_stat_wait/pg_stat_wait.c

Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include"storage/shm_toc.h"
2525
#include"utils/datetime.h"
2626
#include"utils/guc.h"
27+
#include"utils/guc_tables.h"
2728
#include"utils/wait.h"
2829

2930
PG_MODULE_MAGIC;
@@ -121,6 +122,80 @@ shmem_bool_guc_check_hook(bool *newval, void **extra, GucSource source)
121122
return true;
122123
}
123124

125+
/*
126+
* This union allows us to mix the numerous different types of structs
127+
* that we are organizing.
128+
*/
129+
typedefunion
130+
{
131+
structconfig_genericgeneric;
132+
structconfig_bool_bool;
133+
structconfig_realreal;
134+
structconfig_intinteger;
135+
structconfig_stringstring;
136+
structconfig_enum_enum;
137+
}mixedStruct;
138+
139+
staticvoid
140+
set_history_gucs()
141+
{
142+
structconfig_generic**guc_vars;
143+
intnumOpts,
144+
i;
145+
boolhistory_size_found= false,
146+
history_period_found= false,
147+
history_skip_latch_found= false;
148+
149+
/* Initialize the guc_variables[] array */
150+
build_guc_variables();
151+
152+
guc_vars=get_guc_variables();
153+
numOpts=GetNumConfigOptions();
154+
155+
for (i=0;i<numOpts;i++)
156+
{
157+
mixedStruct*var= (mixedStruct*)guc_vars[i];
158+
constchar*name=var->generic.name;
159+
160+
if (!strcmp(name,"pg_stat_wait.history_size"))
161+
{
162+
history_size_found= true;
163+
var->integer.variable=&collector_hdr->historySize;
164+
}
165+
elseif (!strcmp(name,"pg_stat_wait.history_period"))
166+
{
167+
history_period_found= true;
168+
var->integer.variable=&collector_hdr->historyPeriod;
169+
}
170+
elseif (!strcmp(name,"pg_stat_wait.history_skip_latch"))
171+
{
172+
history_skip_latch_found= true;
173+
var->_bool.variable=&collector_hdr->historySkipLatch;
174+
}
175+
}
176+
177+
if (!history_size_found)
178+
DefineCustomIntVariable("pg_stat_wait.history_size",
179+
"Sets size of waits history.",NULL,
180+
&collector_hdr->historySize,5000,100,INT_MAX,
181+
PGC_SUSET,GUC_CUSTOM_PLACEHOLDER,
182+
shmem_int_guc_check_hook,NULL,NULL);
183+
184+
if (!history_period_found)
185+
DefineCustomIntVariable("pg_stat_wait.history_period",
186+
"Sets period of waits history sampling.",NULL,
187+
&collector_hdr->historyPeriod,10,1,INT_MAX,
188+
PGC_SUSET,GUC_CUSTOM_PLACEHOLDER,
189+
shmem_int_guc_check_hook,NULL,NULL);
190+
191+
if (!history_skip_latch_found)
192+
DefineCustomBoolVariable("pg_stat_wait.history_skip_latch",
193+
"Skip latch events in waits history",NULL,
194+
&collector_hdr->historySkipLatch, false,
195+
PGC_SUSET,GUC_CUSTOM_PLACEHOLDER,
196+
shmem_bool_guc_check_hook,NULL,NULL);
197+
}
198+
124199
/*
125200
* Distribute shared memory.
126201
*/
@@ -155,6 +230,7 @@ pgsw_shmem_startup(void)
155230
shm_toc_insert(toc,3,collector_hdr);
156231
collector_mq=shm_toc_allocate(toc,COLLECTOR_QUEUE_SIZE);
157232
shm_toc_insert(toc,4,collector_mq);
233+
set_history_gucs();
158234
}
159235
}
160236
else
@@ -172,24 +248,6 @@ pgsw_shmem_startup(void)
172248
}
173249
}
174250

175-
if (waitsHistoryOn)
176-
{
177-
DefineCustomIntVariable("pg_stat_wait.history_size",
178-
"Sets size of waits history.",NULL,
179-
&collector_hdr->historySize,5000,100,INT_MAX,
180-
PGC_SUSET,0,shmem_int_guc_check_hook,NULL,NULL);
181-
182-
DefineCustomIntVariable("pg_stat_wait.history_period",
183-
"Sets period of waits history sampling.",NULL,
184-
&collector_hdr->historyPeriod,10,1,INT_MAX,
185-
PGC_SUSET,0,shmem_int_guc_check_hook,NULL,NULL);
186-
187-
DefineCustomBoolVariable("pg_stat_wait.history_skip_latch",
188-
"Skip latch events in waits history",NULL,
189-
&collector_hdr->historySkipLatch, false,
190-
PGC_SUSET,0,shmem_bool_guc_check_hook,NULL,NULL);
191-
}
192-
193251
shmem_initialized= true;
194252

195253
if (prev_shmem_startup_hook)
@@ -523,6 +581,8 @@ pg_stat_wait_get_current(PG_FUNCTION_ARGS)
523581
FuncCallContext*funcctx;
524582
WaitCurrentContext*params;
525583

584+
check_shmem();
585+
526586
if (SRF_IS_FIRSTCALL())
527587
{
528588
MemoryContextoldcontext;
@@ -641,6 +701,8 @@ pg_stat_wait_get_profile(PG_FUNCTION_ARGS)
641701
WaitProfileContext*params;
642702
FuncCallContext*funcctx;
643703

704+
check_shmem();
705+
644706
if (SRF_IS_FIRSTCALL())
645707
{
646708
MemoryContextoldcontext;
@@ -755,6 +817,8 @@ pg_stat_wait_reset_profile(PG_FUNCTION_ARGS)
755817
{
756818
inti;
757819

820+
check_shmem();
821+
758822
for (i=0;i<maxProcs*WAIT_EVENTS_COUNT;i++)
759823
{
760824
profile[i].count=0;
@@ -835,6 +899,10 @@ pg_stat_wait_get_history(PG_FUNCTION_ARGS)
835899
mq=shm_mq_create(collector_mq,COLLECTOR_QUEUE_SIZE);
836900
collector_hdr->request=HISTORY_REQUEST;
837901

902+
if (!collector_hdr->latch)
903+
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
904+
errmsg("pg_stat_wait collector wasn't started")));
905+
838906
SetLatch(collector_hdr->latch);
839907

840908
shm_mq_set_receiver(mq,MyProc);
@@ -908,6 +976,8 @@ pg_start_trace(PG_FUNCTION_ARGS)
908976
TraceInfo*traceItem;
909977
char*filename=PG_GETARG_CSTRING(1);
910978

979+
check_shmem();
980+
911981
if (strlen(filename)>WAIT_TRACE_FN_LEN)
912982
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
913983
errmsg("length of filename limited to %d",WAIT_TRACE_FN_LEN)));
@@ -949,6 +1019,8 @@ pg_is_in_trace(PG_FUNCTION_ARGS)
9491019
intprocno;
9501020
TraceInfo*traceItem;
9511021

1022+
check_shmem();
1023+
9521024
if (PG_ARGISNULL(0))
9531025
{
9541026
procno=MyProc->pgprocno;
@@ -973,6 +1045,8 @@ pg_stop_trace(PG_FUNCTION_ARGS)
9731045
intprocno;
9741046
TraceInfo*traceItem;
9751047

1048+
check_shmem();
1049+
9761050
if (PG_ARGISNULL(0))
9771051
{
9781052
procno=MyProc->pgprocno;
@@ -1008,6 +1082,8 @@ pg_stat_wait_start_wait(PG_FUNCTION_ARGS)
10081082
intp4=PG_GETARG_INT32(5);
10091083
intp5=PG_GETARG_INT32(6);
10101084

1085+
check_shmem();
1086+
10111087
WAIT_START(classId,eventId,p1,p2,p3,p4,p5);
10121088
PG_RETURN_VOID();
10131089
}
@@ -1017,6 +1093,8 @@ PG_FUNCTION_INFO_V1(pg_stat_wait_stop_wait);
10171093
Datum
10181094
pg_stat_wait_stop_wait(PG_FUNCTION_ARGS)
10191095
{
1096+
check_shmem();
1097+
10201098
WAIT_STOP();
10211099
PG_RETURN_VOID();
10221100
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp