zoukankan      html  css  js  c++  java
  • 数据库大量Waiting for table flush 状态SQL问题排查

    环境:rds for mysql5.7

    因特殊原因,业务侧账号有reload权限

    今天收到活跃会话数过多的告警,登录服务器查看有大量SQL语句状态处于【Waiting for table flush 】

    下图是复现之后的场景,只有一个大查询再跑,其它的查询语句都是【Waiting for table flush 】状态,

    mysql>  show processlist;
    +----+-------------+-----------------+-------+---------+-------+--------------------------------------------------------+------------------------------------------------+
    | Id | User        | Host            | db    | Command | Time  | State                                                  | Info                                           |
    +----+-------------+-----------------+-------+---------+-------+--------------------------------------------------------+------------------------------------------------+
    |  1 | system user |                 | NULL  | Connect | 21234 | Connecting to master                                   | NULL                                           |
    |  2 | system user |                 | NULL  | Connect | 21234 | Slave has read all relay log; waiting for more updates | NULL                                           |
    |  8 | root        | 127.0.0.1:39070 | ceshi | Sleep   |    10 |                                                        | NULL                                           |
    |  9 | root        | 127.0.0.1:39120 | ceshi | Query   |    65 | User sleep                                             | select * from tt where id=(select sleep(3000)) |
    | 11 | root        | 127.0.0.1:39124 | ceshi | Query   |    45 | Waiting for table flush                                | select * from tt                               |
    | 12 | root        | 127.0.0.1:39126 | NULL  | Query   |     0 | starting                                               | show processlist                               |
    | 15 | root        | 127.0.0.1:39132 | NULL  | Sleep   |    24 |                                                        | NULL                                           |
    +----+-------------+-----------------+-------+---------+-------+--------------------------------------------------------+------------------------------------------------+

    第一反应想到了高鹏的一篇文章,

    https://blog.csdn.net/n88Lpo/article/details/113749804

    在有大查询时,对查询的表执行一次analyze table ,后面所有关于这张表的查询都会被阻塞,状态并处于【Waiting for table flush】,同事将大查询KILL掉以后,实例恢复正常。

    当时怀疑有人执行了analyze table 或代码框架执行过 analyze table,或者其它操作,查看RDS慢日志有一些线索,看到有过几次flush table with read lock;

    这个操作非常重,联系开发查看代码,为了获取binlog位点会锁一次,但似乎这个命令会并发执行,研发将flush table with read lock命令屏蔽掉后,实例一直运行正常。

    正常情况下flush table with lock 后,SQL状态应该是等待全局锁,但不知道为什么会是等待flush table。

    尝试后复现该问题

    从整个过程看,第二个flush table with lock 我停掉后,后续的SQL并没有正常执执行,还是【Waiting for table flush】

    个人猜测原因和高鹏的那篇相似。

  • 相关阅读:
    java.nio.channels.ClosedChannelException
    JAVA面试题以及基本hadoop
    one
    在远程桌面集群中——配置Python的环境变量
    双系统——在win10系统保存和查看Ubuntu系统中的文件——Linux Reader
    MySQL——安装
    Python--简单读写csv文件
    Python--画图时希腊字母的显示
    IDL——关系运算符Eq Ne Le Lt Gt Ge
    python——利用scipy.stats import pearsonr计算皮尔逊相关系数
  • 原文地址:https://www.cnblogs.com/nanxiang/p/15405745.html
Copyright © 2011-2022 走看看