Manually remove ESXi host from vCenter database

Share this:

Some time ago, after I tried to remove ESXi host from vCenter it was still appearing in vSphere client with alert and I couldn’t remove it again. Someone would say it is just cosmetic issue, but for example storage service was failing from initializing because of it too. VMware support provided me with manual how to do manual cleanup directly in database, as it wasn’t publicly available at the time of my issue. I would like to share sequence with you (I performed this procedure in vCenter 5.5, however according to VMware it should work from 2.5):

Warning: Sequence is provided as is and without any guarantee and should be used only as last resort if all attempts to remove host failed, although I’ve got the sequence from VMware support it is not official, and you can seriously damage your database. I strongly recommend you to contact VMware support in case of similar issues. Make sure you have latest backup of you vCenter database.

1. Stop the VMware VirtualCenter service on the vCenter Server. 2. Identify the ESX host ID in the vCenter database with the command:

select ID from VPX_ENTITY where name ='10.66.4.211';

Note: ESXi host being removed is 10.66.4.211 was previously added under IP not DNS name. This name  returned a host ID of 2445 when the select statement above was executed.

3. Execute these SQL statements to remove the ESX\ESXi host from the vCenter database.

Note: There are constraint definitions defined in the database therefore following SQL statements must be executed in the order.

a. Remove all the datastore assignments for virtual machines which exist on this ESXi host with the statement:

delete from vpx_ds_assignment where entity_id in (select id from vpx_vm where host_id = 2445);

b. Remove all the network assignments virtual machines that exist on this ESXi host with the statement:

delete from vpx_nw_assignment where entity_id in (select id from vpx_vm where host_id = 2445);

c. List the virtual machines in the virtual machine table which exist on this ESX\ESXi host with the statement:

select id from vpx_vm where host_id = 2445;

Make a note of any virtual machine IDs returned. In this example, the values returned are 26149, 26215, 26217, 26219, 95343.

d. Delete virtual machines which exist on this ESXi from the virtual machine table with the statement:

delete from vpx_vm where host_id = 2445;

e. Delete virtual machines which exist on this ESXi host from the entity table with the statement:

delete from vpx_entity where id in (26149,26215,26217,26219,95343);

f. Delete the DVS entries associated with the ESX\ESXi host with the statement:

delete from vpx_dvhost where host_id = 2445;
delete from vpx_dvport_membership where host_id = 2445;
delete from vpx_dvs_blob where host_id = 2445;

g. Delete the ESXi host from the host table with the statement:

delete from vpx_host where id = 2445;

h. Remove all relations to this ESX host from the entity table with the statement (Actually in my case only this step was necessary):

delete from vpx_entity where parent_id = 2445;
delete from vpx_entity where id = 2445;

4. Start the VMware vCenter Server service on the vCenter Server to pick up the database changes.

The following two tabs change content below.
With over 12 years of experience in the Virtualization field, currently working as a Senior Consultant for Evoila, contracted to VMware PSO, helping customers with Telco Cloud Platform bundle. Previous roles include VMware Architect for Public Cloud services at Etisalat and Senior Architect for the VMware platform at the largest retail bank in Slovakia. Background in closely related technologies includes server operating systems, networking, and storage. A former member of the VMware Center of Excellence at IBM and co-author of several Redpapers. The main scope of work involves designing and optimizing the performance of business-critical virtualized solutions on vSphere, including, but not limited to, Oracle WebLogic, MSSQL, and others. Holding several industry-leading IT certifications such as VCAP-DCD, VCAP-DCA, VCAP-NV, and MCITP. Honored with #vExpert2015-2019 awards by VMware for contributions to the community. Opinions are my own!

About Dusan Tekeljak

With over 12 years of experience in the Virtualization field, currently working as a Senior Consultant for Evoila, contracted to VMware PSO, helping customers with Telco Cloud Platform bundle. Previous roles include VMware Architect for Public Cloud services at Etisalat and Senior Architect for the VMware platform at the largest retail bank in Slovakia. Background in closely related technologies includes server operating systems, networking, and storage. A former member of the VMware Center of Excellence at IBM and co-author of several Redpapers. The main scope of work involves designing and optimizing the performance of business-critical virtualized solutions on vSphere, including, but not limited to, Oracle WebLogic, MSSQL, and others. Holding several industry-leading IT certifications such as VCAP-DCD, VCAP-DCA, VCAP-NV, and MCITP. Honored with #vExpert2015-2019 awards by VMware for contributions to the community. Opinions are my own!
Bookmark the permalink.

3 Comments

  1. Pingback: TheVirtualist.org runs for Top vBlog 2015 - The Virtualist

  2. Just missing to remove the local datastore from the entity if required.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.