当前位置:网站首页>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 .
边栏推荐
- 第一人称视角的角色移动
- Liste des boucles de l'interface graphique de défaillance
- Solution to the problem of automatic login in Yanshan University Campus Network
- Unity scene jump and exit
- Teach you to release a DeNO module hand in hand
- 编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
- Unity场景跳转及退出
- Office prompts that your license is not genuine pop-up box solution
- Classification, understanding and application of common methods of JS array
- FairyGUI循环列表
猜你喜欢
Naive Bayesian theory derivation
数据库课程设计:高校教务管理系统(含代码)
Liste des boucles de l'interface graphique de défaillance
Expected value (EV)
音乐播放(Toggle && PlayerPrefs)
MySQL time, time zone, auto fill 0
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
FGUI工程打包发布&导入Unity&将UI显示出来的方式
NRF24L01故障排查
随机推荐
ESP8266连接onenet(旧版MQTT方式)
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
Knowledge system of digital IT practitioners | software development methods -- agile
Office prompts that your license is not genuine pop-up box solution
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
[leetcode622] design circular queue
Guided package method in idea
Conditional probability
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
Derivation of logistic regression theory
程序设计大作业:教务管理系统(C语言)
MySQL replacement field part content
Fairygui character status Popup
單片機藍牙無線燒錄
CUDA C programming authoritative guide Grossman Chapter 4 global memory
FairyGUI增益BUFF数值改变的显示
Learning notes of JS variable scope and function
Easy to use shortcut keys in idea
2021.11.10 compilation examination
Game 280 weekly