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

Commitf9a09aa

Browse files
committed
Add wal_fpi_bytes to pg_stat_wal and pg_stat_get_backend_wal()
This new counter, called "wal_fpi_bytes", tracks the total amount inbytes of full page images (FPIs) generated in WAL. This data becomesavailable globally via pg_stat_wal, and for backend statistics viapg_stat_get_backend_wal().Previously, this information could only be retrieved with pg_waldump orpg_walinspect, which may not be available depending on the environment,and are expensive to execute. It offers hints about how much FPIsimpact the WAL generated, which could be a large percentage for someworkloads, as well as the effects of wal_compression or page holes.Bump catalog version.Bump PGSTAT_FILE_FORMAT_ID, due to the addition of wal_fpi_bytes inPgStat_WalCounters.Author: Shinya Kato <shinya11.kato@gmail.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/CAOzEurQtZEAfg6P0kU3Wa-f9BWQOi0RzJEMPN56wNTOmJLmfaQ@mail.gmail.com
1 parent3e8e055 commitf9a09aa

File tree

12 files changed

+46
-15
lines changed

12 files changed

+46
-15
lines changed

‎doc/src/sgml/monitoring.sgml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,15 @@ description | Waiting for a newly initialized WAL file to reach durable storage
33233323
</para></entry>
33243324
</row>
33253325

3326+
<row>
3327+
<entry role="catalog_table_entry"><para role="column_definition">
3328+
<structfield>wal_fpi_bytes</structfield> <type>numeric</type>
3329+
</para>
3330+
<para>
3331+
Total amount of WAL full page images in bytes
3332+
</para></entry>
3333+
</row>
3334+
33263335
<row>
33273336
<entry role="catalog_table_entry"><para role="column_definition">
33283337
<structfield>wal_buffers_full</structfield> <type>bigint</type>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
#include"access/xloginsert.h"
3434
#include"catalog/pg_control.h"
3535
#include"common/pg_lzcompress.h"
36+
#include"executor/instrument.h"
3637
#include"miscadmin.h"
3738
#include"pg_trace.h"
3839
#include"replication/origin.h"
3940
#include"storage/bufmgr.h"
4041
#include"storage/proc.h"
4142
#include"utils/memutils.h"
43+
#include"utils/pgstat_internal.h"
4244

4345
/*
4446
* Guess the maximum buffer size required to store a compressed version of
@@ -796,6 +798,10 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
796798
}
797799

798800
total_len+=bimg.length;
801+
802+
/* Track the WAL full page images in bytes */
803+
pgWalUsage.wal_fpi_bytes+=bimg.length;
804+
pgstat_report_fixed= true;
799805
}
800806

801807
if (needs_data)

‎src/backend/catalog/system_views.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ CREATE VIEW pg_stat_wal AS
12211221
w.wal_records,
12221222
w.wal_fpi,
12231223
w.wal_bytes,
1224+
w.wal_fpi_bytes,
12241225
w.wal_buffers_full,
12251226
w.stats_reset
12261227
FROM pg_stat_get_wal() w;

‎src/backend/executor/instrument.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ WalUsageAdd(WalUsage *dst, WalUsage *add)
280280
dst->wal_bytes+=add->wal_bytes;
281281
dst->wal_records+=add->wal_records;
282282
dst->wal_fpi+=add->wal_fpi;
283+
dst->wal_fpi_bytes+=add->wal_fpi_bytes;
283284
dst->wal_buffers_full+=add->wal_buffers_full;
284285
}
285286

@@ -289,5 +290,6 @@ WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
289290
dst->wal_bytes+=add->wal_bytes-sub->wal_bytes;
290291
dst->wal_records+=add->wal_records-sub->wal_records;
291292
dst->wal_fpi+=add->wal_fpi-sub->wal_fpi;
293+
dst->wal_fpi_bytes+=add->wal_fpi_bytes-sub->wal_fpi_bytes;
292294
dst->wal_buffers_full+=add->wal_buffers_full-sub->wal_buffers_full;
293295
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pgstat_flush_backend_entry_wal(PgStat_EntryRef *entry_ref)
252252
WALSTAT_ACC(wal_records,wal_usage_diff);
253253
WALSTAT_ACC(wal_fpi,wal_usage_diff);
254254
WALSTAT_ACC(wal_bytes,wal_usage_diff);
255+
WALSTAT_ACC(wal_fpi_bytes,wal_usage_diff);
255256
#undef WALSTAT_ACC
256257

