aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pgstatfuncs.c
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2014-01-29 02:58:22 +0900
committerFujii Masao <fujii@postgresql.org>2014-01-29 02:58:22 +0900
commit9132b189bf5589591cb63fef7952842b772e4fe6 (patch)
treeebada3d4f99b03554482b43cf4d6beb7b2a1b371 /src/backend/utils/adt/pgstatfuncs.c
parent98d62c28fd774ad8d123b66131dcdaa0b9c9d6d4 (diff)
downloadpostgresql-9132b189bf5589591cb63fef7952842b772e4fe6.tar.gz
postgresql-9132b189bf5589591cb63fef7952842b772e4fe6.zip
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.
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 2b8f5ee1e60..29fc134858b 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -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)));
+}