Error
Error Code:
1021
MariaDB Error 1021: Disk Full Error
Description
Error 1021 indicates that the MariaDB server has encountered a 'disk full' condition on one of its storage volumes. This prevents the server from performing any write operations, including data inserts, updates, or creating temporary files for query processing, effectively halting database activity.
Error Message
Disk full (%s); waiting for someone to free some space...
Known Causes
3 known causesDatabase Data Growth
The MariaDB data directory, including data files, indexes, and transaction logs, has expanded to consume all available disk space on its partition.
Excessive Temporary Files
Large or complex queries generate numerous temporary files for sorting, grouping, or joining operations, quickly exhausting the disk partition designated for temporary storage.
Non-MariaDB Disk Usage
Other applications, system logs, backups, or unrelated files on the same disk partition have consumed all available storage, leaving no room for MariaDB operations.
Solutions
4 solutions available1. Identify and Purge Large Unnecessary Files easy
Locate and remove large files that are not essential for database operation.
1
Determine the disk space usage of your MariaDB data directory and other critical file systems. You can use the `df -h` command on Linux/macOS or File Explorer on Windows.
df -h
2
Navigate to your MariaDB data directory (e.g., `/var/lib/mysql/` on Linux). Identify large files or directories that are not part of your active databases. This could include old backup files, large log files, or orphaned temporary files.
cd /var/lib/mysql/
3
Use the `du -sh *` command to analyze the disk usage of files and directories within the data directory. Sort the output to find the largest ones.
du -sh * | sort -rh
4
Once identified, safely remove unnecessary files. **Caution: Always back up important data before deleting anything.**
rm -rf /path/to/large/unnecessary/file
2. Manage MariaDB Log Files medium
Reduce disk space by managing and rotating MariaDB's binary and error logs.
1
Check the size of your MariaDB log files. These are typically found in the MariaDB data directory. Common logs include the error log (`error.log`) and binary logs (`mysql-bin.xxxxxx`).
ls -lh /var/lib/mysql/*.log
2
Configure log rotation to automatically manage log file sizes and retention. Edit your MariaDB configuration file (e.g., `my.cnf` or `mariadb.conf.d/50-server.cnf`).
[mysqld]
log_bin = /var/lib/mysql/mysql-bin
binlog_expire_logs_seconds = 259200 # Keep binary logs for 3 days (72 hours * 3600 seconds/hour)
3
For binary logs, you can also set `expire_logs_days` (though `binlog_expire_logs_seconds` is preferred in newer versions) or use `max_binlog_size` to limit individual binary log file size.
[mysqld]
# expire_logs_days = 3 # Older method
max_binlog_size = 100M # Limit individual binary log file size to 100MB
4
Restart the MariaDB service for configuration changes to take effect.
sudo systemctl restart mariadb
5
Manually purge old binary logs if immediate space is needed and automatic rotation is not yet effective or sufficient.
PURGE BINARY LOGS TO 'mysql-bin.XXXXXX';
3. Optimize Table Storage and Clean Up medium
Reduce the size of your database tables by optimizing them and removing unused data.
1
Identify tables that are consuming significant disk space. You can query the information schema.
SELECT table_schema AS 'Database', SUM(data_length + index_length) / 1024 / 1024 AS 'Size in MB' FROM information_schema.tables GROUP BY table_schema ORDER BY SUM(data_length + index_length) DESC;
2
For InnoDB tables, run `OPTIMIZE TABLE` to reclaim space from deleted rows and fragmented data. This can be a time-consuming operation on large tables.
OPTIMIZE TABLE your_database_name.your_table_name;
3
For MyISAM tables, `OPTIMIZE TABLE` also defragments and repairs tables, which can reclaim space.
OPTIMIZE TABLE your_database_name.your_table_name;
4
Consider removing old or unnecessary data from your tables. This is a fundamental data management task that directly impacts disk usage.
DELETE FROM your_database_name.your_table_name WHERE your_condition_for_deletion;
5
After deleting large amounts of data, it's highly recommended to run `OPTIMIZE TABLE` again to reclaim the space effectively.
OPTIMIZE TABLE your_database_name.your_table_name;
4. Expand Disk Capacity easy
The most direct solution is to increase the available disk space for your MariaDB server.
1
Identify the file system where your MariaDB data directory resides.
df -h /var/lib/mysql/
2
If using a virtual machine or cloud instance, provision additional disk space or attach a new volume. The steps vary depending on your virtualization platform (e.g., VMware, AWS EC2, Azure VM).
N/A
3
If using a physical server, add a new hard drive or expand existing partitions. This may require downtime.
N/A
4
Once new storage is available, you'll need to mount it and potentially move your MariaDB data directory to the new location. **This will require stopping MariaDB.**
sudo systemctl stop mariadb
# Steps to mount new disk and move data directory
# ... (e.g., mkfs, mount, rsync)
sudo systemctl start mariadb
5
Alternatively, if you've added space to an existing logical volume or partition, you might be able to resize it online. Consult your operating system's documentation for LVM or partition resizing.
N/A