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

Commite1013f9

Browse files
akorotkovAlexander Korotkov
authored and
Alexander Korotkov
committed
Allow parameters online change.
1 parent8b63d50 commite1013f9

File tree

3 files changed

+99
-49
lines changed

3 files changed

+99
-49
lines changed

‎contrib/pg_stat_wait/collector.c

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include"miscadmin.h"
77
#include"postmaster/bgworker.h"
88
#include"storage/ipc.h"
9+
#include"storage/pg_shmem.h"
910
#include"storage/procarray.h"
1011
#include"storage/procsignal.h"
1112
#include"storage/s_lock.h"
@@ -27,10 +28,6 @@ shm_toc *toc;
2728
shm_mq*mq;
2829
staticvolatilesig_atomic_tshutdown_requested= false;
2930

30-
inthistorySize;
31-
inthistoryPeriod;
32-
boolhistorySkipLatch;
33-
3431
staticvoidhandle_sigterm(SIGNAL_ARGS);
3532
staticvoidcollector_main(Datummain_arg);
3633

@@ -52,6 +49,22 @@ CollectorShmemSize(void)
5249
returnsize;
5350
}
5451

52+
staticbool
53+
shmem_int_guc_check_hook(int*newval,void**extra,GucSourcesource)
54+
{
55+
if (UsedShmemSegAddr==NULL)
56+
return false;
57+
return true;
58+
}
59+
60+
staticbool
61+
shmem_bool_guc_check_hook(bool*newval,void**extra,GucSourcesource)
62+
{
63+
if (UsedShmemSegAddr==NULL)
64+
return false;
65+
return true;
66+
}
67+
5568
CollectorShmqHeader*
5669
GetCollectorMem(boolinit)
5770
{
@@ -75,6 +88,21 @@ GetCollectorMem(bool init)
7588

7689
mq_mem=shm_toc_allocate(toc,COLLECTOR_QUEUE_SIZE);
7790
shm_toc_insert(toc,1,mq_mem);
91+
92+
DefineCustomIntVariable("pg_stat_wait.history_size",
93+
"Sets size of waits history.",NULL,
94+
&hdr->historySize,5000,100,INT_MAX,
95+
PGC_SUSET,0,shmem_int_guc_check_hook,NULL,NULL);
96+
97+
DefineCustomIntVariable("pg_stat_wait.history_period",
98+
"Sets period of waits history sampling.",NULL,
99+
&hdr->historyPeriod,10,1,INT_MAX,
100+
PGC_SUSET,0,shmem_int_guc_check_hook,NULL,NULL);
101+
102+
DefineCustomBoolVariable("pg_stat_wait.history_skip_latch",
103+
"Skip latch events in waits history",NULL,
104+
&hdr->historySkipLatch, false,
105+
PGC_SUSET,0,shmem_bool_guc_check_hook,NULL,NULL);
78106
}
79107
else
80108
{
@@ -110,6 +138,39 @@ AllocHistory(History *observations, int count)
110138
observations->wraparound= false;
111139
}
112140

141+
staticvoid
142+
ReallocHistory(History*observations,intcount)
143+
{
144+
HistoryItem*newitems;
145+
intcopyCount;
146+
inti,j;
147+
148+
newitems= (HistoryItem*)palloc0(sizeof(HistoryItem)*count);
149+
150+
if (observations->wraparound)
151+
copyCount=Min(observations->count,count);
152+
else
153+
copyCount=observations->index;
154+
155+
i=0;
156+
j=observations->index;
157+
while (i<copyCount)
158+
{
159+
j--;
160+
if (j<0)
161+
j=observations->count-1;
162+
memcpy(&newitems[i],&observations->items[j],sizeof(HistoryItem));
163+
i++;
164+
}
165+
166+
pfree(observations->items);
167+
observations->items=newitems;
168+
169+
observations->index=copyCount;
170+
observations->count=count;
171+
observations->wraparound= false;
172+
}
173+
113174
/* Read current wait information from proc, if readCurrent is true,
114175
* then it reads from currently going wait, and can be inconsistent
115176
*/
@@ -167,7 +228,11 @@ get_next_observation(History *observations)
167228
staticvoid
168229
write_waits_history(History*observations,TimestampTzcurrent_ts)
169230
{
170-
inti;
231+
inti,newSize;
232+
233+
newSize=hdr->historySize;
234+
if (observations->count!=newSize)
235+
ReallocHistory(observations,newSize);
171236

172237
LWLockAcquire(ProcArrayLock,LW_SHARED);
173238
for (i=0;i<ProcGlobal->allProcCount;++i)
@@ -181,7 +246,7 @@ write_waits_history(History *observations, TimestampTz current_ts)
181246

182247
if (stateOk)
183248
{
184-
if (historySkipLatch&&item.classId==WAIT_LATCH)
249+
if (hdr->historySkipLatch&&item.classId==WAIT_LATCH)
185250
continue;
186251

187252
item.ts=current_ts;
@@ -237,7 +302,7 @@ collector_main(Datum main_arg)
237302
ALLOCSET_DEFAULT_INITSIZE,
238303
ALLOCSET_DEFAULT_MAXSIZE);
239304
old_context=MemoryContextSwitchTo(collector_context);
240-
AllocHistory(&observations,historySize);
305+
AllocHistory(&observations,hdr->historySize);
241306
MemoryContextSwitchTo(old_context);
242307

243308
while (1)
@@ -254,7 +319,7 @@ collector_main(Datum main_arg)
254319

255320
rc=WaitLatch(&MyProc->procLatch,
256321
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
257-
historyPeriod);
322+
hdr->historyPeriod);
258323

