Unable to remove a datastore from the vCenter Server inventory
search cancel

Unable to remove a datastore from the vCenter Server inventory

book

Article ID: 302735

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

  • Attempts to access a datastore from the vCenter Server inventory are failing with an error message:
    Datastore <datastore_name> is not accessible. No connected and accessible host is attached to this
  • The datastore is grayed out.
  • The options to unmount or delete the datastore are greyed out.
  • When trying to remount the datastore, an error is shown similar to:
    Datastore conflicts with an existing datastore in the datacenter that has the same URL

Environment

VMware vCenter Server 8.x
VMware vCenter Server 7.x
VMware vCenter Server 6.x

Cause

In most cases this issue occurs when the datastore is removed from the ESX host before removing it from the VMware vCenter Server inventory.

Resolution

To resolve this issue, the datastore references can be manually removed from the vCenter Server Inventory.

Important Note:
  • Before attempting the steps below, please ensure to back up vCenter Server Appliance, or take an offline snapshot of the VCSA. Please be also aware that if the vCenter Server Appliance is a a member of an Enhanced Linked Mode (ELM) replication group, offline snapshots for all of the ELM nodes must be taken. 
  • Ensure that the datastore is not referenced by any virtual machine or VM template, either directly or because an ISO is mounted to the VM that was located on the datastore
  • If there are ISOs attached to VMs or templates attached to the datastore, removing the VM/Template from inventory may resolve the issue.

To manually remove the datastore references from the Inventory:

  1. Stop the VMware VirtualCenter Server (vpxd) service on the vCenter Server:
    # service-control --stop vmware-vpxd
  2. Connect to the vCenter Server database by running the following command:
    # /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
  3. Replace <datastore_name> in the following query against the actual datastore name and run the query to identify the ID of the datastore:
     select ID from VPX_ENTITY where name ='<datastore_name>';
  4. Use the ID from previous step to remove the datastore reference  to delete the datastore from database (replace <id> against the value received in step 3):
    # delete from VPX_DS_ASSIGNMENT where DS_ID=<id>;
    # delete from VPX_VM_DS_SPACE where DS_ID=<id>;
    # delete from VPX_DATASTORE where ID=<id>;
  5. Run this query to delete the datastore from the entity table (again replace <id> against the value received in step 3):
    delete from VPX_ENTITY where ID=<id>;
  6. To verify, that the datastore has been removed from the database, the following commands, using the ID from step 3 in place <id>, should not display any results:
    select * from VPX_DS_ASSIGNMENT where DS_ID=<id>;
    select * from VPX_VM_DS_SPACE where DS_ID=<id>;
    select * from VPX_DATASTORE where ID=<id>;
    select * from VPX_ENTITY where ID=<id>;
  7. Start the VMware VirtualCenter Server (vpxd) service:
    service-control --start vmware-vpxd