InnoDB’s tablespace can grow very large in a writeheavy environment. If transactions stay open for a long time (even if they’re not doing any work) and they’re using the default REPEATABLE READ transaction isolation level, InnoDB won’t be able to remove old row versions, because the uncommitted transactions will still need to be able to see them. InnoDB stores the old versions in the tablespace, so the it continues to grow as more data is updated. Sometimes the problem isn’t uncommitted transactions, but just the workload: the purge process is only a single thread, and it might not be able to keep up with the number of old row versions that need to be purged.

In either case, the output of SHOW INNODB STATUS can help you pinpoint the problem.Look at the first and second lines of the TRANSACTIONS section, which show the current transaction number and the point to which the purge has completed. If the difference is large, you may have a lot of unpurged transactions. Here’s an example:

------------

TRANSACTIONS

------------

Trx id counter 0 80157601

Purge done for trx's n:o <0 80154573 undo n:o <0 0

The transaction identifier is a 64-bit number composed of two 32-bit numbers, so you might have to do a little math to compute the difference. In this case it’s easy, because the high bits are just zeros: there are 80157601 – 80154573 = 3028 potentially unpurged transactions (innotop can do this math for you). We said “potentially” because a large difference doesn’t necessarily mean there are a lot of unpurged rows. Only transactions that change data will create old row versions, and there may be many transactions that haven’t changed any data (conversely, a single transaction could have changed many rows).

If you have a lot of unpurged transactions and your tablespace is growing because of it, you can force MySQL to slow down enough for InnoDB’s purge thread to keep up. This may not sound attractive, but there’s no alternative. Otherwise, InnoDB will keep writing data and filling up your disk until the disk runs out of space or the tablespace reaches the limits you’ve defined. To throttle the writes, set the innodb_max_purge_lag variable to a value other than 0. This value indicates the maximum number of transactions that can be waiting to be purged before InnoDB starts to delay further queries that update data. You’ll have to know your workload to decide on a good value. As an example, if your average transaction affects 1 KB of rows and you can tolerate 100 MB of unpurged rows in your tablespace, you could set the value to 100000. Bear in mind that unpurged row versions impact all queries, because they effectively make your tables and indexes larger. If the purge thread simply can’t keep up, performance can decrease dramatically. --如果purge进程跟不上事务更新的速度,那么表和索引文件的大小就会因此增长的很快,而且存在多种版本,innodb在读取或者更新的时候就要进行各种判断,因而性能会急剧降低. Setting the innodb_max_purge_lag variable will slow down performance too, but it’s the lesser of the two evils.--相比而言,设置lag的值比不设置要好.

innodb的purge策略非产复杂,相比而言,在从库上,可以把事务隔离等级设置为read-uncommitted,绕开了innodb的mvcc,也就避免了purge的过程,从而提高性能.同时,对于复杂的事务,就需要读主库了.

