To calculate the number of CPU cores in use by Greenplum Database (GPDB), we need to query the gp_segment_configuration table to identify the relevant hosts and then inspect each host’s CPU configuration. The total number of CPU cores is determined by aggregating the core count from all hosts.
1.Query the gp_segment_configuration table to list all hosts:
psql -c "SELECT DISTINCT hostname FROM gp_segment_configuration" postgres -t -A > host
2.Use gpssh to check the number of CPU cores on each host. This command retrieves the unique core count by querying each host’s CPU configuration:
gpssh -f host "ls /sys/devices/system/cpu/cpu*/topology/core_cpus | xargs cat | sort | uniq | wc -l" > perhost
If the above hit errors, it should because of the Linux Kernel version is old, the path should be /sys/devices/system/cpu/cpu%s/topology/thread_siblings
, let's use the following command:
gpssh -f host "ls /sys/devices/system/cpu/cpu*/topology/thread_siblings | xargs cat | sort | uniq | wc -l" > perhost
3.Sum the results across all hosts to get the total number of CPU cores:
awk '{sum+=$NF;} END{print sum;}' perhost
This method accurately calculates the total CPU cores used by the GPDB across all system segments.