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.
Dusan has over 8 years experience in the Virtualization field. Currently working as Senior VMware plarform Architect at one of the biggest retail bank in Slovakia. He has background in closely related technologies including server operating systems, networking and storage. Used to be a member of VMware Center of Excellence at IBM, co-author of several Redpapers. His main scope of work consists from designing and performance optimization of business critical virtualized solutions on vSphere, including, but not limited to Oracle WebLogic, MSSQL and others. He holds several IT industry leading certifications like VCAP-DCD, VCAP-DCA, MCITP and the others. Honored with #vExpert2015-2018 awards by VMware for his contribution to the community. Opinions are my own!

About Dusan Tekeljak

Dusan has over 8 years experience in the Virtualization field. Currently working as Senior VMware plarform Architect at one of the biggest retail bank in Slovakia. He has background in closely related technologies including server operating systems, networking and storage. Used to be a member of VMware Center of Excellence at IBM, co-author of several Redpapers. His main scope of work consists from designing and performance optimization of business critical virtualized solutions on vSphere, including, but not limited to Oracle WebLogic, MSSQL and others. He holds several IT industry leading certifications like VCAP-DCD, VCAP-DCA, MCITP and the others. Honored with #vExpert2015-2018 awards by VMware for his contribution 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.