mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Add pg_stat_archiver statistics view.
This view shows the statistics about the WAL archiver process's activity. Gabriele Bartolini, reviewed by Michael Paquier, refactored a bit by me.
This commit is contained in:
@ -87,6 +87,8 @@ extern Datum pg_stat_get_db_temp_bytes(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_db_blk_read_time(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum pg_stat_get_archiver(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS);
|
||||
@ -1712,3 +1714,70 @@ pg_stat_reset_single_function_counters(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_archiver(PG_FUNCTION_ARGS)
|
||||
{
|
||||
TupleDesc tupdesc;
|
||||
Datum values[7];
|
||||
bool nulls[7];
|
||||
PgStat_ArchiverStats *archiver_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(7, false);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal",
|
||||
TEXTOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "last_archived_time",
|
||||
TIMESTAMPTZOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "failed_count",
|
||||
INT8OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "last_failed_wal",
|
||||
TEXTOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "last_failed_time",
|
||||
TIMESTAMPTZOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "stats_reset",
|
||||
TIMESTAMPTZOID, -1, 0);
|
||||
|
||||
BlessTupleDesc(tupdesc);
|
||||
|
||||
/* Get statistics about the archiver process */
|
||||
archiver_stats = pgstat_fetch_stat_archiver();
|
||||
|
||||
/* Fill values and NULLs */
|
||||
values[0] = Int64GetDatum(archiver_stats->archived_count);
|
||||
if (archiver_stats->last_archived_wal == 0)
|
||||
nulls[1] = true;
|
||||
else
|
||||
values[1] = CStringGetTextDatum(archiver_stats->last_archived_wal);
|
||||
|
||||
if (archiver_stats->last_archived_timestamp == 0)
|
||||
nulls[2] = true;
|
||||
else
|
||||
values[2] = TimestampTzGetDatum(archiver_stats->last_archived_timestamp);
|
||||
|
||||
values[3] = Int64GetDatum(archiver_stats->failed_count);
|
||||
if (archiver_stats->last_failed_wal == 0)
|
||||
nulls[4] = true;
|
||||
else
|
||||
values[4] = CStringGetTextDatum(archiver_stats->last_failed_wal);
|
||||
|
||||
if (archiver_stats->last_failed_timestamp == 0)
|
||||
nulls[5] = true;
|
||||
else
|
||||
values[5] = TimestampTzGetDatum(archiver_stats->last_failed_timestamp);
|
||||
|
||||
if (archiver_stats->stat_reset_timestamp == 0)
|
||||
nulls[6] = true;
|
||||
else
|
||||
values[6] = TimestampTzGetDatum(archiver_stats->stat_reset_timestamp);
|
||||
|
||||
/* Returns the record as Datum */
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(
|
||||
heap_form_tuple(tupdesc, values, nulls)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user