当前位置:网站首页>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 .
边栏推荐
- MySQL replacement field part content
- 音乐播放(Toggle && PlayerPrefs)
- VLSM variable length subnet mask partition tips
- 地球围绕太阳转
- The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
- GNSS定位精度指标计算
- Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
- RTKLIB: demo5 b34f.1 vs b33
- Office提示您的许可证不是正版弹框解决
- Easy to use shortcut keys in idea
猜你喜欢
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
MySQL time, time zone, auto fill 0
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
使用rtknavi进行RT-PPP测试
单片机蓝牙无线烧录
Unity3d makes the registration login interface and realizes the scene jump
Guided package method in idea
ESP8266连接onenet(旧版MQTT方式)
What are the advantages of using SQL in Excel VBA
随机推荐
Lean product development - Lean Software Development & lean product development
[offer9]用两个栈实现队列
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
(一)R语言入门指南——数据分析的第一步
RTKLIB: demo5 b34f.1 vs b33
ESP8266连接onenet(旧版MQTT方式)
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
[offer9] implement queues with two stacks
FairyGUI条子家族(滚动条,滑动条,进度条)
CUDA C programming authoritative guide Grossman Chapter 4 global memory
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
[leetcode15] sum of three numbers
In 2020, the average salary of IT industry exceeded 170000, ranking first
(1) Introduction Guide to R language - the first step of data analysis
Idea problem record
FairyGUI摇杆
Meanings and differences of PV, UV, IP, VV, CV
(五)R语言入门生物信息学——ORF和序列分析
(课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)