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

7, 8

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.

  1. Please take the snapshop for the vCenter (offline snapshots for the vCenters in linked mode)  

  2. Take the vCenter database backup. 

  3. Stop the vpxd service:
    service-control --stop vmware-vpxd

  4. To disconnect all hosts connected to vCenter:
    /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres -c "UPDATE vpx_host SET enabled=0"

  5. Validate the changes by running:
    /opt/vmware/vpostgres/current/bin/psql -U postgres -d VCDB -xc "select * from vpx_host;" | grep "enabled "

  6. To disconnect a 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

  7. Script to connect all hosts, including a 30-second wait between connects. 

  8. Open Powershell

  9. To connect the vCenter : Connect-VIServer -Server EXAMPLE_FQDN/IP_OF_VCENTER

  10. Create a file with the below contents  and run the script  from the same location as powercli (desktop)
    Note: EXAMPLE_PASSWORD = your custom ESXi password
    Note: This will only connect ESXi hosts with the same password. Need to answer the certificate question about the thumbprint. Accept this if it appears.


    ./<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