当前位置:网站首页>MySQL shutdown is slow
MySQL shutdown is slow
2022-07-06 12:48:00 【wx5caecf2ed0645】
http://www.orczhou.com/index.php/2010/12/more-about-mysql-innodb-shutdown/
http://www.orczhou.com/index.php/2014/03/some-tricky-about-mysqladmin-extended-status/
https://dbarobin.com/2015/08/29/mysql-optimization-under-ssd/
https://www.percona.com/blog/2016/05/05/percona-server-5-7-multi-threaded-lru-flushing/
https://yq.aliyun.com/articles/40903?spm=5176.8091938.0.0.b6sdPr
https://yq.aliyun.com/groups/25
http://mysql.taobao.org/index.php?title=MySQL%E5%86%85%E6%A0%B8%E6%9C%88%E6%8A%A5_2015.02
Fast closing MySQL/InnoDB
If the engine used is InnoDB, Every time you knock mysqladmin -uroot -p shutdown When closing the database , It is always difficult to predict how long this command will be executed , Practical experience shows that , As short as five seconds , As long as 30 minutes, an hour is possible . Also share my experience .
1. Why? InnoDB Closing will be slow ?
in fact , Not every time it closes InnoDB Very slow .Why?InnoDB in comparison with MyISAM, An important feature is InnoDB Will open up a... In memory Buffer Pool To store recently accessed data blocks / Index block , So that the next time you visit this block, the speed can be very fast . When InnoDB When the data block needs to be modified , The modification log will be recorded first , And then directly to Buffer_Pool Operation of data blocks in . Logging is sequential , Operations on data blocks are memory operations , This makes InnoDB This is a good speed advantage in many scenarios .
After the above modification of the memory block ,InnoDB It returns to the client . At this time, the data block on the actual disk , Has not been updated , We put this page be called Dirty Page. stay InnoDB There is a special thread in the background to do the memory data block Flush Work to disk . This Flush Operation is the main influence InnoDB The factor of closing time . Closing MySQL/InnoDB when , be-all Dirty_Page Need to be Flush, therefore Dirty_Page The more , want Flush The more data blocks there are , signify InnoDB The longer the closing time .
We can observe through the following commands Dirty Page The number of :
mysqladmin -uroot ext -i 1 |grep "Innodb_buffer_pool_pages_dirty"
2. Parameters innodb_max_dirty_pages_pct
Buffer_Pool in Dirty_Page The amount of , direct influence InnoDB The closing time of . Parameters innodb_max_dirty_pages_pct It can be directly controlled Dirty_Page stay Buffer_Pool The percentage of the , And fortunately innodb_max_dirty_pages_pct It can be changed dynamically .
therefore , Closing InnoDB Before that innodb_max_dirty_pages_pct The small , Force data blocks Flush A span , Can greatly shorten MySQL Closing time .
set global innodb_max_dirty_pages_pct=0;
Generally, after executing the above command ,Dirty_Page Of Flush It will take some time , So wait a minute , To shut down MySQL It works .
3. What to do before closing
occasionally , Even if you change innodb_max_dirty_pages_pct=0, There is still no guarantee InnoDB Fast closing . There are also some considerations .
Set the database to read-only : If the database is always active , There is a connection writing data to it , that Dirty Page It may also continue to produce .
In case of standby database , stay innodb_max_dirty_pages_pct Set to 0 At the same time , Better first stop slave: This is the key , And it will also have a great impact on the closing time . First of all , Take the initiative stop slave after ,MySQL When closed , There are actually fewer threads that need to be stopped . second , If slave Of SQL If the thread is still executing ,Buffer Pool Is still active ,Dirty Page It may also continue to increase .
commonly , If you notice the above three points :
set global innodb_max_dirty_pages_pct=0
set global read_only=1
stop slave
Close the database , It will be very soon . If you finish the above three steps , Then observe Dirty Page The number of , When the quantity is small , Then execute the command to close the Library , In this way, it can always ensure that the library closing command can be completed at a faster speed .
4. A note
What needs to be noted here is , You don't have to wait Dirty Page To zero , Just started to close MySQL. Because sometimes , Even if there is no active session ,InnoDB Of Insert Buffer The merger of will still produce some Dirty Page, So at this time you may find , I waited for a long time Dirty Page The number of is still greater than zero .
In fact, at this time , You can close the database quickly . How can I judge this situation ? Then we can go through InnoDB Of LSN To judge , Here is SHOW InnoDB Status The information obtained inside :
Log sequence number 814 3121743145
Log flushed up to 814 3121092043
Last checkpoint at 814 2826361389
See here , Current LSN yes 814 3121743145, The last checkpoint is 814 2826361389, That is to say, there is a difference between the two 3121743145-2826361389=295381756, That means InnoDB There are still a lot of it Dirty Page need Flush.
Here is another library LSN Information :
Log sequence number 0 1519256161
Log flushed up to 0 1519256161
Last checkpoint at 0 1519256161
You can see , there Dirty Page Have been Flush 了 , So close it InnoDB Soon .
commonly , There is no need to wait until the last checkpoint and the current LSN Equal to close , As long as the difference between the two is not much (<1000) It will close quickly .
5. Last but not least
Actually , Toss like this , The whole process of closing the library may not be as good as your direct execution mysqladmin -uroot shutdown fast , But perform the above steps , It will let you know how long it is to close the warehouse , It can make your customs command complete in a predictable time . To put it simply , It will make the time to close the warehouse have a bottom in mind .
边栏推荐
- (五)R语言入门生物信息学——ORF和序列分析
- By v$rman_ backup_ job_ Oracle "bug" caused by details
- Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
- There is no red exclamation mark after SVN update
- 地球围绕太阳转
- NovAtel 板卡OEM617D配置步骤记录
- [leetcode19] delete the penultimate node in the linked list
- Flink late data processing (3)
猜你喜欢
数据库课程设计:高校教务管理系统(含代码)
KF UD分解之UD分解基础篇【1】
Office prompts that your license is not genuine pop-up box solution
NRF24L01故障排查
Vulnhub target: hacknos_ PLAYER V1.1
Conditional probability
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Redis based distributed ID generator
随机推荐
InnoDB dirty page refresh mechanism checkpoint in MySQL
Mysql database index
341. Flatten nested list iterator
Single chip Bluetooth wireless burning
Special palindromes of daily practice of Blue Bridge Cup
使用rtknavi进行RT-PPP测试
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
(1) Introduction Guide to R language - the first step of data analysis
基于rtklib源码进行片上移植的思路分享
Unity3D制作注册登录界面,并实现场景跳转
idea中好用的快捷键
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
[offer9]用两个栈实现队列
FairyGUI简单背包的制作
What is the maximum length of MySQL varchar field
(一)R语言入门指南——数据分析的第一步
Expected value (EV)
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Esp8266 connect onenet (old mqtt mode)