stat_user_tables collector exposes comprehensive statistics for user tables, including scan activity, tuple operations, vacuum history, and table sizes.
Status
Default: EnabledMetrics
Scan Metrics
pg_stat_user_tables_seq_scan
Type: CounterDescription: Number of sequential scans initiated on this table Labels:
datname, schemaname, relname
pg_stat_user_tables_seq_tup_read
Type: CounterDescription: Number of live rows fetched by sequential scans Labels:
datname, schemaname, relname
pg_stat_user_tables_idx_scan
Type: CounterDescription: Number of index scans initiated on this table Labels:
datname, schemaname, relname
pg_stat_user_tables_idx_tup_fetch
Type: CounterDescription: Number of live rows fetched by index scans Labels:
datname, schemaname, relname
Tuple Modification Metrics
pg_stat_user_tables_n_tup_ins
Type: CounterDescription: Number of rows inserted Labels:
datname, schemaname, relname
pg_stat_user_tables_n_tup_upd
Type: CounterDescription: Number of rows updated Labels:
datname, schemaname, relname
pg_stat_user_tables_n_tup_del
Type: CounterDescription: Number of rows deleted Labels:
datname, schemaname, relname
pg_stat_user_tables_n_tup_hot_upd
Type: CounterDescription: Number of rows HOT (Heap-Only Tuple) updated Labels:
datname, schemaname, relname
Note: HOT updates don’t require index updates, improving performance.
Live Data Metrics
pg_stat_user_tables_n_live_tup
Type: GaugeDescription: Estimated number of live rows Labels:
datname, schemaname, relname
pg_stat_user_tables_n_dead_tup
Type: GaugeDescription: Estimated number of dead rows Labels:
datname, schemaname, relname
pg_stat_user_tables_n_mod_since_analyze
Type: GaugeDescription: Estimated number of rows changed since last analyze Labels:
datname, schemaname, relname
Vacuum/Analyze Timestamps
pg_stat_user_tables_last_vacuum
Type: GaugeDescription: Last time this table was manually vacuumed (Unix timestamp, 0 if never) Labels:
datname, schemaname, relname
pg_stat_user_tables_last_autovacuum
Type: GaugeDescription: Last time this table was vacuumed by autovacuum (Unix timestamp, 0 if never) Labels:
datname, schemaname, relname
pg_stat_user_tables_last_analyze
Type: GaugeDescription: Last time this table was manually analyzed (Unix timestamp, 0 if never) Labels:
datname, schemaname, relname
pg_stat_user_tables_last_autoanalyze
Type: GaugeDescription: Last time this table was analyzed by autovacuum (Unix timestamp, 0 if never) Labels:
datname, schemaname, relname
Vacuum/Analyze Counts
pg_stat_user_tables_vacuum_count
Type: CounterDescription: Number of times this table has been manually vacuumed Labels:
datname, schemaname, relname
pg_stat_user_tables_autovacuum_count
Type: CounterDescription: Number of times this table has been vacuumed by autovacuum Labels:
datname, schemaname, relname
pg_stat_user_tables_analyze_count
Type: CounterDescription: Number of times this table has been manually analyzed Labels:
datname, schemaname, relname
pg_stat_user_tables_autoanalyze_count
Type: CounterDescription: Number of times this table has been analyzed by autovacuum Labels:
datname, schemaname, relname
Size Metrics
pg_stat_user_tables_table_size_bytes
Type: GaugeDescription: Total disk space used by this table, in bytes Labels:
datname, schemaname, relname
pg_stat_user_tables_index_size_bytes
Type: GaugeDescription: Total disk space used by all indexes on this table, in bytes Labels:
datname, schemaname, relname
SQL Query
PostgreSQL Versions
Supported: All versionsRequired Permissions
The monitoring user needs:- Access to
pg_stat_user_tablesview - Execute permission on
pg_table_size()andpg_indexes_size()functions
Example Output
Use Cases
Sequential Scan Detection
Dead Tuple Monitoring
Vacuum Effectiveness
Table Bloat Detection
HOT Update Ratio
Table Growth
Alert Examples
Performance Tuning
Missing Indexes
Ifseq_scan is high on large tables:
Autovacuum Tuning
If dead tuples accumulate:- Lower
autovacuum_vacuum_scale_factor - Lower
autovacuum_vacuum_threshold - Increase
autovacuum_max_workers
Analyze Frequency
Ifn_mod_since_analyze is high:
- Lower
autovacuum_analyze_scale_factor - Run manual
ANALYZEon frequently modified tables