I have a MySQL database and a big table on it called "tc_positions". Recently I ran out of space on my pc and I'm trying to clean up the database using the command:
delete from tc_positions where servertime < DATE(NOW() - INTERVAL 180 day)
However, I'm encountering the following error:
ERROR 3019 (HY000): Undo Log error: No more space left over in system tablespace for allocating UNDO log pages. Please add new data file to the tablespace or check if filesystem is full or enable auto-extension for the tablespace.
I try with:
ALTER UNDO TABLESPACE tablespace_name SET INACTIVE;
but I get the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNDO TABLESPACE tablespace_name SET INACTIVE' at line 1
I don't know hot to get the undo tablespace name (I'm a noob student), I'm on mysql Ver 14.14 Distrib 5.7.31.
now Is there any way to clean the database out of space in this situation?
Solution: Finally I delete day by day records, then I duplicate a part of the table with 3 days data, drop the biggest table, rename the copy as the original and done. Thanks for all!
-
1Have you considered removing something else and then cleaning your database?Lajos Arpad– Lajos Arpad2024年07月10日 11:38:57 +00:00Commented Jul 10, 2024 at 11:38
-
as @LajosArpad suggested , that could include other files outside of the mysql instance so you can add to the appropriate tablespace to do your clean up then restore when done. longer term you'll need a 'strategy' to deal with exhausting tablespaces - regular purge of older data etc ...ticktalk– ticktalk2024年07月10日 11:47:35 +00:00Commented Jul 10, 2024 at 11:47
-
Yes, but at this point the database takes up almost all the storage spaceClaudio Carrasco– Claudio Carrasco2024年07月10日 11:48:20 +00:00Commented Jul 10, 2024 at 11:48
-
yes @ticktalk, I agree with you, but at this point, I have no choice but to delete old data from the database in order to reduce its size.Claudio Carrasco– Claudio Carrasco2024年07月10日 12:00:06 +00:00Commented Jul 10, 2024 at 12:00
-
restart your db instance, that will (should) clear any undo logs. If your diskspace is nigh on exhausted and you cannot (temporarily) free up space to add to the system undo logs then you have other issues.ticktalk– ticktalk2024年07月10日 13:05:16 +00:00Commented Jul 10, 2024 at 13:05
1 Answer 1
How many records are in that table roughly? If the delete is a large amount of records, you might need to start with a smaller interval. Something like...
delete from tc_positions where servertime < DATE(NOW() - INTERVAL 180 day) limit 10000;
The command you're running doesn't work on the 5.7 distro sadly, which is why you're getting the syntax error.
MySQL also doesn't always reduce the size of a file when data is removed, especially if innodb_file_per_table is turned off. You'll want to enable it, and then alter table tc_positions engine=innodb There are other ways, but they require a lot more diskspace, which you don't seem to have.