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

Commit2318d7b

Browse files
author
Alexander Korotkov
committed
Fix bug in memory allocation.
1 parente1a7772 commit2318d7b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

‎contrib/pg_stat_wait/collector.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ AllocHistory(History *observations, int count)
6161
void
6262
ReadCurrentWait(PGPROC*proc,HistoryItem*item)
6363
{
64+
CurrentWaitEvent*event;
6465
instr_timestartTime,currentTime;
66+
uint32previdx;
6567

6668
while (true)
6769
{
6870
CurrentWaitEventWrap*wrap;
69-
CurrentWaitEvent*event;
70-
uint32previdx;
71-
7271

7372
wrap=&cur_wait_events[proc->pgprocno];
7473
previdx=wrap->curidx;
@@ -138,6 +137,9 @@ write_waits_history(History *observations, TimestampTz current_ts)
138137

139138
ReadCurrentWait(proc,&item);
140139

140+
if (proc->pid==0)
141+
continue;
142+
141143
if (historySkipLatch&&item.classid==WAIT_LATCH)
142144
continue;
143145

‎contrib/pg_stat_wait/pg_stat_wait.c‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include"miscadmin.h"
77
#include"pg_stat_wait.h"
88
#include"port/atomics.h"
9+
#include"postmaster/autovacuum.h"
910
#include"storage/spin.h"
1011
#include"storage/ipc.h"
1112
#include"storage/procarray.h"
@@ -69,6 +70,24 @@ pgsw_shmem_size(void)
6970
returnsize;
7071
}
7172

73+
staticvoid
74+
init_current_wait_event()
75+
{
76+
inti;
77+
instr_timet;
78+
79+
INSTR_TIME_SET_CURRENT(t);
80+
for (i=0;i<maxProcs;i++)
81+
{
82+
CurrentWaitEventWrap*wrap=&cur_wait_events[i];
83+
84+
memset(wrap,0,sizeof(*wrap));
85+
wrap->data[0].start_time=t;
86+
wrap->data[1].start_time=t;
87+
}
88+
}
89+
90+
7291
/*
7392
* Distribute shared memory.
7493
*/
@@ -87,6 +106,7 @@ pgsw_shmem_startup(void)
87106

88107
cur_wait_events=shm_toc_allocate(toc,sizeof(CurrentWaitEventWrap)*maxProcs);
89108
shm_toc_insert(toc,0,cur_wait_events);
109+
init_current_wait_event();
90110

91111
if (waitsHistoryOn)
92112
{
@@ -220,7 +240,8 @@ _PG_init(void)
220240
&historySkipLatch, false,PGC_POSTMASTER,0,NULL,NULL,NULL);
221241

222242
/* Calculate maximem number of processes */
223-
maxProcs=MaxBackends+NUM_AUXILIARY_PROCS;
243+
maxProcs=MaxConnections+autovacuum_max_workers+1+
244+
max_worker_processes+NUM_AUXILIARY_PROCS;
224245

225246
/*
226247
* Request additional shared resources. (These are no-ops if we're not in
@@ -353,7 +374,6 @@ pg_stat_wait_get_current(PG_FUNCTION_ARGS)
353374
{
354375
PGPROC*proc=&ProcGlobal->allProcs[i];
355376

356-
elog(NOTICE,"%d %d",proc->pid,proc->pgprocno);
357377
if (proc!=NULL&&proc->pid!=0)
358378
{
359379
ReadCurrentWait(proc,&params->state[j]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp