当前位置:网站首页>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 .
边栏推荐
- Solution to the problem of automatic login in Yanshan University Campus Network
- FairyGUI簡單背包的制作
- FairyGUI简单背包的制作
- Latex learning
- Devops' future: six trends in 2022 and beyond
- Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
- 341. Flatten nested list iterator
- It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
- NRF24L01故障排查
- FairyGUI条子家族(滚动条,滑动条,进度条)
猜你喜欢
Idea problem record
Liste des boucles de l'interface graphique de défaillance
Office prompts that your license is not genuine pop-up box solution
Conditional probability
rtklib单点定位spp使用抗差估计遇到的问题及解决
(一)R语言入门指南——数据分析的第一步
Unity3d, Alibaba cloud server, platform configuration
Unity3D制作注册登录界面,并实现场景跳转
SVN更新后不出现红色感叹号
Esp8266 connect onenet (old mqtt mode)
随机推荐
[Offer29] 排序的循环链表
地球围绕太阳转
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
VLSM variable length subnet mask partition tips
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
idea中导包方法
Redis based distributed ID generator
FGUI工程打包发布&导入Unity&将UI显示出来的方式
Introduction to the daily practice column of the Blue Bridge Cup
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
[Leetcode15]三数之和
FairyGUI增益BUFF數值改變的顯示
FairyGUI摇杆
What are the advantages of using SQL in Excel VBA
Unity场景跳转及退出
NRF24L01 troubleshooting
Derivation of logistic regression theory
Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
Expected value (EV)
Common DOS commands