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

Commit495864a

Browse files
committed
Refactor code of pg_stat_get_wal() building result tuple
This commit adds to pgstatfuncs.c a new routine calledpg_stat_wal_build_tuple(), helper routine for pg_stat_get_wal(). Thisis in charge of filling one tuple based on the contents ofPgStat_WalStats retrieved from pgstats.This refactoring will be used by an upcoming patch introducingbackend-level WAL statistics, simplifying the main patch. Note thatit is not possible for stats_reset to be NULL in pg_stat_wal; backendstatistics need to be able to handle this case.Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>Discussion:https://postgr.es/m/Z3zqc4o09dM/Ezyz@ip-10-97-1-34.eu-west-3.compute.internal
1 parent62ec3e1 commit495864a

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,21 +1632,23 @@ pg_stat_get_backend_io(PG_FUNCTION_ARGS)
16321632
}
16331633

16341634
/*
1635-
* Returns statistics of WAL activity
1635+
* pg_stat_wal_build_tuple
1636+
*
1637+
* Helper routine for pg_stat_get_wal() returning one tuple based on the
1638+
* contents of wal_counters.
16361639
*/
1637-
Datum
1638-
pg_stat_get_wal(PG_FUNCTION_ARGS)
1640+
staticDatum
1641+
pg_stat_wal_build_tuple(PgStat_WalCounterswal_counters,
1642+
TimestampTzstat_reset_timestamp)
16391643
{
1640-
#definePG_STAT_GET_WAL_COLS5
1644+
#definePG_STAT_WAL_COLS5
16411645
TupleDesctupdesc;
1642-
Datumvalues[PG_STAT_GET_WAL_COLS]= {0};
1643-
boolnulls[PG_STAT_GET_WAL_COLS]= {0};
1646+
Datumvalues[PG_STAT_WAL_COLS]= {0};
1647+
boolnulls[PG_STAT_WAL_COLS]= {0};
16441648
charbuf[256];
1645-
PgStat_WalStats*wal_stats;
1646-
PgStat_WalCounterswal_counters;
16471649

16481650
/* Initialise attributes information in the tuple descriptor */
1649-
tupdesc=CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
1651+
tupdesc=CreateTemplateTupleDesc(PG_STAT_WAL_COLS);
16501652
TupleDescInitEntry(tupdesc, (AttrNumber)1,"wal_records",
16511653
INT8OID,-1,0);
16521654
TupleDescInitEntry(tupdesc, (AttrNumber)2,"wal_fpi",
@@ -1660,10 +1662,6 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
16601662

16611663
BlessTupleDesc(tupdesc);
16621664

1663-
/* Get statistics about WAL activity */
1664-
wal_stats=pgstat_fetch_stat_wal();
1665-
wal_counters=wal_stats->wal_counters;
1666-
16671665
/* Fill values and NULLs */
16681666
values[0]=Int64GetDatum(wal_counters.wal_records);
16691667
values[1]=Int64GetDatum(wal_counters.wal_fpi);
@@ -1677,12 +1675,30 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
16771675

16781676
values[3]=Int64GetDatum(wal_counters.wal_buffers_full);
16791677

1680-
values[4]=TimestampTzGetDatum(wal_stats->stat_reset_timestamp);
1678+
if (stat_reset_timestamp!=0)
1679+
values[4]=TimestampTzGetDatum(stat_reset_timestamp);
1680+
else
1681+
nulls[4]= true;
16811682

16821683
/* Returns the record as Datum */
16831684
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc,values,nulls)));
16841685
}
16851686

1687+
/*
1688+
* Returns statistics of WAL activity
1689+
*/
1690+
Datum
1691+
pg_stat_get_wal(PG_FUNCTION_ARGS)
1692+
{
1693+
PgStat_WalStats*wal_stats;
1694+
1695+
/* Get statistics about WAL activity */
1696+
wal_stats=pgstat_fetch_stat_wal();
1697+
1698+
return (pg_stat_wal_build_tuple(wal_stats->wal_counters,
1699+
wal_stats->stat_reset_timestamp));
1700+
}
1701+
16861702
/*
16871703
* Returns statistics of SLRU caches.
16881704
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp