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

Commita051e71

Browse files
committed
Add data for WAL in pg_stat_io and backend statistics
This commit adds WAL IO stats to both pg_stat_io view and per-backend IOstatistics (pg_stat_get_backend_io()). This change is possible sincef92c854, as WAL IO is not counted in blocks in some code pathswhere its stats data is measured (like WAL read in xlogreader.c).IOContext gains IOCONTEXT_INIT and IOObject IOOBJECT_WAL, with thefollowing combinations allowed:- IOOBJECT_WAL/IOCONTEXT_NORMAL is used to track I/O operations done onalready-created WAL segments.- IOOBJECT_WAL/IOCONTEXT_INIT is used for tracking I/O operations donewhen initializing WAL segments.The core changes are done in pg_stat_io.c, backend statistics inheritthem. Backend statistics and pg_stat_io are now available for the WALwriter, the WAL receiver and the WAL summarizer processes.I/O timing data is controlled by the GUC track_io_timing, like theexisting data of pg_stat_io for consistency. The timings related toIOOBJECT_WAL show up if the GUC is enabled (disabled by default).Bump pgstats file version, due to the additions in IOObject andIOContext, impacting the amount of data written for the fixed-numberedIO stats kind in the pgstats file.Author: Nazir Bilal YavuzReviewed-by: Bertrand Drouvot, Nitin Jadhav, Amit Kapila, MichaelPaquier, Melanie Plageman, Bharath RupireddyDiscussion:https://postgr.es/m/CAN55FZ3AiQ+ZMxUuXnBpd0Rrh1YhwJ5FudkHg=JU0P+-W8T4Vg@mail.gmail.com
1 parent622f678 commita051e71

File tree

9 files changed

+216
-38
lines changed

9 files changed

+216
-38
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,9 +2581,10 @@ description | Waiting for a newly initialized WAL file to reach durable storage
25812581
</para>
25822582

25832583
<para>
2584-
Currently, I/O on relations (e.g. tables, indexes) is tracked. However,
2585-
relation I/O which bypasses shared buffers (e.g. when moving a table from one
2586-
tablespace to another) is currently not tracked.
2584+
Currently, I/O on relations (e.g. tables, indexes) and WAL activity are
2585+
tracked. However, relation I/O which bypasses shared buffers
2586+
(e.g. when moving a table from one tablespace to another) is currently
2587+
not tracked.
25872588
</para>
25882589

25892590
<table id="pg-stat-io-view" xreflabel="pg_stat_io">
@@ -2636,6 +2637,11 @@ description | Waiting for a newly initialized WAL file to reach durable storage
26362637
<literal>temp relation</literal>: Temporary relations.
26372638
</para>
26382639
</listitem>
2640+
<listitem>
2641+
<para>
2642+
<literal>wal</literal>: Write Ahead Logs.
2643+
</para>
2644+
</listitem>
26392645
</itemizedlist>
26402646
</para>
26412647
</entry>
@@ -2660,6 +2666,13 @@ description | Waiting for a newly initialized WAL file to reach durable storage
26602666
<literal>normal</literal>.
26612667
</para>
26622668
</listitem>
2669+
<listitem>
2670+
<para>
2671+
<literal>init</literal>: I/O operations performed while creating the
2672+
WAL segments are tracked in <varname>context</varname>
2673+
<literal>init</literal>.
2674+
</para>
2675+
</listitem>
26632676
<listitem>
26642677
<para>
26652678
<literal>vacuum</literal>: I/O operations performed outside of shared

