# PURGE_LOG()

## Function Description

`PURGE_LOG()` is used to delete logs recorded in the MatrixOne database system table. Returning 0 means that the deletion is successful; if the deletion fails, the error message will be returned.

:::{note}
Currently, only the root user (i.e. the cluster administrator with MOADMIN permission) has permission to execute the `PURGE_LOG()` function for log deletion operations.
:::
## Function Syntax

```text
> PURGE_LOG('sys_table_name', 'date')
```

## Parameter definition

| Parameters | Description |
| ---- | ---- |
| 'sys_table_name' | There are only three system tables that can be deleted at present: metric, rawlog, and statement_info. <br> __Note:__ 'sys_table_name' must be wrapped in quotes. |
| 'date' | Select a date to delete the logs generated before that date. <br> __Note:__ 'date' must be wrapped in single quotes. |

:::{note}
MatrixOne has only three system log tables: metric, rawlog, and statement_info. For more information about these three tables, please refer to [MatrixOne System Database and Tables](https://omnifabric.cloudsigma.com/docs/reference/sql/system-tables.html.md).
:::
## Example

- Example 1:

```text
-- Delete the log of type statement_info before this day
mysql> select purge_log('statement_info', '2023-06-30') a;
+---+
| a |
+---+
| 0 |
+---+
1 row in set (0.01 sec)
```

- Example 2:

```text
-- Query the time and quantity of metric log collection
mysql> select date(collecttime), count(1) from system_metrics.metric group by date(collecttime);
+-------------------+----------+
| date(collecttime) | count(1) |
+-------------------+----------+
| 2023-07-07        | 20067    |
| 2023-07-06        | 30246    |
| 2023-07-05        | 27759    |
+-------------------+----------+
3 rows in set (0.04 sec)

-- Delete the logs of rawlog, statement_info, and metric before this day.
mysql> select purge_log('rawlog, statement_info, metric', '2023-07-06');
+-------------------------------------------------------+
| purge_log(rawlog, statement_info, metric, 2023-07-06) |
+-------------------------------------------------------+
| 0                                                     |
+-------------------------------------------------------+
1 row in set (0.33 sec)

-- Query again 2023-07-05, 2023-07-06 and 2023-07-07
mysql> select date(collecttime), count(1) from system_metrics.metric group by date(collecttime);
+-------------------+----------+
| date(collecttime) | count(1) |
+-------------------+----------+
| 2023-07-06        | 30246    |
| 2023-07-07        | 20121    |
+-------------------+----------+
2 rows in set (0.01 sec)
```
