From 40d9e94bd7537144d3d379c1fd1264dff5cf4bb2 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 3 Jan 2011 12:46:03 +0100 Subject: Add views and functions to monitor hot standby query conflicts Add the view pg_stat_database_conflicts and a column to pg_stat_database, and the underlying functions to provide the information. --- src/backend/utils/adt/pgstatfuncs.c | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 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 d357b5c8b5d..a95ba8b3eb3 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -71,6 +71,12 @@ extern Datum pg_stat_get_db_tuples_fetched(PG_FUNCTION_ARGS); extern Datum pg_stat_get_db_tuples_inserted(PG_FUNCTION_ARGS); extern Datum pg_stat_get_db_tuples_updated(PG_FUNCTION_ARGS); extern Datum pg_stat_get_db_tuples_deleted(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_conflict_tablespace(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_conflict_lock(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_conflict_snapshot(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_conflict_bufferpin(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_conflict_startup_deadlock(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_conflict_all(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); @@ -1129,6 +1135,101 @@ pg_stat_get_db_tuples_deleted(PG_FUNCTION_ARGS) PG_RETURN_INT64(result); } +Datum +pg_stat_get_db_conflict_tablespace(PG_FUNCTION_ARGS) +{ + Oid dbid = PG_GETARG_OID(0); + int64 result; + PgStat_StatDBEntry *dbentry; + + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = (int64) (dbentry->n_conflict_tablespace); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_db_conflict_lock(PG_FUNCTION_ARGS) +{ + Oid dbid = PG_GETARG_OID(0); + int64 result; + PgStat_StatDBEntry *dbentry; + + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = (int64) (dbentry->n_conflict_lock); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_db_conflict_snapshot(PG_FUNCTION_ARGS) +{ + Oid dbid = PG_GETARG_OID(0); + int64 result; + PgStat_StatDBEntry *dbentry; + + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = (int64) (dbentry->n_conflict_snapshot); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_db_conflict_bufferpin(PG_FUNCTION_ARGS) +{ + Oid dbid = PG_GETARG_OID(0); + int64 result; + PgStat_StatDBEntry *dbentry; + + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = (int64) (dbentry->n_conflict_bufferpin); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_db_conflict_startup_deadlock(PG_FUNCTION_ARGS) +{ + Oid dbid = PG_GETARG_OID(0); + int64 result; + PgStat_StatDBEntry *dbentry; + + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = (int64) (dbentry->n_conflict_startup_deadlock); + + PG_RETURN_INT64(result); +} + +Datum +pg_stat_get_db_conflict_all(PG_FUNCTION_ARGS) +{ + Oid dbid = PG_GETARG_OID(0); + int64 result; + PgStat_StatDBEntry *dbentry; + + if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) + result = 0; + else + result = (int64) ( + dbentry->n_conflict_tablespace + + dbentry->n_conflict_lock + + dbentry->n_conflict_snapshot + + dbentry->n_conflict_bufferpin + + dbentry->n_conflict_startup_deadlock); + + PG_RETURN_INT64(result); +} + Datum pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS) { -- cgit v1.2.3