1. 事务历史的分析,pg_stat_statements、performance_schema?
请说明事务历史的分析工具,包括 pg_stat_statements 与 performance_schema?
- pg_stat_statements 统计语句执行历史。
- performance_schema 记录事件与事务。
- 用于事务与性能分析。
事务历史分析依赖统计工具。PostgreSQL 的 pg_stat_statements 扩展记录每条 SQL 语句的执行次数、总耗时、平均耗时、块读取等统计,可分析慢语句与高频语句,是性能分析的核心。MySQL 的 performance_schema 提供结构化的事件监控(等待、执行、锁、事务),其中的 events_transactions_current / events_transactions_history 记录事务的执行历史,可分析事务耗时、状态、关联的语句。配合 slow query log、information_schema 可全面分析事务。通过 pg_stat_statements 可定位高频/慢 SQL,通过 performance_schema 可细粒度分析事务与事件。二者是事务与性能历史分析的关键工具。
pg_stat_statements 统计语句,performance_schema 记录事务与事件。两者互补分析事务历史与性能。