257258
/*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pgstat_wal_flush_cb(bool nowait)
121121
WALSTAT_ACC(wal_records,wal_usage_diff);
122122
WALSTAT_ACC(wal_fpi,wal_usage_diff);
123123
WALSTAT_ACC(wal_bytes,wal_usage_diff);
124+
WALSTAT_ACC(wal_fpi_bytes,wal_usage_diff);
124125
WALSTAT_ACC(wal_buffers_full,wal_usage_diff);
125126
#undef WALSTAT_ACC
126127

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ static Datum
16371637
pg_stat_wal_build_tuple(PgStat_WalCounterswal_counters,
16381638
TimestampTzstat_reset_timestamp)
16391639
{
1640-
#definePG_STAT_WAL_COLS5
1640+
#definePG_STAT_WAL_COLS6
16411641
TupleDesctupdesc;
16421642
Datumvalues[PG_STAT_WAL_COLS]= {0};
16431643
boolnulls[PG_STAT_WAL_COLS]= {0};
@@ -1651,9 +1651,11 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
16511651
INT8OID,-1,0);
16521652
TupleDescInitEntry(tupdesc, (AttrNumber)3,"wal_bytes",
16531653
NUMERICOID,-1,0);
1654-
TupleDescInitEntry(tupdesc, (AttrNumber)4,"wal_buffers_full",
1654+
TupleDescInitEntry(tupdesc, (AttrNumber)4,"wal_fpi_bytes",
1655+
NUMERICOID,-1,0);
1656+
TupleDescInitEntry(tupdesc, (AttrNumber)5,"wal_buffers_full",
16551657
INT8OID,-1,0);
1656-
TupleDescInitEntry(tupdesc, (AttrNumber)5,"stats_reset",
1658+
TupleDescInitEntry(tupdesc, (AttrNumber)6,"stats_reset",
16571659
TIMESTAMPTZOID,-1,0);
16581660

16591661
BlessTupleDesc(tupdesc);
@@ -1669,12 +1671,18 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
16691671
ObjectIdGetDatum(0),
16701672
Int32GetDatum(-1));
16711673

1672-
values[3]=Int64GetDatum(wal_counters.wal_buffers_full);
1674+
snprintf(buf,sizeofbuf,UINT64_FORMAT,wal_counters.wal_fpi_bytes);
1675+
values[3]=DirectFunctionCall3(numeric_in,
1676+
CStringGetDatum(buf),
1677+
ObjectIdGetDatum(0),
1678+
Int32GetDatum(-1));
1679+
1680+
values[4]=Int64GetDatum(wal_counters.wal_buffers_full);
16731681

16741682
if (stat_reset_timestamp!=0)
1675-
values[4]=TimestampTzGetDatum(stat_reset_timestamp);
1683+
values[5]=TimestampTzGetDatum(stat_reset_timestamp);
16761684
else
1677-
nulls[4]= true;
1685+
nulls[5]= true;
16781686

16791687
/* Returns the record as Datum */
16801688
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc,values,nulls)));

‎src/include/catalog/catversion.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#defineCATALOG_VERSION_NO202510221
60+
#defineCATALOG_VERSION_NO202510281
6161

6262
#endif

‎src/include/catalog/pg_proc.dat‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6029,16 +6029,16 @@
60296029
{ oid => '1136', descr => 'statistics: information about WAL activity',
60306030
proname => 'pg_stat_get_wal', proisstrict => 'f', provolatile => 's',
60316031
proparallel => 'r', prorettype => 'record', proargtypes => '',
6032-
proallargtypes => '{int8,int8,numeric,int8,timestamptz}',
6033-
proargmodes => '{o,o,o,o,o}',
6034-
proargnames => '{wal_records,wal_fpi,wal_bytes,wal_buffers_full,stats_reset}',
6032+
proallargtypes => '{int8,int8,numeric,numeric,int8,timestamptz}',
6033+
proargmodes => '{o,o,o,o,o,o}',
6034+
proargnames => '{wal_records,wal_fpi,wal_bytes,wal_fpi_bytes,wal_buffers_full,stats_reset}',
60356035
prosrc => 'pg_stat_get_wal' },
60366036
{ oid => '6313', descr => 'statistics: backend WAL activity',
60376037
proname => 'pg_stat_get_backend_wal', provolatile => 'v', proparallel => 'r',
60386038
prorettype => 'record', proargtypes => 'int4',
6039-
proallargtypes => '{int4,int8,int8,numeric,int8,timestamptz}',
6040-
proargmodes => '{i,o,o,o,o,o}',
6041-
proargnames => '{backend_pid,wal_records,wal_fpi,wal_bytes,wal_buffers_full,stats_reset}',
6039+
proallargtypes => '{int4,int8,int8,numeric,numeric,int8,timestamptz}',
6040+
proargmodes => '{i,o,o,o,o,o,o}',
6041+
proargnames => '{backend_pid,wal_records,wal_fpi,wal_bytes,wal_fpi_bytes,wal_buffers_full,stats_reset}',
60426042
prosrc => 'pg_stat_get_backend_wal' },
60436043
{ oid => '6248', descr => 'statistics: information about WAL prefetching',
60446044
proname => 'pg_stat_get_recovery_prefetch', prorows => '1', proretset => 't',

‎src/include/executor/instrument.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef struct WalUsage
5353
int64wal_records;/* # of WAL records produced */
5454
int64wal_fpi;/* # of WAL full page images produced */
5555
uint64wal_bytes;/* size of WAL records produced */
56+
uint64wal_fpi_bytes;/* size of WAL full page images produced */
5657
int64wal_buffers_full;/* # of times the WAL buffers became full */
5758
}WalUsage;
5859

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp