Three years ago I published a post that describe how to connect to the vCenter Server database (PostgreSQL) investigating or changing any required values, especially objects that are getting in trouble and you couldn't modify them directly via vSphere management tools (Web Client, PowerCLI
and so on). For example, an orphaned virtual machine (like a Horizon Replica VM) that is not possible to remove.
In my recent case, I have an ESXi host that is a member of a HA Cluster and since it has been added via IP address, if we want to alter its name, we should remove and add it again to the vCenter. As you probably know, I should put it into the maintenance mode, and unfortunately, there are not enough available resources in the other ESXi hosts of this cluster for VM migration. So I decided to modify the ESXi name that is connected to the vCenter server via changing the value of the database.
First, I strongly suggest reading my post, then taking a new backup before doing any action through the vCenter server shell. In the second step, after connecting to the vPostgres database via the PgAdmin tool, go to this path: "Databases\VCDB\Schemas\vc\Tables" and run the following queries in the mentioned tables:
1. To list and check all existing ESXi in the considered data center
SELECT id, dns_name, ip_address, vpxa_id
FROM vc.vpx_host
You can reduce the query result via adding a condition like filtering per Data Center, if you note it. For example:
SELECT id, dns_name, ip_address, vpxa_id
FROM vc.vpx_host WHERE datacenter_id= '1001';
2. Note the consider id. So to modify and set the FQDN instead of IP address, run the following query:
UPDATE vc.vpxv_host
SET dns_name = 'ESXi_FQDN' WHERE id = '7044';
The query should return successfully. However, you can modify the dns_name field manually for the corresponding ESXi host in the result table of the SELECT query. In both methods, you should execute F6 "Save Data Changes" to commit all changes.
3. Also, you can check the corresponding modification via querying other related Tables, like:
SELECT id, name
FROM vc.vpx_entity WHERE type_id= '1';
You should consider running the last query again for type_id='2'.
4. Finally, to confirm the accuracy of changes. it's better to repeat these actions for the corresponding Views in this path: "Databases\VCDB\Schemas\vc\Views"
SELECT hostid, name
FROM vc.vpxv_hosts WHERE datacenter_id='1001';
Do it also for datacenter_id='1002' too.
SELECT id, name
FROM vc.vpxv_entity WHERE entity_type='COMPUTE_RESOURCE'
5. Then run the following command to restart all VCSA services:
services-control --stop --all | services-control --start --all
So after login into the vSphere web client again, you can see your modification has been successfully done. Just a duration needed to pass, so don't be hurry to see the considered results quickly in operations like this. However, I should mention once again, described procedure is a very risky action, so do it carefully or avoid doing, if you don't have any knowledge about the databases and how to run the query against them.