# Database Repair

The commands listed below from least to most destructive will fix issues that can occur if the database is corrupted.

### Clear Message Cache

Clearing the message cache removes and recreates the database collection used for internal communication between hosts. When the internal host communication isn't working servers may fail to start and connections my become unstable. Clearing this collection should not require stopping hosts. This can be run without impacting server availability. Hosts will automatically reset the messaging cursor shortly after running the command and resume internal messaging.

```sh
sudo pritunl clear-message-cache
```

### Clear All Cache Data

When there is additional corruption in the database all cached data can be removed. This removes all temporary data like connection states and records for recently used authentication nonces. This data is referred to as secondary data and can be cleared with the commands below. The message cache will also be cleared when running this command. All hosts should be stopped before running this command.

```sh
sudo systemctl stop pritunl
sudo pritunl destroy-secondary
sudo systemctl start pritunl
```

### Full Database Repair

The full database repair is the most extensive repair command and the only command that will result in configuration changes. This command will clear the client IP pools resulting in client static IP addresses being reassigned. If specific client IP addresses were relied on for networking those configurations will need to be updated. Additionally the system logs will be removed from the database, auditing history will not be removed. This command will also clear the message cache and remove all secondary cache data. All hosts should be stopped before running this command.

```sh
sudo systemctl stop pritunl
sudo pritunl repair-database
sudo systemctl start pritunl
```


---

# Agent Instructions: 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:

```
GET https://docs.pritunl.com/kb/vpn/debugging/database-repair.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