‎src/backend/access/transam/xlog.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,16 +2435,19 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
24352435
{
24362436
errno=0;
24372437

2438-
/* Measure I/O timing to write WAL data */
2439-
if (track_wal_io_timing)
2440-
INSTR_TIME_SET_CURRENT(start);
2441-
else
2442-
INSTR_TIME_SET_ZERO(start);
2438+
/*
2439+
* Measure I/O timing to write WAL data, for pg_stat_io and/or
2440+
* pg_stat_wal.
2441+
*/
2442+
start=pgstat_prepare_io_time(track_io_timing||track_wal_io_timing);
24432443

24442444
pgstat_report_wait_start(WAIT_EVENT_WAL_WRITE);
24452445
written=pg_pwrite(openLogFile,from,nleft,startoffset);
24462446
pgstat_report_wait_end();
24472447

2448+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_NORMAL,
2449+
IOOP_WRITE,start,1,written);
2450+
24482451
/*
24492452
* Increment the I/O timing and the number of times WAL data
24502453
* were written out to disk.
@@ -3216,6 +3219,7 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
32163219
intfd;
32173220
intsave_errno;
32183221
intopen_flags=O_RDWR |O_CREAT |O_EXCL |PG_BINARY;
3222+
instr_timeio_start;
32193223

32203224
Assert(logtli!=0);
32213225

@@ -3259,6 +3263,9 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
32593263
(errcode_for_file_access(),
32603264
errmsg("could not create file \"%s\": %m",tmppath)));
32613265

3266+
/* Measure I/O timing when initializing segment */
3267+
io_start=pgstat_prepare_io_time(track_io_timing);
3268+
32623269
pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_WRITE);
32633270
save_errno=0;
32643271
if (wal_init_zero)
@@ -3294,6 +3301,14 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
32943301
}
32953302
pgstat_report_wait_end();
32963303

3304+
/*
3305+
* A full segment worth of data is written when using wal_init_zero. One
3306+
* byte is written when not using it.
3307+
*/
3308+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_INIT,IOOP_WRITE,
3309+
io_start,1,
3310+
wal_init_zero ?wal_segment_size :1);
3311+
32973312
if (save_errno)
32983313
{
32993314
/*
@@ -3310,6 +3325,9 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
33103325
errmsg("could not write to file \"%s\": %m",tmppath)));
33113326
}
33123327

3328+
/* Measure I/O timing when flushing segment */
3329+
io_start=pgstat_prepare_io_time(track_io_timing);
3330+
33133331
pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_SYNC);
33143332
if (pg_fsync(fd)!=0)
33153333
{
@@ -3322,6 +3340,9 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
33223340
}
33233341
pgstat_report_wait_end();
33243342

3343+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_INIT,
3344+
IOOP_FSYNC,io_start,1,0);
3345+
33253346
if (close(fd)!=0)
33263347
ereport(ERROR,
33273348
(errcode_for_file_access(),
@@ -8696,11 +8717,11 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
86968717
wal_sync_method==WAL_SYNC_METHOD_OPEN_DSYNC)
86978718
return;
86988719

8699-
/* Measure I/O timing to sync the WAL file */
8700-
if (track_wal_io_timing)
8701-
INSTR_TIME_SET_CURRENT(start);
8702-
else
8703-
INSTR_TIME_SET_ZERO(start);
8720+
/*
8721+
* Measure I/O timing to sync the WAL file for pg_stat_io and/or
8722+
* pg_stat_wal.
8723+
*/
8724+
start=pgstat_prepare_io_time(track_io_timing||track_wal_io_timing);
87048725

87058726
pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC);
87068727
switch (wal_sync_method)
@@ -8757,6 +8778,9 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
87578778
INSTR_TIME_ACCUM_DIFF(PendingWalStats.wal_sync_time,end,start);
87588779
}
87598780

8781+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_NORMAL,IOOP_FSYNC,
8782+
start,1,0);
8783+
87608784
PendingWalStats.wal_sync++;
87618785
}
87628786

