> For the complete documentation index, see [llms.txt](https://docs.opsmx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opsmx.com/opsmx-1/opsmx-context-engine/additional-resources/database/periodic-cleanup-of-historic-data-in-isd-database.md).

# Periodic Cleanup of Historic Data in ISD Database

{% hint style="info" %}
**Note**: Please ensure to configure periodic backup of the database before enabling periodic cleanup.&#x20;
{% endhint %}

### Periodic cleanup of historic data in ISD DB

The Periodic ISD DB cleanup is the process in which the data in the DB tables of ISD across multiple databases are cleaned on a regular basis. To keep the audit DB size under control for optimal performance, this feature is enabled.&#x20;

{% hint style="info" %}
**Important**: Please note that the periodic DB cleanup is disabled by default.&#x20;
{% endhint %}

The list of tables that are cleaned up during this process are:

| **DATABASE** | **TABLE NAME**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PlatformDB   | Service\_deployments\_history                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| VisibilityDB | <p>Pipeline\_executions</p><p>custom\_connector\_data</p><p>Approval\_gate\_parameter</p><p>Approval\_gate\_audit\_data</p><p>Approval\_gate\_audit</p><p>Approval\_gate\_approval</p><p>Approval\_gate\_instance → parent table </p>                                                                                                                                                                                                                                                                                                                                                        |
| SaporDB      | <p>Policy\_gate\_status</p><p>Policy\_gate\_status\_image</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| AuditDB      | <p>Audit\_events</p><p>Pipeline\_execution\_audit\_events</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| AutopilotDB  | <p>LogAnalysis Related Tables</p><p>·       Contextualcluster</p><p>·       Contextualtemplate</p><p>·       Userlogfeedback</p><p>·       Tagsfeedback</p><p>·       Patternfeedback</p><p>·       Entropy</p><p>·       Logclusterscorereduction</p><p>·       Logcluster</p><p>·       loganalysis</p><p>Metric Analysis Related Tables</p><p>·       versionstats</p><p>·       metricscore</p><p>·       logclusterdetails</p><p>Common tables</p><p>·       serviceriskanalysis</p><p>·       riskanalysis\_imageid\_info</p><p>·       riskanalysisjob</p><p>·       riskanalysis</p> |

### Configuration for DB cleanup in ISD:

To enable DB cleanup in ISD, you need to set up a few configurations in ISD as mentioned below.

1. Edit the isd-feature-flag-config config map and set db-cleanup flag as true. Use the command below to edit the config map.

```
kubectl edit cm isd-feature-flag-config -n <namespace name>
```

2. Edit the platform secret and modify the database section as per your requirement for cleaning up the database. Use the command below to edit the platform secret.

```
kubectl edit secret oes-platform-config -n <namespace name>

```

3. Modify the database section configuration in platform secret as below.<br>
   * database:
   * Cleanup:
   * Scheduler
   * enabled: true
   * daysInterval: 18
   * cron: 0 0 0 \* \* \*

**daysInterval**: The number of day intervals in which you want ISD to clean the database should be mentioned here. For example if the value is given as 18 days then ISD will delete 18 days old data in the database.

**cron**: To trigger the database cleanup,you should give the cron expression. Database cleanup cron job will trigger based on the value provided in the cron expression.&#x20;

For example if daysInterval and cron expression are given as mentioned below:

daysInterval: 18

cron: 5 \* \* \* \* \*

Then, database cleanup will happen every 5 minutes and it will delete 18 days old data.

You can refer to the image below on how to set up cron expression.

![](https://lh5.googleusercontent.com/VZnm0hcKch7zD1qZpu8lqMlGBzO7FtD8_aLJJawy7HnsxQb3AVIAu1rsA0-hG5iEhF7NHCTKvBq8Q-lUzzUUfAj_CUNF6nEM9caCO074CUclZqqzjbLvEm1JSdys3DVOP_8WZVcffV3OXRCIKGR5vGs)

4. Now restart the platform pod in your namespace. The  database cleanup is set in your ISD successfully. Use the command given below to restart your platform pod.

```
kubectl rollout restart deploy oes-platform -n <namespace name>
```

To verify the database cleanup is done, you can connect to your database and execute  the below commands.

| **DATABASE**                | **COMMANDS**                                                                                                                                                                                                                                                                                                           |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PlatformDB                  | <p>To enter into platform db</p><p>\c platformdb</p><p>To get the total record count</p><p>select COUNT(*) from service\_deployments\_history; </p><p>To get the record count which is of 40 days older</p><p>select COUNT(*) from service\_deployments\_history where created\_at < now() - interval '40 days';  </p> |
| <p>VisibilityDB</p><p> </p> | <p>\c visibilitydb</p><p>select COUNT(*) from approval\_gate\_instance;</p><p>select COUNT(*) from approval\_gate\_instance where activated\_time < now() - interval '40 days';</p><p> </p>                                                                                                                            |
| <p>Autopilot DB</p><p> </p> | <p>\c opsmx</p><p>select COUNT(*) from riskanalysis;</p><p>select COUNT(*) from riskanalysis where opsmxcreateddate < now() - interval '40 days';</p><p> </p>                                                                                                                                                          |
| <p>Sapor DB</p><p> </p>     | <p>\c oesdb</p><p>select COUNT(*) from policy\_gate\_status;</p><p>select COUNT(*) from policy\_gate\_status where created\_date < now() - interval '40 days';</p><p> </p>                                                                                                                                             |
| <p>Audit DB</p><p><br></p>  | <p>\c auditdb</p><p>select COUNT(*) from audit\_events;</p><p>select COUNT(*) from audit\_events where created\_at < now() - interval '40 days';</p><p> </p>                                                                                                                                                           |

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.opsmx.com/opsmx-1/opsmx-context-engine/additional-resources/database/periodic-cleanup-of-historic-data-in-isd-database.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
