For DBServer, deleting a large table is tricky. To delete a large table, you can create a hard link to The. ibd file of the original table. When multiple file names direct to the same Node, deleting any file name is very fast, because the physical file directly connected is not deleted, but only a pointer is deleted. When the number of Node references is 1, you need to delete all file-related For DB servers, deleting large tables is tricky. To delete a large table, you can create a hard link to The. ibd file of the original table. When multiple file names direct to the same Node, deleting any file name is very fast. Because the physical file for direct connection is not deleted, it is just a pointer. When the number of Node references is 1, delete all data blocks related to the file.
Today we will only discuss how to avoid IO hang when deleting a large file by using the above method to create a hard link file?
The answer is the truncate tool in the coreutils tool set.
Truncate to shrink or expand the file to the specified size
Syntax: truncate option... file...
If the file does not exist, it will be created.
If the size of a file is greater than the specified size, the file will be truncated and lost as part of the data. If the size is smaller than the specified size, it will be filled with 0 bytes.
Option:
-C
-- No-create: if the file does not exist, it will not be created.
-O
-- Io-blocks: the size of the file is treated as an I/O block.
-R rfile
-- Reference = file Base the size of each file on the size of rfile
-S size
-- Size = size adjust the file size according to the following options
'Kb' => 1000 (KiloBytes)
'K' => 1024 (KibiBytes)
'Mb' => 1000*1000 (MegaBytes)
'M' => 1024*1024 (MebiBytes)
'Gb' => 1000*1000*1000 (GigaBytes)
'G' => 1024*1024*1024 (GibiBytes)
Or t p e z.
Adjust the size according to the following symbols according to their own size.
+ Expansion
-Zoom out
<Up
> At least
/A multiple of rounding down
% Multiples of up
Simple Example:
Touch abc
Truncate-s + 1KB abc
Truncate-s + 1KB abc
Ll abc