zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

MYSQL performance_schema 不显示信息 和调整 performance_schema 的配置

2023-02-18 16:28:13 时间

最近在某云使用了MYSQL RDS 产品,说实话不怎么满意,和他家的其他产品比较我到时更原因使用 PG 的产品和云原生产品,那才是业界良心。为什么说不原因,主要是PS 方面让我们初次使用就感觉,不十分良好,2天了PS 里面部分的表还没有数据展示,沟通找问题,最终问题还是我们自己解决了大部分。

本着,还的靠自己的思路,这里的重新整理一下PS 中的各种信息的显示开关,与本次问题的为什么不显示的部分。

PS 主要的功能

1 收集详细的mysql 运行信息

2 收集活跃的线程信息

3 查看数据库负载和事件通过PS 查看数据库在那个事件方面产生瓶颈

要打开PS 第一个开关就是 performance_schema ,这个值是不能进行动态设置的,必须在配置文件中进行设置。如果你想在系统内部动态的进行调整,会报错。

| performance_schema | ON |

如果你打开开关后,还无法使用PS的第一个问题是,无法分配缓存导致的PS 无法工作。在安装数据库后,这部分实际上是应该自动进行设置的,但是这个云厂商不知道是因为什么将这个部分全部设置为0 ,原因我们也大概知道,就是通过他的某项功能来收费,而将原有的MYSQL的功能给禁用了。

怎么查看他到底禁用了没有,通过 show variables like 'performance%class%'; 如果此时你看到的下面的位置的信息,全部是0 那么恭喜你,你就是被人家下了 科技与狠活了。这里没有办法,坑你就因为你不懂,你就去花钱买人家的 monitor 服务。我们自然是不人头的,下面给出如下值调整的 “姿势”。

1 performance_schema_max_cond_classes = 256

2 performance_schema_max_file_classes = 80

3 performance_schema_max_memory_classes = 320

4 performance_schema_max_mutex_classes =200

5 performance_schema_max_rwlock_classes = 80

6 performance_schema_max_socket_classes = 20

7 performance_schema_max_stage_classes = 200

8 performance_schema_max_statement_classes = 256

9 performance_schema_max_thread_classes = 200

以上的调整值建议用文字的标注的数值,截图的数值的主机内存太小,导致分配的值太低。(内存低于8G,用截图的值),这些值实际上如果禁用过,是需要写到 my.cnf中进行固话的,但实际上我们也不建议固化。

此时,基本上你的performance_schema 中就应该有数据了。但基于调整PS 中一些用不上的数据,尽量减少性能的消耗的问题,所以我们有了下面的东西。

在打开开关后,实际上剩下的开关与以下的几个表有关

setup_actors

setup_actors 主要的功能是设置那些 ,这里针对主机,用户来进行过滤那些用户的线程需要进行信息的留存。 默认是100条

这里可以通过performance_schema_setup_actors_size来查看到底留存多行,这里最大值是 1048576, 这里一般来说,我们是要针对一些系统的用户进行屏蔽的,比如监控账号,备份账号,等,这里可以根据管理方式酌情处理。

setup_consumers 中存在的那些记录需要进行存储,这里我们总结了一下statements 系列的是必须要进行存储的。

mysql> update setup_consumers set enabled = 'yes' where name like '%statements%';

Query OK, 2 rows affected (0.00 sec)

Rows matched: 5 Changed: 2 Warnings: 0

mysql> update setup_consumers set enabled = 'yes' where name like '%waits%';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3 Changed: 3 Warnings: 0

mysql> update setup_consumers set enabled = 'yes' where name like '%transactions%';

Query OK, 1 row affected (0.00 sec)

Rows matched: 3 Changed: 1 Warnings: 0

setup_instruments 针对需要获取信息的设备的开关信息 ,的信息主要关于那些MYSQL 的项目被包含在需要进行信息收集的部分。这里我们将stage部门全部关闭,主要的原因是消耗的资源较大,系统越繁忙消耗越大。

update setup_instruments set enabled = 'no' where name like 'stage%';

update setup_instruments set enabled = 'no' where name like '%myisam%';

update setup_instruments set enabled = 'YES' where name like 'wait/io/file/innodb/%';

update setup_instruments set enabled = 'NO' where name like 'statement%';

update setup_instruments set enabled = 'NO' where name like 'statement%update%';

update setup_instruments set enabled = 'YES' where name like 'statement%update%';

update setup_instruments set enabled = 'YES' where name like 'statement%delete%';

update setup_instruments set enabled = 'YES' where name like 'statement%insert%';

update setup_instruments set enabled = 'YES' where name like 'statement%select%';

update setup_instruments set enabled = 'NO' where name like 'wait%';

update setup_instruments set enabled = 'yes',TIMED = 'yes' where name like 'wait/io/file/innodb/innodb%';

update setup_instruments set enabled ='yes' where name = 'statement/abstract/Query';

update setup_instruments set enabled ='yes' where name = 'statement/abstract/new_packet';

最后的两个UPDATE 本身,是必须进行相关的开启的,否则语句将无法进行统计,根据官方文档中的说明

1 statement/abstract/new_packet 主要的功能是收集所有的语句,所有的语句在进行更细的过滤和分析。

2 在确认是语句的同时,需要对语句进行进行更细粒度的过滤的确认他是一个我们认为的QUERY,所以我们必须打开 statement/abstract/Query

https://dev.mysql.com/doc/refman/5.7/en/performance-schema-statement-tables.html

setup_objects 针对收取信息的OBJECT的设置

setup_threads 针对MYSQL当中收集的线程信息,以及是否进行历史信息的留存。

在经过调试后,MYSQL RDS 的PS 信息收集和展示终于正常了。