vCenter删除无效的数据存储

问题现象
vCenter中存在无效的数据存储,无法通过“卸载数据存储”或“删除数据存储”进行移除,需要从数据库进行删除

操作步骤
1. SSH登录VCSA

2. 执行/opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres进入数据库工具

3. 执行\d,列出所有表,确认正常

4. 查找无效的数据存储ID
SELECT id FROM vpx_entity WHERE name = 'InvalidDatastoreName';

VCDB=# SELECT id FROM vpx_entity WHERE name = 'Server LUN 01';
 id
----
 74
(1 row)

5. 查找数据存储都被哪些资源占用,导致没有能自动删除
SELECT * FROM vpx_ds_assignment WHERE ds_id=<ID>;

VCDB=# SELECT * FROM vpx_ds_assignment WHERE ds_id=74;
 ds_id | entity_id | accessible | mount_path | mount_id | mount_mode | mounted
-------+-----------+------------+------------+----------+------------+---------
    74 |        24 |            |            |          |            |
(1 row)

继续查找,根据entity_id查找占用对象的名称
SELECT * FROM vpx_entity WHERE id=<ID>;

VCDB=# SELECT * FROM vpx_entity WHERE id=24;
 id |     name     | type_id | parent_id
----+--------------+---------+-----------
 24 | Win2012R2TMP |       0 |        80
(1 row)

6. 至此,可以删除占用的对象来让vCenter自动删除数据存储

7. 如果上一步无法删除,可以继续,在数据库里直接删除数据存储,使用以下命令

DELETE FROM vpx_ds_assignment WHERE ds_id=<ID>;
DELETE FROM vpx_datastore WHERE id=<ID>;
DELETE FROM vpx_vm_ds_space WHERE ds_id=<ID>;

删除完成后重启VCSA,数据存储成功被删除

来源:https://vmninja.wordpress.com/2019/04/05/remove-inaccessible-datastore-from-inventory