linux中快速删除大文件

在搞mha的时候,看到了一个介绍linux上使用硬连接快速删除大文件的方法,以前还真没注意过。测试如下:

在创建测试表的时候,遇到了下面的错误
mysql> insert into test select * from test;
ERROR 1206 (HY000): The total number of locks exceeds the lock table size
If you’re running an operation on a large number of rows within a table that uses the InnoDB storage engine, you might see this error:

ERROR 1206 (HY000): The total number of locks exceeds the lock table size

MySQL is trying to tell you that it doesn’t have enough room to store all of the row locks that it would need to execute your query. The only way to fix it for sure is to adjust innodb_buffer_pool_size and restart MySQL. By default, this is set to only 8MB, which is too small for anyone who is using InnoDB to do anything.

If you need a temporary workaround, reduce the amount of rows you’re manipulating in one query. For example, if you need to delete a million rows from a table, try to delete the records in chunks of 50,000 or 100,000 rows. If you’re inserting many rows, try to insert portions of the data at a single time
from:http://blog.chinaunix.net/uid-25266990-id-3293445.html

这个错误会导致事务回滚。我的饿测试环境是事务非自动提交,第二次创建测试表的时候在创建测试表的时候,每次insert后都commit下,没有在出现上面的报错,但是发现commit随着buffer中脏数据的数量增大而变慢(mysql中所有的操作写入log buffer,不会后台自动刷新,数量超过log buffer后写入临时表中,commit的时候会将所有的log写入磁盘),这个跟oracle不同,oracle中commit的速度是个很快的操作,跟数据量无关。

mysql> insert into test select * from test;
Query OK, 5193728 rows affected (1 min 12.79 sec)
Records: 5193728 Duplicates: 0 Warnings: 0

mysql> commit;
Query OK, 0 rows affected (9.93 sec)

mysql> insert into test select * from test;
Query OK, 10387456 rows affected (2 min 19.96 sec)
Records: 10387456 Duplicates: 0 Warnings: 0

mysql> commit;
Query OK, 0 rows affected (11.56 sec)

mysql> insert into test select * from test;
Query OK, 20774912 rows affected (4 min 25.23 sec)
Records: 20774912 Duplicates: 0 Warnings: 0

mysql> commit;
Query OK, 0 rows affected (19.37 sec)

创建了2个相同数据量大小的表,对比测试下:
ll
-rw-rw—-. 1 my3333 mysql 17702 May 15 16:51 test2.frm
-rw-rw—-. 1 my3333 mysql 32585547776 May 15 17:23 test2.ibd
-rw-rw—-. 1 my3333 mysql 17702 May 15 15:53 test.frm
-rw-rw—-. 1 my3333 mysql 32585547776 May 15 16:40 test.ibd

mysql> drop table test;
Query OK, 0 rows affected (1.85 sec)
[root@hz-10-200-142-43 test]# ln test2.ibd test2.idbbak
[root@hz-10-200-142-43 test]# ll

-rw-rw—-. 1 my3333 mysql 17702 May 15 16:51 test2.frm
-rw-rw—-. 2 my3333 mysql 32585547776 May 15 17:23 test2.ibd
-rw-rw—-. 2 my3333 mysql 32585547776 May 15 17:23 test2.idbbak
mysql> drop table test2;
Query OK, 0 rows affected (1.08 sec)
看到使用硬链接的方式删除,时间上是少了0.8s。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值