在上一篇《用于修改配置的存储过程 | 全方位认识 sys 系统库》中,我们介绍了sys 系统库中用于修改配置的存储过程,利用这些存储过程可以代替修改performance_schema配置表的DML语句等操作,本期的内容讲介绍用于查看performance_schema配置信息的存储过程。
PS:下文中如果存储过程定义文本较短的会列出部存储过程的定义文本,以便大家更直观地学习它们。过长的存储过程定义文本请自行按照《初相识 | 全方位认识 sys 系统库》一文中介绍的下载路径下载查看。
01
ps_setup_show_disabled()
查看当前被禁用的performance_schema配置信息,通过查询performance_schema.setup_actors表enabled为NO、performance_schema.setup_objects表enabled为NO、performance_schema.setup_consumers表enabled为NO、performance_schema.threads表INSTRUMENTED为NO、performance_schema.setup_instruments表enabled为NO 实现,其中,调用时传递的两个布尔型值,第一个为控制是否打印performance_schema.setup_instruments表中处于关闭状态的配置(instruments关闭选项的返回值可能比较长),第二个控制是否打印performance_schema.threads表中处于关闭状态的配置,因为这俩表打印的信息最多,所以需要单独传值控制。
参数:
in_show_instruments BOOLEAN:是否显示关闭的instruments,返回的instruments关闭状态列表可能比较长
in_show_threads BOOLEAN:是否显示关闭的线程
示例
mysql> CALL sys.ps_setup_show_disabled(TRUE, TRUE);
+----------------------------+
| performance_schema_enabled |
+----------------------------+
| 1 |
+----------------------------+
1 row in set (0.00 sec)
02
ps_setup_show_disabled_consumers()
查看当前禁用的consumers配置项,通过查询performance_schema.setup_consumers表enabled字段为NO实现,执行时无需任何传入参数
存储过程定义语句文本
DROP PROCEDURE IF EXISTS ps_setup_show_disabled_consumers;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_disabled_consumers ()
COMMENT '
Description
-----------
Shows all currently disabled consumers.
Parameters
-----------
None
Example
-----------
mysql> CALL sys.ps_setup_show_disabled_consumers();
+---------------------------+
| disabled_consumers |
+---------------------------+
| events_statements_current |
| global_instrumentation |
| thread_instrumentation |
| statements_digest |
+---------------------------+
4 rows in set (0.05 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
SELECT name AS disabled_consumers
FROM performance_schema.setup_consumers
WHERE enabled = 'NO'
ORDER BY disabled_consumers;
END$$
DELIMITER ;
03
ps_setup_show_disabled_instruments()
查看当前禁用的instruments配置,通过查询performance_schema.setup_instruments表enabled字段为NO的值实现,执行时无需任何传入参数,返回的instruments列表可能比较长
存储过程定义语句文本
DROP PROCEDURE IF EXISTS ps_setup_show_disabled_instruments;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_disabled_instruments ()
COMMENT '
Description
-----------
Shows all currently disabled instruments.
Parameters
-----------
None
Example
-----------
mysql> CALL sys.ps_setup_show_disabled_instruments();
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
SELECT name AS disabled_instruments, timed
FROM performance_schema.setup_instruments
WHERE enabled = 'NO'
ORDER BY disabled_instruments;
END$$
DELIMITER ;
04
ps_setup_show_enabled()
显示当前启用的performance配置(所有配置表),通过查询performance_schema.setup_actors表enabled为YES、performance_schema.setup_objects表enabled为YES、performance_schema.setup_consumers表enabled为YES、performance_schema.threads表INSTRUMENTED为YES、performance_schema.setup_instruments表enabled为YES实现,其中,调用时传递的两个布尔型值,第一个为控制是否打印setup_instruments表中处于启用状态的配置,第二个控制是否打印performance_schema.threads表中处于启用状态的配置,因为这俩表打印的信息最多,所以需要单独传值控制。
参数:
in_show_instruments BOOLEAN:是否显示启用的instruments,返回的instruments启用状态列表可能比较长
in_show_threads BOOLEAN:是否显示启用监控功能的线程
示例
mysql> CALL sys.ps_setup_show_enabled(TRUE, TRUE);
+----------------------------+
| performance_schema_enabled |
+----------------------------+
| 1 |
+----------------------------+
1 row in set (0.00 sec)
05
ps_setup_show_enabled_consumers()
查看当前启用的consumers配置,通过查询performance_schema.setup_consumers表enabled字段为YES实现,执行时无需任何传入参数
存储过程定义语句文本
DROP PROCEDURE IF EXISTS ps_setup_show_enabled_consumers;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_enabled_consumers ()
COMMENT '
Description
-----------
Shows all currently enabled consumers.
Parameters
-----------
None
Example
-----------
mysql> CALL sys.ps_setup_show_enabled_consumers();
+---------------------------+
| enabled_consumers |
+---------------------------+
| events_statements_current |
| global_instrumentation |
| thread_instrumentation |
| statements_digest |
+---------------------------+
4 rows in set (0.05 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
SELECT name AS enabled_consumers
FROM performance_schema.setup_consumers
WHERE enabled = 'YES'
ORDER BY enabled_consumers;
END$$
DELIMITER ;
06
ps_setup_show_enabled_instruments()
查看当前启用的instruments配置,通过查询performance_schema.setup_instruments表enabled字段为YES的值实现,执行时无需任何传入参数,但返回的instruments列表可能比较长
存储过程定义语句文本
DROP PROCEDURE IF EXISTS ps_setup_show_enabled_instruments;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_enabled_instruments ()
COMMENT '
Description
-----------
Shows all currently enabled instruments.
Parameters
-----------
None
Example
-----------
mysql> CALL sys.ps_setup_show_enabled_instruments();
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
SELECT name AS enabled_instruments, timed
FROM performance_schema.setup_instruments
WHERE enabled = 'YES'
ORDER BY enabled_instruments;
END$$
DELIMITER ;
本期内容就介绍到这里,本期内容参考链接如下:
https://dev.mysql.com/doc/refman/5.7/en/sys-ps-setup-show-enabled-instruments.html
https://dev.mysql.com/doc/refman/5.7/en/sys-ps-setup-show-disabled.html
https://dev.mysql.com/doc/refman/5.7/en/sys-ps-setup-show-disabled-consumers.html
https://dev.mysql.com/doc/refman/5.7/en/sys-ps-setup-show-disabled-instruments.html
https://dev.mysql.com/doc/refman/5.7/en/sys-ps-setup-show-enabled.html
https://dev.mysql.com/doc/refman/5.7/en/sys-ps-setup-show-enabled-consumers.html
| 作者简介
罗小波·数据库技术专家
《千金良方——MySQL性能优化金字塔法则》、《数据生态:MySQL复制技术与生产实践》作者之一。熟悉MySQL体系结构,擅长数据库的整体调优,喜好专研开源技术,并热衷于开源技术的推广,在线上线下做过多次公开的数据库专题分享,发表过近100篇数据库相关的研究文章。
全文完。
Enjoy MySQL :)
叶老师的「MySQL核心优化」大课已升级到MySQL 8.0,扫码开启MySQL 8.0修行之旅吧