mysql清除旧版本_MYSQL使用INNODB时及时清理旧版本数据相关推荐

  1. mysql每隔俩小时、四小时、八小时进行数据统计

    mysql每隔俩小时.四小时.八小时进行数据统计 需求:我们经常会遇到每隔一分钟.一小时.一天.一个月进行数据统计,遇到如标题所说的统计信息比较少见,在遇到一些坑之后,解决了问题,先上坑: HOUR ...

  2. mysql迁移版本_MySQL 5.7迁移升级8.0版本

    MySQL版本升级问题 由于OpenSSL等一些安全漏洞的原因,需要升级MySQL版本. 原本MySQL 5.7.30是使用安装包安装的,计划使用安装包升级补丁5.7.33,升级过程中2个步骤遇到认证 ...

  3. mysql innodb4大特征_MYSQL中InnoDB特性浅谈

    许久没有更新博客,上周末放假把网易大牛姜sir的著作MYSQL技术内幕InnoDB存储引擎又翻阅了一番,对当前工作的InnoDB特性有了一些新的认识,下面谈谈自己的读后感. 1. InnoDB的体系架 ...

  4. 版本向量 使用css时正确区分IE版本[转]

    Windows Internet Explorer Web Windows Internet Explorer 8 版本向量是指的内部版本号,它存储在浏览器启动时读取的注册表项中.开发人员可以使用版本 ...

  5. MySQL数据库锁构建_MySQL数据库InnoDB存储引擎中的锁机制

    00 – 基本概念 当并发事务同时访问一个资源的时候,有可能导致数据不一致.因此需要一种致机制来将访问顺序化. 锁就是其中的一种机制.我们用商场的试衣间来做一个比喻.试衣间供许多消费者使用.因此可能有 ...

  6. mysql更新锁机制_mysql查询更新时的锁表机制分析

    欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 为了给高并发情况下的mysql进行更好的优化,有必要了解一下mysql查询更新时的锁表机制. 一.概述 MySQL有三种锁 ...

  7. lnmp 查看mysql版本_MySQL数据库之Lnmp环境中php-mysql版本问题

    本文主要向大家介绍了MySQL数据库之Lnmp环境中php-mysql版本问题 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 操作系统:CentOS release 6.7 ( ...

  8. mysql数据库断电恢复_MySQL数据库InnoDB引擎下服务器断电数据恢复方法

    说明: 线上的一台MySQL数据库服务器突然断电,造成系统故障无法启动,重新安装系统后,找到之前的MySQL数据库文件夹. 问题: 通过复制文件的方式对之前的MySQL数据库进行恢复,发现在程序调用时 ...

  9. mysql 表 页 行_Mysql之InnoDB行格式、数据页结构

    Mysql架构图 存储引擎负责对表中的数据的进行读取和写入,常用的存储引擎有InnoDB.MyISAM.Memory等,不同的存储引擎有自己的特性,数据在不同存储引擎中存放的格式也是不同的,比如Mem ...

最新文章

  1. 控件的呈现方法(Rendering)的内核
  2. cisco路由器基本实验之七 Standard Access-Lists with RIP (Boson NetSim)
  3. PHP获取IP的多种方式解析
  4. 疫情撬动游戏产业“底层认知”,正向价值愈发突显
  5. SAP Hybris Commerce启用customer coupon的前提条件
  6. 华为云公布2021产品上新计划,让云无处不在,让智能无所不及
  7. Java基础学习总结(63)——Java集合总结
  8. 服务器访问危险网站降权重,网站权重下降,原因有哪些?如何处理?
  9. python 命令模式_python 设计模式之命令模式
  10. linux ftp指定下载文件名称,linux中通过FTP下载指定的文件方法linux网页制作 -电脑资料...
  11. 浅学一维傅里叶变换【下一章发布 : 快速二维傅里叶变换FFT、快速二维傅里叶逆变换IFFT】
  12. Effect Size
  13. 2020电信校园卡已经发售,更新校园卡最新消息及选购建议
  14. android中point pt1,Android dip,px,pt,sp 的区别详解
  15. POI Excel插入线条(直线、斜线)
  16. JAVA图形界面中的事件处理
  17. 离散数学__第2章命题逻辑的推理理论__析取范式和合取范式
  18. 油猴插件(隐藏知乎标题,屏蔽百度搜索广告)
  19. file://android,asset/hto,位于 file:///android_asset/www/..的网页无法加载
  20. 评审8年终获发表,数学天才望月新一证明abc猜想,全球只有十几个数学家读懂但争议未消...

热门文章

  1. /plus/recommend.php sql注入漏洞,代码审计:ThinkPHP框架通杀所有版本的一个SQL注入漏洞详细分析及测试方法 | Seay 渗透 编程 代码审计 网络安全博客...
  2. HALCON 20.11:深度学习笔记(7)---术语表
  3. 企业微信接收消息服务器配置php,微信企业号配置及在公众号里获取用户信息
  4. laravel 数据填充
  5. hadoop hdfs空间满后重新启动不了
  6. mui ajax方法
  7. scala----计数器zipWithIndex
  8. 华为泛BYOD融合网络解决方案实践与演示
  9. c语言速算24源代码,C语言源程序代码-速算24
  10. codesys raspberry pi_【Pi讯早餐】2020.11.02 星期一gt;gt;