# Deleting Broker Data Volumes

Deleting broker data volumes permanently removes all persistent MQTT data, including client sessions, retained messages, and subscriptions. This operation is typically performed when you need to completely reset the broker state or decommission a broker cluster.

{% hint style="warning" %}

### Deleting Broker Data is Irreversible

This operation is destructive and cannot be undone. Ensure you have backups if you need to preserve any data.
{% endhint %}

{% tabs %}
{% tab title="Kubernetes" %}

### Deleting Broker Data Volumes on Kubernetes

#### Prerequisites

* [Helm version 3](https://helm.sh/docs/intro/quickstart/#install-helm) is installed on your system.
* [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) is installed on your system.
* You know the name and namespace of your Connectware installation. See [Obtaining the name, namespace, and version of your Connectware installation](/2-3-0/documentation/connectware-on-kubernetes/connectware-helm-chart.md#obtaining-the-name-namespace-and-version-of-your-connectware-installation).

#### Procedure

1. Before making any changes, gather the information you need to complete this procedure.

* **PersistentVolumeClaims list**: List the broker PersistentVolumeClaims (PVCs) to identify which volumes you will delete:

  <pre class="language-bash" data-line-numbers><code class="lang-bash">kubectl get pvc -lapp=broker -n ${NAMESPACE}
  </code></pre>

  **Example output**

  ```
  NAME                  STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
  brokerdata-broker-0   Bound    pvc-3e4cbb94-0e59-4e93-b90b-3fa120ac4d23   1Gi        RWO            efs-sc         <unset>                 11m
  brokerdata-broker-1   Bound    pvc-1316bdc4-5e27-4319-8a15-69e6e8262e12   1Gi        RWO            efs-sc         <unset>                 8m32s
  brokerdata-broker-2   Bound    pvc-6cdbcb83-e7ad-4381-b3ad-bb31484ae7d0   1Gi        RWO            efs-sc         <unset>                 7m58s
  brokerlog-broker-0    Bound    pvc-5f7704ab-c64f-4f0c-b611-1d6ccf476ada   200Mi      RWO            efs-sc         <unset>                 11m
  brokerlog-broker-1    Bound    pvc-52a2c747-7c20-485b-86e9-60cad9e21a45   200Mi      RWO            efs-sc         <unset>                 8m32s
  brokerlog-broker-2    Bound    pvc-467f2e1f-9e64-4981-9c19-cee42b00dfb5   200Mi      RWO            efs-sc         <unset>                 7m58s
  ```

  The output lists two types of volumes. `brokerdata-*` volumes contain message data. You will delete these in step 3. `brokerlog-*` volumes contain only log files, you do not need to delete them for a data reset.
* **Replica count**: Run the following command and write down the number it returns. You will need it in step 5 to scale the broker back up:

  <pre class="language-bash" data-line-numbers><code class="lang-bash">kubectl get sts broker -n ${NAMESPACE} -o jsonpath='{ .status.replicas }'
  </code></pre>

2. Scale the broker cluster down to zero replicas. See [Scaling the Broker Cluster to Zero Replicas](/2-3-0/broker/cybusmq/operations/scaling-the-broker-cluster.md#scaling-down-the-broker-cluster-to-zero).
3. Delete the broker data volumes. Replace `${PVC_NAME}` with the name of each `brokerdata-*` PVC you identified in step 1:

{% code lineNumbers="true" %}

```bash
kubectl delete pvc -n ${NAMESPACE} ${PVC_NAME}
```

{% endcode %}

**Example**

For each PVC that starts with `brokerdata`, run:

{% code lineNumbers="true" %}

```bash
kubectl delete pvc -n ${NAMESPACE} brokerdata-broker-0
```

{% endcode %}

Repeat this command for each `brokerdata-*` volume you identified in step 1.

**Alternative: Automated deletion**

To delete all broker data volumes at once, use the following command:

{% code lineNumbers="true" %}

```bash
kubectl get pvc -lapp=broker -n ${NAMESPACE} -o name | grep brokerdata | xargs kubectl delete -n ${NAMESPACE}
```

{% endcode %}

{% hint style="info" %}
This command deletes only `brokerdata-*` volumes, not `brokerlog-*` volumes.
{% endhint %}

4. Verify that the PersistentVolumeClaims have been deleted:

{% code lineNumbers="true" %}

```bash
kubectl get pvc -lapp=broker -n ${NAMESPACE}
```

{% endcode %}

If the command returns no results, the PVCs have been successfully deleted.

5. After deleting the data volumes, scale the StatefulSet back to the original number of replicas. Replace `${NUM_REPLICAS}` with the replica count you noted in step 1:

{% code lineNumbers="true" %}

```bash
kubectl scale sts broker -n ${NAMESPACE} --replicas ${NUM_REPLICAS}
```

{% endcode %}

The broker pods will restart with fresh, empty data volumes.

#### Cleaning Up Persistent Volumes

Depending on your storage configuration, the underlying PersistentVolumes may still exist after deleting the PersistentVolumeClaims.

1. List any PersistentVolumes that were previously bound to the deleted claims:

{% code lineNumbers="true" %}

```bash
kubectl get pv | grep broker
```

{% endcode %}

2. If PersistentVolumes remain with a `Retain` reclaim policy, delete them manually. Replace `${PERSISTENT_VOLUME_NAME}` with the name from the output of step 1:

{% code lineNumbers="true" %}

```bash
kubectl delete pv ${PERSISTENT_VOLUME_NAME}
```

{% endcode %}

{% hint style="info" %}
PersistentVolumes with a `Delete` reclaim policy are automatically removed when their corresponding PersistentVolumeClaim is deleted.
{% endhint %}
{% endtab %}

{% tab title="Docker Compose" %}

### Deleting Broker Data Volumes on Docker Compose

1. The broker container must be stopped before deleting the volume. If the Connectware is running, go to the Connectware installation directory (default: `/opt/connectware`) and run:

{% code lineNumbers="true" %}

```bash
docker compose down
```

{% endcode %}

2. List all Docker volumes to identify the broker data volume:

{% code lineNumbers="true" %}

```bash
docker volume ls
```

{% endcode %}

3. Locate the broker data volume in the list. It typically has a name like `${INSTALLATION_NAME}_brokerData`.
4. Delete the broker data volume. Replace `${BROKER_DATA_VOLUME}` with the full volume name you identified in step 3:

{% code lineNumbers="true" %}

```bash
docker volume rm ${BROKER_DATA_VOLUME}
```

{% endcode %}

5. Verify that the volume has been deleted:

{% code lineNumbers="true" %}

```bash
docker volume ls | grep broker
```

{% endcode %}

If the volume no longer appears in the output, it has been successfully deleted.

6. Start Connectware again to recreate the broker data volume:

{% code lineNumbers="true" %}

```bash
docker compose up -d
```

{% endcode %}

The broker will create a fresh, empty data volume when it restarts.
{% endtab %}
{% endtabs %}


---

# 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.cybus.io/2-3-0/broker/cybusmq/operations/deleting-broker-data-volumes.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.