‎src/backend/access/transam/xlogreader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#ifndefFRONTEND
3737
#include"pgstat.h"
38+
#include"storage/bufmgr.h"
3839
#else
3940
#include"common/logging.h"
4041
#endif
@@ -1507,6 +1508,9 @@ WALRead(XLogReaderState *state,
15071508
char*p;
15081509
XLogRecPtrrecptr;
15091510
Sizenbytes;
1511+
#ifndefFRONTEND
1512+
instr_timeio_start;
1513+
#endif
15101514

15111515
p=buf;
15121516
recptr=startptr;
@@ -1552,6 +1556,9 @@ WALRead(XLogReaderState *state,
15521556
segbytes=nbytes;
15531557

15541558
#ifndefFRONTEND
1559+
/* Measure I/O timing when reading segment */
1560+
io_start=pgstat_prepare_io_time(track_io_timing);
1561+
15551562
pgstat_report_wait_start(WAIT_EVENT_WAL_READ);
15561563
#endif
15571564

@@ -1561,6 +1568,9 @@ WALRead(XLogReaderState *state,
15611568

15621569
#ifndefFRONTEND
15631570
pgstat_report_wait_end();
1571+
1572+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_NORMAL,IOOP_READ,
1573+
io_start,1,readbytes);
15641574
#endif
15651575

15661576
if (readbytes <=0)

‎src/backend/access/transam/xlogrecovery.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include"utils/datetime.h"
6161
#include"utils/fmgrprotos.h"
6262
#include"utils/guc_hooks.h"
63+
#include"utils/pgstat_internal.h"
6364
#include"utils/pg_lsn.h"
6465
#include"utils/ps_status.h"
6566
#include"utils/pg_rusage.h"
@@ -3306,6 +3307,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
33063307
uint32targetPageOff;
33073308
XLogSegNotargetSegNoPG_USED_FOR_ASSERTS_ONLY;
33083309
intr;
3310+
instr_timeio_start;
33093311

33103312
XLByteToSeg(targetPagePtr,targetSegNo,wal_segment_size);
33113313
targetPageOff=XLogSegmentOffset(targetPagePtr,wal_segment_size);
@@ -3398,6 +3400,9 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
33983400
/* Read the requested page */
33993401
readOff=targetPageOff;
34003402

3403+
/* Measure I/O timing when reading segment */
3404+
io_start=pgstat_prepare_io_time(track_io_timing);
3405+
34013406
pgstat_report_wait_start(WAIT_EVENT_WAL_READ);
34023407
r=pg_pread(readFile,readBuf,XLOG_BLCKSZ, (off_t)readOff);
34033408
if (r!=XLOG_BLCKSZ)
@@ -3406,6 +3411,10 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
34063411
intsave_errno=errno;
34073412

34083413
pgstat_report_wait_end();
3414+
3415+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_NORMAL,IOOP_READ,
3416+
io_start,1,r);
3417+
34093418
XLogFileName(fname,curFileTLI,readSegNo,wal_segment_size);
34103419
if (r<0)
34113420
{
@@ -3426,6 +3435,9 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
34263435
}
34273436
pgstat_report_wait_end();
34283437

3438+
pgstat_count_io_op_time(IOOBJECT_WAL,IOCONTEXT_NORMAL,IOOP_READ,
3439+
io_start,1,r);
3440+
34293441
Assert(targetSegNo==readSegNo);
34303442
Assert(targetPageOff==readOff);
34313443
Assert(reqLen <=readLen);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,6 @@ pgstat_tracks_backend_bktype(BackendType bktype)
236236
caseB_DEAD_END_BACKEND:
237237
caseB_ARCHIVER:
238238
caseB_LOGGER:
239-
caseB_WAL_RECEIVER:
240-
caseB_WAL_WRITER:
241-
caseB_WAL_SUMMARIZER:
242239
caseB_BG_WRITER:
243240
caseB_CHECKPOINTER:
244241
caseB_STARTUP:
@@ -249,7 +246,10 @@ pgstat_tracks_backend_bktype(BackendType bktype)
249246
caseB_BG_WORKER:
250247
caseB_STANDALONE_BACKEND:
251248
caseB_SLOTSYNC_WORKER:
249+
caseB_WAL_RECEIVER:
252250
caseB_WAL_SENDER:
251+
caseB_WAL_SUMMARIZER:
252+
caseB_WAL_WRITER:
253253
return true;
254254
}
255255

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp