pg_stat_user_tables system view, providing table-level visibility into access patterns, data modifications, and maintenance operations.
This collector is enabled by default.
What It Monitors
The user tables statistics collector tracks:- Sequential and index scan activity
- Row insertion, update, and deletion counts
- Live and dead tuple counts
- Vacuum and analyze operations
- Table and index sizes
- HOT (Heap-Only Tuple) updates
Metrics Exposed
Scan Metrics
pg_stat_user_tables_seq_scan
Number of sequential scans initiated on this table. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_seq_tup_read
Number of live rows fetched by sequential scans. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_idx_scan
Number of index scans initiated on this table. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_idx_tup_fetch
Number of live rows fetched by index scans. Type: CounterLabels:
datname, schemaname, relname
Modification Metrics
pg_stat_user_tables_n_tup_ins
Number of rows inserted. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_n_tup_upd
Number of rows updated. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_n_tup_del
Number of rows deleted. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_n_tup_hot_upd
Number of rows HOT updated (Heap-Only Tuple updates that don’t require index updates). Type: CounterLabels:
datname, schemaname, relname
High HOT update ratios indicate efficient updates. Low ratios may suggest fill factor adjustments are needed.
Tuple Count Metrics
pg_stat_user_tables_n_live_tup
Estimated number of live rows. Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_n_dead_tup
Estimated number of dead rows. Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_n_mod_since_analyze
Estimated number of rows changed since last analyze. Type: GaugeLabels:
datname, schemaname, relname
Maintenance Operation Metrics
pg_stat_user_tables_last_vacuum
Timestamp of the last manual vacuum (not counting VACUUM FULL). Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_last_autovacuum
Timestamp of the last autovacuum. Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_last_analyze
Timestamp of the last manual analyze. Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_last_autoanalyze
Timestamp of the last autoanalyze. Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_vacuum_count
Number of times this table has been manually vacuumed. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_autovacuum_count
Number of times this table has been vacuumed by autovacuum. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_analyze_count
Number of times this table has been manually analyzed. Type: CounterLabels:
datname, schemaname, relname
pg_stat_user_tables_autoanalyze_count
Number of times this table has been analyzed by autoanalyze. Type: CounterLabels:
datname, schemaname, relname
Size Metrics
pg_stat_user_tables_table_size_bytes
Total disk space used by this table in bytes. Type: GaugeLabels:
datname, schemaname, relname
pg_stat_user_tables_index_size_bytes
Total disk space used by indexes on this table in bytes. Type: GaugeLabels:
datname, schemaname, relname
SQL Query Used
Configuration
Enable/Disable the Collector
Use Cases
Identify Tables Needing Indexes
Find tables with high sequential scan ratios:Monitor Dead Tuple Bloat
Detect tables with excessive dead tuples:Calculate HOT Update Efficiency
Measure HOT update ratio:Alert on Stale Statistics
Detect tables that haven’t been analyzed recently:Find Largest Tables
Identify tables consuming the most disk space:Monitor Index Size Growth
Track index bloat over time:Understanding Table Activity Patterns
Read-Heavy Tables
- High
seq_scanoridx_scanvalues - Low modification counts
- Consider read replicas for scaling
Write-Heavy Tables
- High
n_tup_ins,n_tup_upd,n_tup_delvalues - May accumulate dead tuples quickly
- Requires frequent vacuuming
- Monitor autovacuum effectiveness
Tables Needing Maintenance
- High
n_dead_tuprelative ton_live_tup - Large
n_mod_since_analyzevalues - Old
last_autovacuumorlast_autoanalyzetimestamps
Permissions Required
The user tables statistics collector requires:CONNECTprivilege on the database- Read access to the
pg_stat_user_tablesview - For size metrics: Access to
pg_table_size()andpg_indexes_size()functions - For PostgreSQL 10+:
pg_monitororpg_read_all_statsrole - For PostgreSQL <10: Read access to statistics views and size functions
Performance Considerations
The user tables statistics collector:- Queries per-table statistics from
pg_stat_user_tables - Calculates table and index sizes for each table
- Can generate many metrics in databases with many tables
- Size calculations may be expensive for very large tables
- Consider disabling if you have thousands of tables and performance issues
Related Collectors
- Database Statistics - Database-level statistics
- Database - Database size metrics
- I/O User Tables Collector - Physical I/O statistics per table (if enabled)
Troubleshooting
High Dead Tuple Counts
- Check autovacuum settings:
SHOW autovacuum; - Review autovacuum thresholds for specific tables
- Consider manual VACUUM for severely bloated tables
- Check for long-running transactions blocking vacuum
Missing Indexes
- Look for high
seq_scanon large tables - Use
pg_stat_statementsto identify slow queries - Create indexes on frequently queried columns
- Monitor index usage after creation