Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0e42d31

Browse files
committed
Adding new PgStat_WalCounters structure in pgstat.h
This new structure contains the counters and the data related to the WAL activity statistics gathered from WalUsage, separated into its own structure so as it can be shared across more than one Stats structure in pg_stat.h. This refactoring will be used by an upcoming patch introducing backend-level WAL statistics. Bump PGSTAT_FILE_FORMAT_ID. 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 parent d7cbeaf commit 0e42d31

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

src/backend/utils/activity/pgstat_wal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pgstat_wal_flush_cb(bool nowait)
106106
return true;
107107

108108
#define WALSTAT_ACC(fld, var_to_add) \
109-
(stats_shmem->stats.fld += var_to_add.fld)
109+
(stats_shmem->stats.wal_counters.fld += var_to_add.fld)
110110
WALSTAT_ACC(wal_records, wal_usage_diff);
111111
WALSTAT_ACC(wal_fpi, wal_usage_diff);
112112
WALSTAT_ACC(wal_bytes, wal_usage_diff);

src/backend/utils/adt/pgstatfuncs.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
16431643
bool nulls[PG_STAT_GET_WAL_COLS] = {0};
16441644
char buf[256];
16451645
PgStat_WalStats *wal_stats;
1646+
PgStat_WalCounters wal_counters;
16461647

16471648
/* Initialise attributes information in the tuple descriptor */
16481649
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
@@ -1661,19 +1662,20 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
16611662

16621663
/* Get statistics about WAL activity */
16631664
wal_stats = pgstat_fetch_stat_wal();
1665+
wal_counters = wal_stats->wal_counters;
16641666

16651667
/* Fill values and NULLs */
1666-
values[0] = Int64GetDatum(wal_stats->wal_records);
1667-
values[1] = Int64GetDatum(wal_stats->wal_fpi);
1668+
values[0] = Int64GetDatum(wal_counters.wal_records);
1669+
values[1] = Int64GetDatum(wal_counters.wal_fpi);
16681670

16691671
/* Convert to numeric. */
1670-
snprintf(buf, sizeof buf, UINT64_FORMAT, wal_stats->wal_bytes);
1672+
snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_bytes);
16711673
values[2] = DirectFunctionCall3(numeric_in,
16721674
CStringGetDatum(buf),
16731675
ObjectIdGetDatum(0),
16741676
Int32GetDatum(-1));
16751677

1676-
values[3] = Int64GetDatum(wal_stats->wal_buffers_full);
1678+
values[3] = Int64GetDatum(wal_counters.wal_buffers_full);
16771679

16781680
values[4] = TimestampTzGetDatum(wal_stats->stat_reset_timestamp);
16791681

src/include/pgstat.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ typedef struct PgStat_TableXactStatus
212212
* ------------------------------------------------------------
213213
*/
214214

215-
#define PGSTAT_FILE_FORMAT_ID 0x01A5BCB4
215+
#define PGSTAT_FILE_FORMAT_ID 0x01A5BCB5
216216

217217
typedef struct PgStat_ArchiverStats
218218
{
@@ -474,12 +474,29 @@ typedef struct PgStat_StatTabEntry
474474
PgStat_Counter total_autoanalyze_time;
475475
} PgStat_StatTabEntry;
476476

477-
typedef struct PgStat_WalStats
477+
/* ------
478+
* PgStat_WalCounters WAL activity data gathered from WalUsage
479+
*
480+
* This stores all the counters and data gathered from WalUsage for WAL
481+
* activity statistics, separated into its own structure so as this can be
482+
* shared across multiple Stats structures.
483+
* ------
484+
*/
485+
typedef struct PgStat_WalCounters
478486
{
479487
PgStat_Counter wal_records;
480488
PgStat_Counter wal_fpi;
481489
uint64 wal_bytes;
482490
PgStat_Counter wal_buffers_full;
491+
} PgStat_WalCounters;
492+
493+
/* -------
494+
* PgStat_WalStats WAL statistics
495+
* -------
496+
*/
497+
typedef struct PgStat_WalStats
498+
{
499+
PgStat_WalCounters wal_counters;
483500
TimestampTz stat_reset_timestamp;
484501
} PgStat_WalStats;
485502

src/tools/pgindent/typedefs.list

+1
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,7 @@ PgStat_SubXactStatus
21892189
PgStat_TableCounts
21902190
PgStat_TableStatus
21912191
PgStat_TableXactStatus
2192+
PgStat_WalCounters
21922193
PgStat_WalStats
21932194
PgXmlErrorContext
21942195
PgXmlStrictness

0 commit comments

Comments
 (0)