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

Commit8f6f7e6

Browse files
Oleg Tselebrovskiyshinderuk
Oleg Tselebrovskiy
authored andcommitted
Store GUC variables in local process memory to avoid IPC shenanigans
For more context and reasoning see issue#85
1 parent28687a1 commit8f6f7e6

File tree

5 files changed

+118
-194
lines changed

5 files changed

+118
-194
lines changed

‎README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ If `pg_wait_sampling.sample_cpu` is set to true then processes that are not
158158
waiting on anything are also sampled. The wait event columns for such processes
159159
will be NULL.
160160

161-
These GUCs are allowed tobe changedby superuser. Also, they are placed into
162-
shared memory. Thus, they could be changed from any backend and affects worker
163-
runtime.
161+
Values of these GUC variables canbe changedonly in config file or with ALTER SYSTEM.
162+
Then you need to reload server's configuration (such as with pg_reload_conf function)
163+
for changes to take effect.
164164

165165
See
166166
[PostgreSQL documentation](http://www.postgresql.org/docs/devel/static/monitoring-stats.html#WAIT-EVENT-TABLE)

‎collector.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include"funcapi.h"
1717
#include"miscadmin.h"
1818
#include"postmaster/bgworker.h"
19+
#include"postmaster/interrupt.h"
1920
#include"storage/ipc.h"
2021
#include"storage/procarray.h"
2122
#include"storage/procsignal.h"
@@ -151,7 +152,7 @@ probe_waits(History *observations, HTAB *profile_hash,
151152
TimestampTzts=GetCurrentTimestamp();
152153

153154
/* Realloc waits history if needed */
154-
newSize=pgws_collector_hdr->historySize;
155+
newSize=pgws_historySize;
155156
if (observations->count!=newSize)
156157
realloc_history(observations,newSize);
157158

@@ -170,7 +171,7 @@ probe_waits(History *observations, HTAB *profile_hash,
170171
item.pid=proc->pid;
171172
item.wait_event_info=proc->wait_event_info;
172173

173-
if (pgws_collector_hdr->profileQueries)
174+
if (pgws_profileQueries)
174175
item.queryId=pgws_proc_queryids[i];
175176
else
176177
item.queryId=0;
@@ -289,7 +290,7 @@ make_profile_hash()
289290
hash_ctl.hash=tag_hash;
290291
hash_ctl.hcxt=TopMemoryContext;
291292

292-
if (pgws_collector_hdr->profileQueries)
293+
if (pgws_profileQueries)
293294
hash_ctl.keysize= offsetof(ProfileItem,count);
294295
else
295296
hash_ctl.keysize= offsetof(ProfileItem,queryId);
@@ -346,6 +347,7 @@ pgws_collector_main(Datum main_arg)
346347
* partitipate to the ProcSignal infrastructure.
347348
*/
348349
pqsignal(SIGTERM,handle_sigterm);
350+
pqsignal(SIGHUP,SignalHandlerForConfigReload);
349351
pqsignal(SIGUSR1,procsignal_sigusr1_handler);
350352
BackgroundWorkerUnblockSignals();
351353
InitPostgresCompat(NULL,InvalidOid,NULL,InvalidOid,0,NULL);
@@ -361,7 +363,7 @@ pgws_collector_main(Datum main_arg)
361363
collector_context=AllocSetContextCreate(TopMemoryContext,
362364
"pg_wait_sampling context",ALLOCSET_DEFAULT_SIZES);
363365
old_context=MemoryContextSwitchTo(collector_context);
364-
alloc_history(&observations,pgws_collector_hdr->historySize);
366+
alloc_history(&observations,pgws_historySize);
365367
MemoryContextSwitchTo(old_context);
366368

367369
ereport(LOG, (errmsg("pg_wait_sampling collector started")));
@@ -375,29 +377,31 @@ pgws_collector_main(Datum main_arg)
375377
shm_mq_handle*mqh;
376378
int64history_diff,
377379
profile_diff;
378-
inthistory_period,
379-
profile_period;
380380
boolwrite_history,
381381
write_profile;
382382

383383
/* We need an explicit call for at least ProcSignal notifications. */
384384
CHECK_FOR_INTERRUPTS();
385385

386+
if (ConfigReloadPending)
387+
{
388+
ConfigReloadPending= false;
389+
ProcessConfigFile(PGC_SIGHUP);
390+
}
391+
386392
/* Wait calculate time to next sample for history or profile */
387393
current_ts=GetCurrentTimestamp();
388394

389395
history_diff=millisecs_diff(history_ts,current_ts);
390396
profile_diff=millisecs_diff(profile_ts,current_ts);
391-
history_period=pgws_collector_hdr->historyPeriod;
392-
profile_period=pgws_collector_hdr->profilePeriod;
393397

394-
write_history= (history_diff >= (int64)history_period);
395-
write_profile= (profile_diff >= (int64)profile_period);
398+
write_history= (history_diff >= (int64)pgws_historyPeriod);
399+
write_profile= (profile_diff >= (int64)pgws_profilePeriod);
396400

397401
if (write_history||write_profile)
398402
{
399403
probe_waits(&observations,profile_hash,
400-
write_history,write_profile,pgws_collector_hdr->profilePid);
404+
write_history,write_profile,pgws_profilePid);
401405

402406
if (write_history)
403407
{
@@ -421,8 +425,8 @@ pgws_collector_main(Datum main_arg)
421425
* shared memory.
422426
*/
423427
rc=WaitLatch(&MyProc->procLatch,WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
424-
Min(history_period- (int)history_diff,
425-
profile_period- (int)profile_diff),PG_WAIT_EXTENSION);
428+
Min(pgws_historyPeriod- (int)history_diff,
429+
pgws_historyPeriod- (int)profile_diff),PG_WAIT_EXTENSION);
426430

427431
if (rc&WL_POSTMASTER_DEATH)
428432
proc_exit(1);

‎compat.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,4 @@ InitPostgresCompat(const char *in_dbname, Oid dboid,
5151
#endif
5252
}
5353

54-
staticinlinevoid
55-
get_guc_variables_compat(structconfig_generic***vars,int*num_vars)
56-
{
57-
Assert(vars!=NULL);
58-
Assert(num_vars!=NULL);
59-
60-
#ifPG_VERSION_NUM >=160000
61-
*vars=get_guc_variables(num_vars);
62-
#else
63-
*vars=get_guc_variables();
64-
*num_vars=GetNumConfigOptions();
65-
#endif
66-
}
67-
6854
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp