Manually removing an ESXi host from the vCenter Server database
search cancel

Manually removing an ESXi host from the vCenter Server database

book

Article ID: 314599

calendar_today

Updated On:

Products

VMware vCenter Server VMware vCenter Server 7.0 VMware vCenter Server 8.0 VMware vCenter Server 6.0

Issue/Introduction

This article provides steps to manually remove an ESXi host from the vCenter Server database.
 
Warnings:
  • This procedure should only be used as a last resort where all other attempts to remove an ESXi host from the vCenter Server Inventory fail.
  • Before performing any database operations, take a full backup of the database. VMware recommends that you consult a Database Administrator (DBA) before implementing any changes to the database configuration.
  • This procedure does not work for Oracle database.


Symptoms:
  • An ESXi host is decommissioned without first removing it from the Inventory in vCenter Server.
  • The ESXi host no longer exists, physically or in DNS, but is shown as Disconnected in vCenter Server.
  • The ESXi host cannot be removed from the vCenter Inventory.
  • If you select either Remove or Connect in vCenter Server, you see an error similar to:

    Unable to access to the specified host. It either does not exist, the server software is not responding, or there is a network problem.

     
  • When there is a ghosted host on the vDS (vNetwork Distributed Switch), you see entries similar to these in the vpxd.log file:

    [YYYY-MM-DD hh:mm:ss.283 01624 warning 'App' opID=35C8EC56-0010FD71] [MoDVSwitch::UpdateHostNetworkSummaryOnDvsDestroy] Invalid host member [host-635] found in the vDS. [2011-05-31 12:24:32.295 01624 error 'App' opID=35C8EC56-0010FD71] [MoDVSwitch::HostCallPreFlightCheckInt] DVS.ConfigSpec.host[host-635].host not registered in vmom
     
  • The host is already connected to this vCenter Server


Environment

VMware vCenter Server 6.0.x
VMware vCenter Server 7.0.x
VMware vCenter Server 8.0.x

Resolution

Warning: Theses steps should not be used on environments using vCloud Director.

Caution: Please consult a Broadcom Support Engineer before performing these steps

Note: These steps are for vCenter Server using a Microsoft SQL database or vPostgres.

ESXi 6.x and 7.x

To manually remove an ESXi 6.x and 7.x host from the vCenter Server database:

  1. Stop the vpxd service on the vCenter Server. For more information, see Stopping, starting, or restarting vCenter services (1003895) for Windows vCenter and
    Stopping, Starting or Restarting VMware vCenter Server Appliance 6.x & above services (2109887) for vCenter Appliance


    service-control --stop vmware-vpxd

     

  2. Connect to the vCenter Server vPostgres database:

    /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres

  3. Identify the ESXi host ID in the vCenter database with this command:

    select ID, parent_id from VPX_ENTITY where name ='<esxi host name>';

    Note: For example, the ESXi host being removed is esx01.vmware.com. This host returns a host ID of 24699 when the preceding select statement is executed.
     
  4. Execute these SQL statements to remove the ESXi host from the vCenter database.

    Note: The SQL statements must be executed in the order specified to ensure that any constraint definitions in the database are not violated.

     
    1. Remove all the datastore assignments for virtual machines which exist on this ESXi host with this statement:
      delete from vpx_ds_assignment where entity_id in (select id from vpx_vm where host_id = 24699);
       
    2. Remove all the network assignments virtual machines that exist on this ESXi host with this statement:
      delete from vpx_nw_assignment where entity_id in (select id from vpx_vm where host_id = 24699);
       
    3. List the virtual machines in the virtual machine table which exist on this ESXi host with this statement:
      select id from vpx_vm where host_id = 24699;

      Note: Make a note of the virtual machine IDs returned.
       
    4. Remove the virtual machines from the previous step using Wolken | Manually removing a stale VM from the vCenter Server vpostgres database(311105)
    5. Delete the DVS entries associated with the ESXi host with this statement:
      delete from vpx_dvhost where host_id = 24699;
      delete from vpx_dvport_membership where host_id = 24699;
      delete from vpx_dvs_blob where host_id = 24699;
       
    6. Delete the ESXi host from the host table with this statement:
      delete from vpx_host where id = 24699;
      Notes:
      • A cascade delete constraint definition (constraint FK_VPX_HOST_REFERENCE_VPX_HOST foreign key (HOST_ID) references VPX_HOST (ID) on delete cascade) is created on these tables. Corresponding entries with matching HOST_ID=24699 automatically get removed from these tables:
        vpx_host_x
        vpx_host_vm_config_option
        vpx_compute_resource_dpm_host
        vpx_host_cpu
        vpx_host_node
        vpx_host_node_cpu
        vpx_host_pci_device
         
      • A cascade delete constraint definition (constraint FK_VPX_CPU_THREAD_REF_HOST_CPU foreign key (HOST_ID, CPU_INDEX) references VPX_HOST_CPU (HOST_ID, CPU_INDEX) on delete cascade) is created on these tables. Corresponding entries with matching HOST_ID=24699 automatically get removed from these tables:
        vpx_host_cpu_thread
        vpx_host_cpu_cpuid_feature
         
    7. Delete the ESXi host from the entity table with this statement:
      delete from vpx_entity where id = 24699;
       
    8. Remove all relations to this ESXi host from the entity table with this statement:
      delete from vpx_entity where parent_id = 24699;
      delete from vpx_entity where id = 24699;
  5. Start the vpxd service on the vCenter Server to pick up the database changes. For more information, see Stopping, starting, or restarting vCenter services (1003895) for Windows vCenter and Stopping, Starting or Restarting VMware vCenter Server Appliance 6.x & above services (2109887) for vCenter Appliance.

In case the ESXi Host is as standalone host (not part of a cluster), additional steps needs to be taken to avoid any invalid situation where a standalone compute resource is left without a host.

 

To remove standalone ESXi Host from vCenter Database:

  • Apply same first two steps ( stop vpxd and identify the ESXi Host ID) 
  • In the Execute SQL statement step, please apply the below two extra steps:
  1. Check for orphaned compute resources with this statement:

SELECT id, name FROM vpx_entity WHERE type_id = 2 and id not in (SELECT a.id FROM vpx_entity as A LEFT JOIN vpx_entity as B ON A.id = B.parent_id where a.type_id=2 and b.type_id=1 GROUP BY A.id);

Example:

"SELECT * FROM vpx_entity WHERE type_id = 2 and id not in (SELECT a.id FROM vpx_entity as A LEFT JOIN vpx_entity as B ON A.id = B.parent_id where a.type_id=2 and b.type_id=1  GROUP BY A.id);"

id | name |

--------+--------------------------+---------+-----------

187911 | somename---------------- |

187913 | somename---------------- |

(2 rows)

  1. If some records are displayed, DELETE all zombies (XXX is the id of each compute resource from step 1):

DELETE FROM vpx_entity WHERE parent_id = XXX;

DELETE FROM vpx_entity WHERE id = XXX;

Example:

DELETE FROM vpx_entity WHERE parent_id = 187911;

DELETE FROM vpx_entity WHERE id = 187911;