For DB Server, it's tricky to delete a large table. If you delete a large table, you can establish a hard link to the. ibd file of the existing table. When multiple file names point to the same node, deleting any one of the filenames is very quick, because the physical files are not deleted, just a pointer is removed. When the node reference number is 1, deleting the file requires that all data blocks associated with the file be deleted.
Today we'll just talk about how to avoid IO hang if we use the above method to create a hard link file, and then delete that large file. The
answer is the Truncate tool in the Coreutils toolset
Truncate shrink or extend file to a specified size
Syntax: Truncate option ... file ...
If the file does not exist, it will be created.
If the size of a file is larger than the specified size, the file is truncated to a subset of the data, and if size is smaller than specified, he will be populated with 0 bytes.
Option:
-C
--no-create If this file is not created
-o
--io-blocks treats the size of the file with I/O block for
-R rfile
--reference=file Base the size of each file on the size of Rfile
-S size
--size=size adjusts the size of the file
' KB ' according to the options below > 1000 (kilobytes)
' K ' => 1024 (kibibytes)
' MB ' => 1000*1000 (megabytes)
' M ' => 1024*1024 (mebi Bytes)
' GB ' => 1000*1000*1000 (gigabytes)
' G ' => 1024*1024*1024 (gibibytes)
or a unit such as T P E Z is based on the following The symbol of the face, depending on their size to resize
+ expand
-Reduce the
< at most
> at least
/down-round multiple
% up to a multiple
Simple example:
Touch aBC
truncate-s +1kb ABC
truncate-s +1KB ABC
LL ABC
-rwxrwxrwx 1 root root 2000 November 05:31 ABC