# Revert a PV Stuck in a Deleting State

## Problem

You accidentally deleted a PV but now it is stuck in a deleting state due to it being attached to a pod.

## Environment

* Platform9 Managed Kubernetes - All Versions

Cause

The reason for PV not being deleted successfully is because the `kubernetes.io/pv-protection` finalizer protects it from being deleted while being attached to a pod.

## Resolution

{% hint style="warning" %}
**Warning**

Please create an ETCD backup before proceeded with the below steps. If you are not sure about the commands that need to be run, reach out to our Support Team for requesting assistance.
{% endhint %}

1. Login to the master node of the canary cluster and run the following command.

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

```javascript
# /opt/pf9/pf9-kube/bin/etcdctl --cert /etc/pf9/kube.d/certs/etcdctl/etcd/request.crt --cacert /etc/pf9/kube.d/certs/etcdctl/etcd/ca.crt --key /etc/pf9/kube.d/certs/etcdctl/etcd/request.key get / --prefix --keys-only | grep -i 'persistentvolume'
```

{% endtab %}
{% endtabs %}

2. In the output, you will find the name of the PV that is stuck in a Terminating state. Run the following command to get the PV data from ETCD:

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

```javascript
# /opt/pf9/pf9-kube/bin/etcdctl --cert /etc/pf9/kube.d/certs/etcdctl/etcd/request.crt --cacert /etc/pf9/kube.d/certs/etcdctl/etcd/ca.crt --key /etc/pf9/kube.d/certs/etcdctl/etcd/request.key get /registry/persistentvolumes/<pv_name>
```

{% endtab %}
{% endtabs %}

3. Copy the JSON output from the above command and use a text editor to remove the following 2 key value pairs:

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

```javascript
DeletionTimestamp
DeletionGracePeriodSeconds
```

{% endtab %}
{% endtabs %}

4. Once you have the edited JSON, use the following command to update the ETCD using the following command.

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

```javascript
# /opt/pf9/pf9-kube/bin/etcdctl --cert /etc/pf9/kube.d/certs/etcdctl/etcd/request.crt --cacert /etc/pf9/kube.d/certs/etcdctl/etcd/ca.crt --key /etc/pf9/kube.d/certs/etcdctl/etcd/request.key put /registry/persistentvolumes/<pv_name> '<edited_JSON>'
```

{% 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://platform9.com/kb/pmk/solutions/revert-a-pv-stuck-in-a-deleting-state.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.