259324
if (rc&WL_POSTMASTER_DEATH)
260325
exit(1);

‎contrib/pg_stat_wait/pg_stat_wait.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,12 @@ _PG_init(void)
5050
DefineCustomBoolVariable("pg_stat_wait.history","Collect waits history",
5151
NULL,&WaitsHistoryOn, false,PGC_POSTMASTER,0,NULL,NULL,NULL);
5252

53-
DefineCustomIntVariable("pg_stat_wait.history_size",
54-
"Sets size of waits history.",NULL,
55-
&historySize,5000,100,INT_MAX,
56-
PGC_POSTMASTER,0,NULL,NULL,NULL);
57-
58-
DefineCustomIntVariable("pg_stat_wait.history_period",
59-
"Sets period of waits history sampling.",NULL,
60-
&historyPeriod,10,1,INT_MAX,
61-
PGC_POSTMASTER,0,NULL,NULL,NULL);
62-
63-
DefineCustomBoolVariable("pg_stat_wait.history_skip_latch",
64-
"Skip latch events in waits history",NULL,
65-
&historySkipLatch, false,PGC_POSTMASTER,0,NULL,NULL,NULL);
66-
6753
if (WaitsHistoryOn)
6854
{
6955
/*
7056
* Request additional shared resources. (These are no-ops if we're not in
7157
* the postmaster process.) We'll allocate or attach to the shared
72-
* resources inpgss_shmem_startup().
58+
* resources inpgsw_shmem_startup().
7359
*/
7460
RequestAddinShmemSpace(CollectorShmemSize());
7561
RegisterWaitsCollector();

‎contrib/pg_stat_wait/pg_stat_wait.h

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,44 @@
1212

1313
typedefstruct
1414
{
15-
uint32backendPid;
16-
boolreset;
17-
intbackendIdx;
18-
intclassIdx;
19-
inteventIdx;
15+
uint32backendPid;
16+
boolreset;
17+
intbackendIdx;
18+
intclassIdx;
19+
inteventIdx;
2020
}WaitProfileContext;
2121

2222
typedefstruct
2323
{
24-
intclass_cnt;
25-
intevent_cnt;
24+
intclass_cnt;
25+
intevent_cnt;
2626
}WaitEventContext;
2727

2828
typedefstruct
2929
{
30-
intclassId;
31-
inteventId;
32-
intparams[WAIT_PARAMS_COUNT];
33-
intbackendPid;
34-
uint64waitTime;
30+
intclassId;
31+
inteventId;
32+
intparams[WAIT_PARAMS_COUNT];
33+
intbackendPid;
34+
uint64waitTime;
3535

3636
TimestampTzts;
3737
}HistoryItem;
3838

3939
typedefstruct
4040
{
41-
intidx;
42-
HistoryItem*state;
43-
booldone;
44-
TimestampTzts;
41+
intidx;
42+
HistoryItem*state;
43+
booldone;
44+
TimestampTzts;
4545
}WaitCurrentContext;
4646

4747
typedefstruct
4848
{
49-
boolwraparound;
50-
intindex;
51-
intcount;
52-
HistoryItem*items;
49+
boolwraparound;
50+
intindex;
51+
intcount;
52+
HistoryItem*items;
5353
}History;
5454

5555
typedefenum
@@ -60,19 +60,18 @@ typedef enum
6060

6161
typedefstruct
6262
{
63-
Latch*latch;
64-
SHMRequestrequest;
63+
Latch*latch;
64+
SHMRequestrequest;
65+
inthistorySize;
66+
inthistoryPeriod;
67+
boolhistorySkipLatch;
6568
}CollectorShmqHeader;
6669

6770
externPGDLLIMPORTchar*WAIT_LOCK_NAMES[];
6871
externPGDLLIMPORTchar*WAIT_LWLOCK_NAMES[];
6972
externPGDLLIMPORTchar*WAIT_IO_NAMES[];
7073
externPGDLLIMPORTchar*WAIT_NETWORK_NAMES[];
7174
externPGDLLIMPORTconstintWAIT_OFFSETS[];
72-
externPGDLLIMPORTinthistorySize;
73-
externPGDLLIMPORTinthistoryPeriod;
74-
externPGDLLIMPORTboolhistorySkipLatch;
75-
7675

7776
SizeCollectorShmemSize(void);
7877
CollectorShmqHeader*GetCollectorMem(boolinit);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp