From 2fb7a75f37d0beca80f45e15736ec8d50064228a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 19 Feb 2015 21:36:50 -0500 Subject: Add pg_stat_get_snapshot_timestamp() to show statistics snapshot timestamp. Per discussion, this could be useful for purposes such as programmatically detecting a nonresponding stats collector. We already have the timestamp anyway, it's just a matter of providing a SQL-accessible function to fetch it. Matt Kelly, reviewed by Jim Nasby --- src/backend/utils/adt/pgstatfuncs.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/backend/utils/adt/pgstatfuncs.c') diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 389ea494dbb..9964c5e1032 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -115,6 +115,7 @@ extern Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS); extern Datum pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS); extern Datum pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_snapshot_timestamp(PG_FUNCTION_ARGS); extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS); extern Datum pg_stat_reset(PG_FUNCTION_ARGS); extern Datum pg_stat_reset_shared(PG_FUNCTION_ARGS); @@ -1682,6 +1683,13 @@ pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS) } +/* Get the timestamp of the current statistics snapshot */ +Datum +pg_stat_get_snapshot_timestamp(PG_FUNCTION_ARGS) +{ + PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stats_timestamp); +} + /* Discard the active statistics snapshot */ Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS) -- cgit v1.2.3