How do I write a Go program to automatically connect to vCenter's PostgreSQL and export VM data?
Use Go with the `github.com/lib/pq` package, but note a bug in vCenter's environment: the third-party package may fail due to the `$PGSERVICEFILE` environment variable. Fix it by commenting out lines 1988-1989 in `conn.go`. Then, read the vc password from `/etc/vmware-vpx/vcdb.properties`, connect to VCDB, and query `vc.vpx_vm` and `vc.vpxv_hosts` tables. Cross-compile for Linux using `GOOS=linux GOARCH=amd64 go build`. The full code example is in vSphere Development Guide 4 - PostgreSQL.
Go programmingPostgreSQLpq packagevCentervcdb.propertiescross-compilation