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

Commit3f1db99

Browse files
committed
Handle auxiliary processes in SQL functions of backend statistics
This commit impacts the following SQL functions, authorizing the accessto the PGPROC entries of auxiliary processes when attempting to fetch orreset backend-level pgstats entries:- pg_stat_reset_backend_stats()- pg_stat_get_backend_io()This is relevant sincea051e71 for at least the WAL summarizer, WALreceiver and WAL writer processes, that has changed the backendstatistics to authorize these three following the addition of WAL I/Ostatistics in pg_stat_io and backend statistics. The code is moreflexible with future changes written this way, adapting automatically toany updates done in pgstat_tracks_backend_bktype().While on it, pgstat_report_wal() gains a call to pgstat_flush_backend(),making sure that backend I/O statistics are updated when calling thisroutine. This makes the statistics report correctly for the WAL writer.WAL receiver and WAL summarizer do not call pgstat_report_wal() yet(spoiler: both should). It should be possible to lift some of theexisting restrictions for other auxiliary processes, as well, but thisis left as future work.Reported-by: Rahila Syed <rahilasyed90@gmail.com>Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>Discussion:https://postgr.es/m/CAH2L28v9BwN8_y0k6FQ591=0g2Hj_esHLGj3bP38c9nmVykoiA@mail.gmail.com
1 parentfe186bd commit3f1db99

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

‎src/backend/utils/activity/pgstat_backend.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ pgstat_fetch_stat_backend_by_pid(int pid, BackendType *bktype)
103103
if (bktype)
104104
*bktype=B_INVALID;
105105

106-
/*
107-
* This could be an auxiliary process but these do not report backend
108-
* statistics due to pgstat_tracks_backend_bktype(), so there is no need
109-
* for an extra call to AuxiliaryPidGetProc().
110-
*/
106+
/* this could be an auxiliary process */
107+
if (!proc)
108+
proc=AuxiliaryPidGetProc(pid);
109+
111110
if (!proc)
112111
returnNULL;
113112

@@ -117,6 +116,10 @@ pgstat_fetch_stat_backend_by_pid(int pid, BackendType *bktype)
117116
if (!beentry)
118117
returnNULL;
119118

119+
/* check if the backend type tracks statistics */
120+
if (!pgstat_tracks_backend_bktype(beentry->st_backendType))
121+
returnNULL;
122+
120123
backend_stats=pgstat_fetch_stat_backend(procNumber);
121124
if (!backend_stats)
122125
returnNULL;
@@ -125,10 +128,6 @@ pgstat_fetch_stat_backend_by_pid(int pid, BackendType *bktype)
125128
if (beentry->st_procpid!=pid)
126129
returnNULL;
127130

128-
/* backend may be gone, so recheck in case */
129-
if (beentry->st_backendType==B_INVALID)
130-
returnNULL;
131-
132131
if (bktype)
133132
*bktype=beentry->st_backendType;
134133

‎src/backend/utils/activity/pgstat_wal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pgstat_report_wal(bool force)
5555

5656
/* flush IO stats */
5757
pgstat_flush_io(nowait);
58+
(void)pgstat_flush_backend(nowait,PGSTAT_BACKEND_FLUSH_IO);
5859
}
5960

6061
/*

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,19 +1919,30 @@ Datum
19191919
pg_stat_reset_backend_stats(PG_FUNCTION_ARGS)
19201920
{
19211921
PGPROC*proc;
1922+
PgBackendStatus*beentry;
1923+
ProcNumberprocNumber;
19221924
intbackend_pid=PG_GETARG_INT32(0);
19231925

19241926
proc=BackendPidGetProc(backend_pid);
19251927

1926-
/*
1927-
* This could be an auxiliary process but these do not report backend
1928-
* statistics due to pgstat_tracks_backend_bktype(), so there is no need
1929-
* for an extra call to AuxiliaryPidGetProc().
1930-
*/
1928+
/* This could be an auxiliary process */
1929+
if (!proc)
1930+
proc=AuxiliaryPidGetProc(backend_pid);
1931+
19311932
if (!proc)
19321933
PG_RETURN_VOID();
19331934

1934-
pgstat_reset(PGSTAT_KIND_BACKEND,InvalidOid,GetNumberFromPGProc(proc));
1935+
procNumber=GetNumberFromPGProc(proc);
1936+
1937+
beentry=pgstat_get_beentry_by_proc_number(procNumber);
1938+
if (!beentry)
1939+
PG_RETURN_VOID();
1940+
1941+
/* Check if the backend type tracks statistics */
1942+
if (!pgstat_tracks_backend_bktype(beentry->st_backendType))
1943+
PG_RETURN_VOID();
1944+
1945+
pgstat_reset(PGSTAT_KIND_BACKEND,InvalidOid,procNumber);
19351946

19361947
PG_RETURN_VOID();
19371948
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp