---
title: "Remove inactive datastore from vCenter"
canonical: "https://www.virtcloudrocks.com/space/VSPHTECH01/852177/Remove%20inactive%20datastore%20from%20vCenter"
format: markdown
---
Recently we faced an issue where after removing an NFS datastore from all the ESXi hosts, this datastore kept appearing and it was marked as inactive.

We searched through Internet for other people who might have faced this issue, and we came up that the best way to get rid of this datastore was to remove it from the VCSA database.


> ❌ **IMPORTANT NOTE**
> ❌ 
> ❌ Prior performing any of the following activities, please make sure that you have taken a backup or snapshot of the vCenter server.
> ❌ 
> ❌ Do anything of the below tasks with your own risk!

## <span style="color: #003366">Step-by-step guide</span>

1 - Initially make sure that SSH access to the VCSA appliance has been enabled; if not then you need to login to the VCSA appliance and enable it.

2 - Using an SSH client, initiate an ssh connection to the VCSA appliance

3 - As soon as you are connected then execute below command to connect to the PSQL database

```shell
root@crimv3vcsa01 [ ~ ]# /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
```

##### **Results of command execution**

```shell
psql.bin (9.4.9 (VMware Postgres 9.4.9.1-4536683 release))
Type "help" for help.

VCDB=# 
```


4 - At the **VCDB=#** prompt run the below command in order to get details of the datastore in reference; in our case our inactive datastore appeared under the vCenter inventory with the name MEDIA

```shell
VCDB=# SELECT id FROM vpx_entity WHERE name = 'MEDIA';
```

##### **Results of command execution**

```shell
  id
------
 1593
(1 row)
```

As we can see there is an entry for the datastore in reference.


5 - Next we need to find out if this datastore is connected with other objects. To do so run below command in the PSQL prompt,

```shell
VCDB=# SELECT * FROM vpx_ds_assignment WHERE ds_id=1593;
```

##### **Results of command execution**

```shell
 ds_id | entity_id | accessible | mount_path | mount_id | mount_mode | mounted
-------+-----------+------------+------------+----------+------------+---------
  1593 |      1471 |            |            |          |            |
  1593 |      1473 |            |            |          |            |
  1593 |      8930 |            |            |          |            |
(3 rows)
```

Ao it looks that there are some objects that are linked with the datastore ID.


6 - Run below commands in the PSQL prompt, in order to identify those objects,

```shell
VCDB=# SELECT * FROM vpx_entity WHERE id=1471;
   id  |     name     | type_id | parent_id
------+--------------+---------+-----------
 1471 | crimv3dem001 |       0 |      1476
(1 row)
```

```shell
VCDB=# SELECT * FROM vpx_entity WHERE id=1473;
  id  |     name     | type_id | parent_id
------+--------------+---------+-----------
 1473 | crimv3dem002 |       0 |      1476
(1 row)
```

```shell
VCDB=# SELECT * FROM vpx_entity WHERE id=8930;
  id  |                 name                 | type_id | parent_id
------+--------------------------------------+---------+-----------
 8930 | BrightCluster82-Head-Node-001_rhel75 |       0 |      9057
(1 row)
```

So it looks that there are three VMs that are linked with that datastore, and as I recall the datastore, prior its deletion it had some ISO files that were linked to those VMs.

But prior deleting the datastore, I had removed the ISO files from the VMs; in case I checked again the VM settings of each VM and there was not ISO file linked to the CDROM.


7 - In the next steps we proceed and delete the links from the PSQL database. In order to do so, you have to run each command to PSQL prompt.

```shell
VCDB=# DELETE FROM vpx_ds_assignment WHERE ds_id=1593;
VCDB=# DELETE FROM vpx_datastore WHERE id=1593;
VCDB=# DELETE FROM vpx_vm_ds_space WHERE ds_id=1593;
```


8 - Then run below command to remove the datastore from the PSQL database,

```shell
VCDB=# DELETE FROM vpx_entity where ID=1593;
```


9 - Reboot the VCSA appliance and check if the datastore has been removed from the vCenter inventory 🙂

## Related articles

Below it can be found a list of internal / external reference articles

> Macro (ui-button)



> Macro (ui-button)



> Macro (ui-button)



> Macro (ui-button)