Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c87ff71

Browse files
committed
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
1 parent 9ce9dfd commit c87ff71

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

doc/src/sgml/monitoring.sgml

+5
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,11 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
950950
<entry><type>bigint</></entry>
951951
<entry>Estimated number of dead rows</entry>
952952
</row>
953+
<row>
954+
<entry><structfield>n_mod_since_analyze</></entry>
955+
<entry><type>bigint</></entry>
956+
<entry>Estimated number of rows modified since this table was last analyzed</entry>
957+
</row>
953958
<row>
954959
<entry><structfield>last_vacuum</></entry>
955960
<entry><type>timestamp with time zone</></entry>

src/backend/catalog/system_views.sql

+1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ CREATE VIEW pg_stat_all_tables AS
405405
pg_stat_get_tuples_hot_updated(C.oid) AS n_tup_hot_upd,
406406
pg_stat_get_live_tuples(C.oid) AS n_live_tup,
407407
pg_stat_get_dead_tuples(C.oid) AS n_dead_tup,
408+
pg_stat_get_mod_since_analyze(C.oid) AS n_mod_since_analyze,
408409
pg_stat_get_last_vacuum_time(C.oid) as last_vacuum,
409410
pg_stat_get_last_autovacuum_time(C.oid) as last_autovacuum,
410411
pg_stat_get_last_analyze_time(C.oid) as last_analyze,

src/backend/utils/adt/pgstatfuncs.c

+17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS);
3434
extern Datum pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS);
3535
extern Datum pg_stat_get_live_tuples(PG_FUNCTION_ARGS);
3636
extern Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS);
37+
extern Datum pg_stat_get_mod_since_analyze(PG_FUNCTION_ARGS);
3738
extern Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS);
3839
extern Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS);
3940
extern Datum pg_stat_get_last_vacuum_time(PG_FUNCTION_ARGS);
@@ -265,6 +266,22 @@ pg_stat_get_dead_tuples(PG_FUNCTION_ARGS)
265266
}
266267

267268

269+
Datum
270+
pg_stat_get_mod_since_analyze(PG_FUNCTION_ARGS)
271+
{
272+
Oid relid = PG_GETARG_OID(0);
273+
int64 result;
274+
PgStat_StatTabEntry *tabentry;
275+
276+
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
277+
result = 0;
278+
else
279+
result = (int64) (tabentry->changes_since_analyze);
280+
281+
PG_RETURN_INT64(result);
282+
}
283+
284+
268285
Datum
269286
pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS)
270287
{

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201307031
56+
#define CATALOG_VERSION_NO 201307051
5757

5858
#endif

src/include/catalog/pg_proc.h

+2
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,8 @@ DATA(insert OID = 2878 ( pg_stat_get_live_tuples PGNSP PGUID 12 1 0 0 0 f f f f
25932593
DESCR("statistics: number of live tuples");
25942594
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_ ));
25952595
DESCR("statistics: number of dead tuples");
2596+
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_ ));
2597+
DESCR("statistics: number of tuples changed since last analyze");
25962598
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_ ));
25972599
DESCR("statistics: number of blocks fetched");
25982600
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_ ));

src/test/regress/expected/rules.out

+3
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem
16261626
| pg_stat_get_tuples_hot_updated(c.oid) AS n_tup_hot_upd, +
16271627
| pg_stat_get_live_tuples(c.oid) AS n_live_tup, +
16281628
| pg_stat_get_dead_tuples(c.oid) AS n_dead_tup, +
1629+
| pg_stat_get_mod_since_analyze(c.oid) AS n_mod_since_analyze, +
16291630
| pg_stat_get_last_vacuum_time(c.oid) AS last_vacuum, +
16301631
| pg_stat_get_last_autovacuum_time(c.oid) AS last_autovacuum, +
16311632
| 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
17201721
| pg_stat_all_tables.n_tup_hot_upd, +
17211722
| pg_stat_all_tables.n_live_tup, +
17221723
| pg_stat_all_tables.n_dead_tup, +
1724+
| pg_stat_all_tables.n_mod_since_analyze, +
17231725
| pg_stat_all_tables.last_vacuum, +
17241726
| pg_stat_all_tables.last_autovacuum, +
17251727
| pg_stat_all_tables.last_analyze, +
@@ -1762,6 +1764,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem
17621764
| pg_stat_all_tables.n_tup_hot_upd, +
17631765
| pg_stat_all_tables.n_live_tup, +
17641766
| pg_stat_all_tables.n_dead_tup, +
1767+
| pg_stat_all_tables.n_mod_since_analyze, +
17651768
| pg_stat_all_tables.last_vacuum, +
17661769
| pg_stat_all_tables.last_autovacuum, +
17671770
| pg_stat_all_tables.last_analyze, +

0 commit comments

Comments
 (0)