当前位置:网站首页>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 .
边栏推荐
- In 2020, the average salary of IT industry exceeded 170000, ranking first
- [leetcode19]删除链表中倒数第n个结点
- MySQL time, time zone, auto fill 0
- Fairygui character status Popup
- Get the position of the nth occurrence of the string
- FairyGUI条子家族(滚动条,滑动条,进度条)
- Common DOS commands
- 第一人称视角的角色移动
- [Nodejs] 20. Koa2 onion ring model ----- code demonstration
- Single chip Bluetooth wireless burning
猜你喜欢
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
Halcon knowledge: gray_ Tophat transform and bottom cap transform
Guided package method in idea
ORA-02030: can only select from fixed tables/views
(五)R语言入门生物信息学——ORF和序列分析
FairyGUI循環列錶
Fabrication d'un sac à dos simple fairygui
Unity scene jump and exit
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
随机推荐
What are the functions and features of helm or terrain
Combination of fairygui check box and progress bar
C programming exercise
【RTKLIB 2.4.3 b34 】版本更新简介一
VLSM variable length subnet mask partition tips
JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
(课设第一套)1-4 消息传递接口 (100 分)(模拟:线程)
[offer29] sorted circular linked list
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
FairyGUI循環列錶
FairyGUI簡單背包的制作
[offer78]合并多个有序链表
單片機藍牙無線燒錄
Office prompts that your license is not genuine pop-up box solution
By v$rman_ backup_ job_ Oracle "bug" caused by details
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
程序设计大作业:教务管理系统(C语言)
Liste des boucles de l'interface graphique de défaillance
What is the maximum length of MySQL varchar field
Containers and Devops: container based Devops delivery pipeline