简体   繁体   中英

Mariadb - How to delete history by query?

My Mariadb Version : 10.3.23

Problem: My server's disk is reaching saturation point soon, I got many useless history data in my database. My table is created with SYSTEM VERSIONING. I want delete the useless history data by query like below:

DELETE HISTORY FROM my_table FOR SYSTEM_TIME ALL where my_table.id = 2152 

I got error message :

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SYSTEM_TIME ALL where writing_id= 2152'

Question: How to delete useless historical data associated with a id ?

Correct syntax for deleting useless history is described in User Manual , for example, if you want to remove versions with the age of a month or above use:

DELETE HISTORY 
    FROM table_name 
    BEFORE SYSTEM_TIME (CURRENT_DATE - INTERVAL 1 MONTH);

You cannot delete versioning history for separate rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM