mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Add pg_stat_wal statistics view.
This view shows the statistics about WAL activity. Currently it has only two columns: wal_buffers_full and stats_reset. wal_buffers_full column indicates the number of times WAL data was written to the disk because WAL buffers got full. This information is useful when tuning wal_buffers. stats_reset column indicates the time at which these statistics were last reset. pg_stat_wal view is also the basic infrastructure to expose other various statistics about WAL activity later. Bump PGSTAT_FILE_FORMAT_ID due to the change in pgstat format. Bump catalog version. Author: Masahiro Ikeda Reviewed-by: Takayuki Tsunakawa, Kyotaro Horiguchi, Amit Kapila, Fujii Masao Discussion: https://postgr.es/m/188bd3f2d2233cf97753b5ced02bb050@oss.nttdata.com
This commit is contained in:
@ -1697,6 +1697,42 @@ pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns statistics of WAL activity
|
||||
*/
|
||||
Datum
|
||||
pg_stat_get_wal(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define PG_STAT_GET_WAL_COLS 2
|
||||
TupleDesc tupdesc;
|
||||
Datum values[PG_STAT_GET_WAL_COLS];
|
||||
bool nulls[PG_STAT_GET_WAL_COLS];
|
||||
PgStat_WalStats *wal_stats;
|
||||
|
||||
/* Initialise values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* Initialise attributes information in the tuple descriptor */
|
||||
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_buffers_full",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "stats_reset",
|
||||
TIMESTAMPTZOID, -1, 0);
|
||||
|
||||
BlessTupleDesc(tupdesc);
|
||||
|
||||
/* Get statistics about WAL activity */
|
||||
wal_stats = pgstat_fetch_stat_wal();
|
||||
|
||||
/* Fill values and NULLs */
|
||||
values[0] = Int64GetDatum(wal_stats->wal_buffers_full);
|
||||
values[1] = TimestampTzGetDatum(wal_stats->stat_reset_timestamp);
|
||||
|
||||
/* Returns the record as Datum */
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns statistics of SLRU caches.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user