Disconnect hosts from vCenter via database when vCenter fails to start
search cancel

Disconnect hosts from vCenter via database when vCenter fails to start

book

Article ID: 321930

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

vCenter continually crashes while trying to start. 

Environment

VMware vCenter Server 6.x

VMware vCenter Server 7.x

VMware vCenter Server 8.x

Cause

vCenter is stopping due to issues at the host level.

Resolution

To narrow down which host is causing the issue you need to disconnect all hosts from the vCenter database and then add them back one by one until you locate the faulty one for closer inspection.

  • Please take the snapshop for the vCenter (offline snapshots for the vCenters in linked mode)  
    • Take the vCenter database backup. 
    • Stop the vpxd service : service-control --stop vmware-vpxd
    • To disconnect all hosts connected to vCenter:
      • /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres -c "UPDATE vpx_host SET enabled=0"
    • Validate the changes by running the below command.  
      • /opt/vmware/vpostgres/current/bin/psql -U postgres -d VCDB -xc "select * from vpx_host;" | grep "enabled "

  • To disconnect single host from the vCenter:
    • /opt/vmware/vpostgres/current/bin/psql -U postgres -d VCDB -xc "select * from vpx_host;"  |egrep "id |dns_name |enabled "
    • /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres -c "UPDATE vpx_host SET enabled = 0 where id = <host-id>;"
    • Start the vpxd service : service-control --start vmware-vpxd
  • Script to connect all hosts including 30 second wait between connects. 
    • Open Powershell
    • To connect the vCenter : Connect-VIServer -Server EXAMPLE_FQDN/IP_OF_VCENTER
    • Create a file with the below contents  and run the script  from the same location as powercli (desktop)
./<filename>.ps1
 
-----------------------------------
$password = "EXAMPLE_PASSWORD"

get-vmhost | % {
$view = get-view $_.id
$arg = new-object VMware.Vim.HostConnectSpec
$arg.userName = "root"
$arg.password = $password
$arg.force = $true

$view.ReconnectHost_Task($arg,$null)
}

Disconnect-VIServer -Confirm:$false
--------------------------------------
 
Note that : EXAMPLE_PASSWORD = your custom ESXi password
 
Notes:
  • This will only connect ESXi hosts with the same password.
  • You probably will need to answer the certificate question regarding the thumbprint. Accept this if it appears.