diff options
author | Magnus Hagander <magnus@hagander.net> | 2013-07-05 15:02:09 +0200 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2013-07-05 15:10:15 +0200 |
commit | c87ff71f374652936a6089215a30998492b14d52 (patch) | |
tree | b258309f40ab3f9302bcc2d29b0753c29cf8fbed /src | |
parent | 9ce9dfdb999960aa7596bb219db02ccdbe2da855 (diff) | |
download | postgresql-c87ff71f374652936a6089215a30998492b14d52.tar.gz postgresql-c87ff71f374652936a6089215a30998492b14d52.zip |
Expose the estimation of number of changed tuples since last analyze
This value, now pg_stat_all_tables.n_mod_since_analyze, was already
tracked and used by autovacuum, but not exposed to the user.
Mark Kirkwood, review by Laurenz Albe
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/catalog/system_views.sql | 1 | ||||
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 17 | ||||
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 2 | ||||
-rw-r--r-- | src/test/regress/expected/rules.out | 3 |
5 files changed, 24 insertions, 1 deletions
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index d3086f43dd6..575a40f5dbe 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -405,6 +405,7 @@ CREATE VIEW pg_stat_all_tables AS pg_stat_get_tuples_hot_updated(C.oid) AS n_tup_hot_upd, pg_stat_get_live_tuples(C.oid) AS n_live_tup, pg_stat_get_dead_tuples(C.oid) AS n_dead_tup, + pg_stat_get_mod_since_analyze(C.oid) AS n_mod_since_analyze, pg_stat_get_last_vacuum_time(C.oid) as last_vacuum, pg_stat_get_last_autovacuum_time(C.oid) as last_autovacuum, pg_stat_get_last_analyze_time(C.oid) as last_analyze, diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 8c1a76728de..0533cd6b3eb 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -34,6 +34,7 @@ extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS); extern Datum pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS); extern Datum pg_stat_get_live_tuples(PG_FUNCTION_ARGS); extern Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_mod_since_analyze(PG_FUNCTION_ARGS); extern Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS); extern Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS); extern Datum pg_stat_get_last_vacuum_time(PG_FUNCTION_ARGS); @@ -266,6 +267,22 @@ pg_stat_get_dead_tuples(PG_FUNCTION_ARGS) Datum +pg_stat_get_mod_since_analyze(PG_FUNCTION_ARGS) +{ + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; + + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) + result = 0; + else + result = (int64) (tabentry->changes_since_analyze); + + PG_RETURN_INT64(result); +} + + +Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS) { Oid relid = PG_GETARG_OID(0); diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 9358e955475..4fdd81fa6b4 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201307031 +#define CATALOG_VERSION_NO 201307051 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index b5be075ee16..90aff3d0484 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -2593,6 +2593,8 @@ DATA(insert OID = 2878 ( pg_stat_get_live_tuples PGNSP PGUID 12 1 0 0 0 f f f f DESCR("statistics: number of live tuples"); DATA(insert OID = 2879 ( pg_stat_get_dead_tuples PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_dead_tuples _null_ _null_ _null_ )); DESCR("statistics: number of dead tuples"); +DATA(insert OID = 3177 ( pg_stat_get_mod_since_analyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_mod_since_analyze _null_ _null_ _null_ )); +DESCR("statistics: number of tuples changed since last analyze"); DATA(insert OID = 1934 ( pg_stat_get_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_blocks_fetched _null_ _null_ _null_ )); DESCR("statistics: number of blocks fetched"); DATA(insert OID = 1935 ( pg_stat_get_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_blocks_hit _null_ _null_ _null_ )); diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 4b182e7f541..8f24c51f000 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1626,6 +1626,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem | pg_stat_get_tuples_hot_updated(c.oid) AS n_tup_hot_upd, + | pg_stat_get_live_tuples(c.oid) AS n_live_tup, + | pg_stat_get_dead_tuples(c.oid) AS n_dead_tup, + + | pg_stat_get_mod_since_analyze(c.oid) AS n_mod_since_analyze, + | pg_stat_get_last_vacuum_time(c.oid) AS last_vacuum, + | pg_stat_get_last_autovacuum_time(c.oid) AS last_autovacuum, + | pg_stat_get_last_analyze_time(c.oid) AS last_analyze, + @@ -1720,6 +1721,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem | pg_stat_all_tables.n_tup_hot_upd, + | pg_stat_all_tables.n_live_tup, + | pg_stat_all_tables.n_dead_tup, + + | pg_stat_all_tables.n_mod_since_analyze, + | pg_stat_all_tables.last_vacuum, + | pg_stat_all_tables.last_autovacuum, + | pg_stat_all_tables.last_analyze, + @@ -1762,6 +1764,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem | pg_stat_all_tables.n_tup_hot_upd, + | pg_stat_all_tables.n_live_tup, + | pg_stat_all_tables.n_dead_tup, + + | pg_stat_all_tables.n_mod_since_analyze, + | pg_stat_all_tables.last_vacuum, + | pg_stat_all_tables.last_autovacuum, + | pg_stat_all_tables.last_analyze, + |