Removing an Orphaned (stale) Virtual Machine Record from the vCenter Server Database.
search cancel

Removing an Orphaned (stale) Virtual Machine Record from the vCenter Server Database.

book

Article ID: 382350

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

  • A virtual machine (VM) is listed as orphaned in vCenter and it's not visible on the ESXi host.
  • The "Remove from Inventory" option is grayed out, preventing its removal from vCenter.

Environment

VMware vCenter Server 8.0.x

VMware vCenter Server 7.0.x

VMware vCenter Server 6.7

Resolution

Before making an attempt at following the steps below, please make sure that a fresh backup or offline snapshot of the vCenter Server Appliance (VCSA) in powered off state exists. If the VCSA is part of an Enhanced Linked Mode (ELM) replication group, please be aware that offline snapshots of all ELM nodes are required to enable a successful rollback if anything goes wrong.

To address this issue, you have 2 options

 

Option 1 - using a dummy VM folder in vSphere Client

  1. In vSphere Client, change into the "VMs and Folders" view.
  2. Create a new Virtual Machine folder.
  3. Drag and drop the orphaned virtual machine into this folder.
  4. Delete the folder. 

 

Option 2 - manually removing the virtual machine related entries from the vCenter vPostgres database

  1. Open an SSH connection to the vCenter Server Appliance and login with the root account
  2. Stop the vCenter Server service:
    # service-control --stop vpxd
  3. Connect to the vCenter vPostgres database:
    # /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
  4. Identify the VM ID in the vCenter database with this command (replace <vm name> against the actual name of the orphaned VM):
    select * from vpx_entity where name like '%<vm name>%'; 
  5. Example Output: 
    VCDB=# select * from vpx_entity where name like '%vcsa%';
    id  |   name    | type_id | parent_id
    ------+----------+---------+-----------
    xxx8 | vcsa |       0 |      xxx2
    xxx9 | vcsa(orphaned) |       0 |      xxx2
  6. Note down the ID of the VM to be deleted from the above output, then use it in the following statements to remove the VM from the VCDB. Attention: These statements must be executed in the order specified to ensure that any constraint definitions in the database are not violated:
    delete from  VPX_COMPUTE_RESOURCE_DAS_VM where VM_ID=xxx9;
    
    delete from  VPX_COMPUTE_RESOURCE_DRS_VM where VM_ID=xxx9;
    
    delete from  VPX_COMPUTE_RESOURCE_ORC_VM where VM_ID=xxx9;
    
    delete from  VPX_VM_SGXINFO where VM_ID=xxx9;
    
    delete from  VPX_GUEST_DISK where VM_ID=xxx9;
    
    delete from  VPX_VM_VIRTUAL_DEVICE where ID=xxx9;
    
    delete from  VPX_VM_DS_SPACE where VM_ID=xxx9;
    
    delete from  VPX_NON_ORM_VM_CONFIG_INFO where ID=xxx9;
    
    delete from  VPX_NORM_VM_FLE_FILE_INFO where VM_ID=xxx9;
    
    delete from  VPX_VDEVICE_BACKING_REL where VM_ID=xxx9;
    
    delete from  VPX_VIRTUAL_DISK_IOFILTERS where VM_ID=xxx9;
    
    delete from  VPX_VM_STATIC_OVERHEAD_MAP where VM_ID=xxx9;
    
    delete from  VPX_VM_TEXT where VM_ID=xxx9;
    
    delete from  VPX_VM where ID=xxx9;
    
    delete from  VPX_ENTITY where ID=xxx9;
  7. Start the vpxd service on the vCenter Server to pick up the database changes.
    # service-control --start vpxd