This topic describes the issue of exhausted storage caused by excessive temporary files. This topic also provides a solution on how to release the storage and perform subsequent maintenance.
Problem description
Temporary table files may be generated in a PolarDB for MySQL cluster when a query statement is executed to sort, group, or associate tables in the cluster. Alternatively, cached binary log files are generated before large transactions are submitted. The generated files occupy a large number of storage resources and may exhaust the storage resources of the cluster. In this case, the “The table '/home/mysql/log/tmp/#sql_xxx' is full”
error is reported.
Solution
- Log on to the PolarDB console.
- In the upper-left corner of the console, select the region in which the cluster that you want to manage is deployed.
- Find the cluster and click the cluster ID.
In the upper-right corner of the Basic Information page, click Log on to Database.
In the database that you want to manage, execute the following SQL statement to view a database session:
SHOW PROCESSLIST
Click the State column in the returned query result to sort the data in the column and check whether the column contains a large number of messages such as "Copy to tmp table" and "Sending data". If the column contains a large number of messages, record the session ID.
Execute the following SQL statement to terminate the session:
kill [$ID];
In the preceding statement, [$ID] indicates the session ID mentioned in the preceding step.
ImportantBefore you terminate the session, make sure that the session does not affect your business.
If storage is not released after the preceding steps, you can restart all nodes in the cluster to release the storage occupied by temporary files. For more information about how to restart nodes, see Restart nodes.
What to do next
To prevent temporary files generated in queries from occupying a large amount of storage, you can optimize query statements. For example, you can avoid the frequent usage of the Order By and Group By clauses in query statements. You can use EXPLAIN together with an SQL statement to check whether an internal temporary table is used. Example:
EXPLAIN SELECT * FROM alarm GROUP BY created_on ORDER BY default;
The following output is returned.
If the "Using temporary" message is displayed in the Extra column, an internal temporary table is used.
To prevent cached binary log files from occupying a large amount of storage, you can reduce the number of large transactions, especially large transactions that are run in parallel over multiple connections. If you want to run a large number of large transactions, we recommend that you use short-lived connections. This reduces the storage occupied by cached binary log files.
We recommend that you monitor the storage usage of your cluster on a regular basis, and promptly clear or split data to ensure that storage usage does not exceed 80%.