当前位置:网站首页>A troubleshooting process for database timeout caused by SQL misguided
A troubleshooting process for database timeout caused by SQL misguided
2022-06-13 07:36:00 【Fish is not fish】
The phenomenon
A project I just took over recently , At noon one day 12 spot 30 Receive more development feedback , When their business requests a database , There are a lot of request timeouts , Although there have been before , But this one lasted a long time , I recovered in about two minutes .
Database version 8.0.22. Isolation level RR.
Preliminary analysis
Receive questions , take it easy , Take a look at the surveillance :

From the monitoring diagram, it can be seen that the corresponding 12 spot 36 The number of connections began to soar around the minute , And there is a small amount of slowness at this point sql.
View the slow query log at the corresponding time point , The following slow queries are found at the corresponding time sql:
Here you can see the slow query from 12 spot 36 It's done 155s.
This SQL It's not supposed to be slow , because (uid,msg_id) It's a uk Indexes ,id It's the primary key .
And then because of the timeout , So guess it is the timeout caused by the lock ?
However, the new project does not have a very deep lock related monitoring , You can only query the storage engine information Show engine innodb status\G; You can only see the latest deadlock information . To see the complete deadlock information Suggest opening innodb_print_all_deadlocks, This parameter will output all deadlock information to MySQL Of error log among . In this way, the deadlock log at the corresponding time point will not be missed .
As a result, a deadlock message occurred at the corresponding time point , as follows :
From the latest deadlock log , We can see :
At that time, there was a lock waiting situation Here we need to declare the difference between lock waiting and deadlock
1. An error will be reported immediately when a deadlock occurs , And the rollback cost is small SQL. Lock waiting is based on innodb_lock_wait_timeout Default 50s, If in 50s Can't get the corresponding lock , An error will be reported try again. Therefore, the deadlock must be caused by the lock waiting first .
At that time, lock competition mainly focused on the primary key index record Lock contention leads to however , From two SQL Look at , these two items. SQL All have uk Indexed , Finally, the primary key cannot have lock contention .
Here we are. , I have no idea , Later, I thought I could only look back at the implementation plan , Whether the implementation plan has not reached ;

A magical scene happened , This SQL I went to the primary key index , Then there is a train of thought .
The data in the table is 2500w strip , It's almost like scanning the whole table ,
If it is a full table scan , Lock all primary keys , That makes sense .
summary
The process of the problem is as follows :
12 spot 36 branch , This is slow SQL Due to the wrong index , With all the primary key indexes gap and record lock
Then other requests come , because innodb_lock_wait_timeout=50s By default ,
So the following SQL Waiting when you can't get the lock 50s Later error reporting try again, The business response is timeout .
Thus, during the slow query execution , The corresponding in the back SQL Can't get the lock , All in 50s Time out after ,
Also because of waiting , So the connection stack , soar , Slow behind SQL 155s completion of enforcement , Back to normal .
边栏推荐
- EF core execute SQL statement
- Simple use of logs
- Sharp weapon tcpdump
- AQS - detailed explanation of reentrantlock source code
- [log framework] add user-defined parameters to the MDC implementation log
- 关于oracle的函数。
- redis-1. Install redis with pictures and texts
- [hard copy] core differences among dirty reading, non repeatable reading and unreal reading scenarios
- How to solve the 404 problem
- Redis cluster parsing docker building redis cluster
猜你喜欢

Reflection of C # Foundation

redis-7. Redis master-slave replication, cap, Paxos, cluster sharding cluster 02

Powerdispatcher reverse generation of Oracle data model

MySQL summary

Export chrome plug-ins and import local plug-ins to chrome

redis-4. Redis' message subscription, pipeline, transaction, modules, bloom filter, and cache LRU
![[log framework] add user-defined parameters to the MDC implementation log](/img/94/5c0c51663f6a26d2ccf4a81047060f.jpg)
[log framework] add user-defined parameters to the MDC implementation log

Redis learning journey - cache exceptions (CACHE penetration, cache avalanche, cache breakdown)

Mui mixed development - when updating the download app, the system status bar displays the download progress

Paper notes: multi label learning bp-mll
随机推荐
部署RDS服务
First graphical interface (modified version)
25 domestic and foreign literature databases
China phosphate market in-depth analysis and investment prospect forecast report 2022-2028
redis-1. Install redis with pictures and texts
AQS - detailed explanation of reentrantlock source code
The management practice of leading enterprises has proved that what is the core of sustainable development of enterprises?
Some optimization for seckill project
[log4j2 log framework] sensitive character filtering
C drawing table and sending mail function
Sorting of numbers and strings
Postgraduate entrance examination English
JMeter encryption interface test
QT reading SQLSERVER database
Socket programming 2:io reuse (select & poll & epoll)
论文笔记: 多标签学习 BP-MLL
powerdisgner逆向生成oracle数据模型
Redis learning journey master-slave replication
关于c#委托、事件相关问题
MySQL summary