PG_STAT_ALL_TABLES
PG_STAT_ALL_TABLES视图显示当前数据库中与表访问相关的统计信息(包括TOAST表)。
名称 | 类型 | 描述 |
|---|---|---|
relid | oid | 表的OID。 |
schemaname | name | 此表的模式名。 |
relname | name | 表名。 |
seq_scan | bigint | 在此表上启动的顺序扫描数。 |
seq_tup_read | bigint | 顺序扫描抓取的有live数据行的数目。 |
idx_scan | bigint | 索引扫描的次数。 |
idx_tup_fetch | bigint | 索引扫描抓取的有live数据行的数目。 |
n_tup_ins | bigint | 插入的行数。 |
n_tup_upd | bigint | 更新的行数。 |
n_tup_del | bigint | 删除的行数。 |
n_tup_hot_upd | bigint | 热更新的行数(即不需要单独的索引更新)。 |
n_live_tup | bigint | live行估计数。 |
n_dead_tup | bigint | dead行估计数。 |
last_vacuum | timestamp with time zone | 最后一次手动vacuum时间(不计算VACUUM FULL)。 |
last_autovacuum | timestamp with time zone | 最后一次autovacuum时间。 |
last_analyze | timestamp with time zone | 最后一次非自动轮询分析的时间。 |
last_autoanalyze | timestamp with time zone | 最后一次自动轮询分析的时间。 |
vacuum_count | bigint | vacuum次数(不计算VACUUM FULL)。 |
autovacuum_count | bigint | autovacuum次数。 |
analyze_count | bigint | analyze次数。 |
autoanalyze_count | bigint | autoanalyze次数。 |
last_data_changed | timestamp with time zone | 记录该表最后一次数据发生变化的时间(引起数据变化的操作包括INSERT/UPDATE/DELETE、EXCHANGE/TRUNCATE/DROP partition),该列数据仅在本地CN记录。 |
应用示例
查询表table_test最后一次数据发生变化的时间:
1 2 3 4 5 | SELECT last_data_changed FROM PG_STAT_ALL_TABLES WHERE relname ='table_test'; last_data_changed ------------------------------- 2024-03-27 10:28:16.277136+08 (1 row) |

