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 can disconnect all hosts from the database and then add them back one by one until you locate the culprit for closer inspection.

  • Please make sure vCenter is stopped, if required set the service startup type to "Manual" and Take a backup of the vCenter database first.
  • If you wish to narrow this down you can use the command below instead to disconnect only a single host:
    • /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>;"

  • Script to connect all hosts including 30 second wait between connects. Copy it to file and run from the same location as powercli (desktop)
    • Open powershell
    • Run: Connect-VIServer -Server EXAMPLE_FQDN/IP_OF_VCENTER
    • To run the script, use the following syntax with the file name you chose:
./<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.