F.41. pgpro_cpumeter
pgpro_cpumeter is an extension providing access to a new CPU usage monitoring system function. This pgpro_cpumeter function continuously collects and records information about CPU cores used by Postgres Pro server processes.
F.41.1. Installation
The pgpro_cpumeter extension is a built-in extension included into Postgres Pro Standard. To enable pgpro_cpumeter, use the following query:
CREATE EXTENSION pgpro_cpumeter;
F.41.2. pgpro_cpumeter function
The pgpro_cpumeter provides the following system function:
-
pgpro_cpumeter(OUT start_time timestamptz, OUT end_time timestamptz, OUT user_time int, OUT system_time int, OUT cpus_allowed int, OUT cpus_online int, OUT arch text, OUT machine_id text, OUT system_identifier bigint) returns setof record Returns the collected statistics on CPU usage in the following output columns:
start_timeThe start time of the measurement period. This value is inclusive (
[start_time, end_time)). It matches theend_timeof the previous measurement record.end_timeThe end time of the measurement period, indicating when the collected information is recorded to the disk. This value is exclusive (
[start_time, end_time)). It becomes thestart_timeof the subsequent measurement period.user_timeThe user CPU time, which is the total CPU time in seconds spent by all Postgres Pro processes in user mode.
system_timeThe system CPU time, which is the total CPU time in seconds spent by all Postgres Pro processes in system (kernel) mode.
cpus_allowedThe number of logical CPU cores available to Postgres Pro processes. This value may be limited, for example, by the
tasksettool and is typically less than or equal tocpus_online.cpus_onlineThe number of logical CPU cores currently active and available to the operating system. This value may be less than the total number of physical cores in the system, for example, if some cores are disabled.
archThe processor architecture. This value remains constant for the entire database cluster.
machine_idThe unique identifier of the host stored in the
/etc/machine-idfile. This value may change if thePGDATAdirectory is moved to a different server.system_identifierThe system identifier of the database cluster. This value remains constant for the cluster lifetime, changing only in very limited and exceptional circumstances.
F.41.3. Limitations and Considerations
When using pgpro_cpumeter, consider the following issues:
The collected statistics are recorded every 10 minutes. This interval cannot be changed.
However, statistics are also recorded at the server shutdown. In this case, the last measurement period may be less than 10 minutes.
At the next server start,
start_timewill not matchend_timeof the previous period. Thestart_timevalue for the first record will be equal to the server start time.If the server crashes, the collected statistics for the most recent measurement period (up to 10 minutes) are lost.
F.41.4. Example
The example below illustrates how to use pgpro_cpumeter and its expected output.
postgres=# CREATE EXTENSION pgpro_cpumeter;
CREATE EXTENSION
postgres=# SELECT * FROM pgpro_cpumeter() ORDER BY start_time ASC LIMIT 5;
start_time | end_time | user_time | system_time | cpus_allowed | cpus_online | arch | machine_id | system_identifier
-------------------------------+-------------------------------+-----------+-------------+--------------+-------------+--------+----------------------------------+---------------------
2025-11-18 14:20:18.83645+03 | 2025-11-18 14:30:19.209694+03 | 43 | 23 | 8 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
2025-11-18 14:30:19.209694+03 | 2025-11-18 14:40:19.494243+03 | 5456 | 432 | 8 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
2025-11-18 14:40:19.494243+03 | 2025-11-18 14:50:19.718256+03 | 0 | 0 | 3 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
2025-11-18 14:50:19.718256+03 | 2025-11-18 15:00:19.972368+03 | 5 | 2 | 3 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
2025-11-18 15:00:19.972368+03 | 2025-11-18 15:10:20.222102+03 | 97 | 21 | 3 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
(5 rows)
postgres=# SELECT start_time, end_time, user_time, system_time, cpus_allowed, cpus_online FROM pgpro_cpumeter() ORDER BY start_time ASC LIMIT 5;
start_time | end_time | user_time | system_time | cpus_allowed | cpus_online
-------------------------------+-------------------------------+-----------+-------------+--------------+-------------
2025-11-18 14:20:18.83645+03 | 2025-11-18 14:30:19.209694+03 | 43 | 23 | 8 | 8
2025-11-18 14:30:19.209694+03 | 2025-11-18 14:40:19.494243+03 | 5456 | 432 | 8 | 8
2025-11-18 14:40:19.494243+03 | 2025-11-18 14:50:19.718256+03 | 0 | 0 | 3 | 8
2025-11-18 14:50:19.718256+03 | 2025-11-18 15:00:19.972368+03 | 5 | 2 | 3 | 8
2025-11-18 15:00:19.972368+03 | 2025-11-18 15:10:20.222102+03 | 97 | 21 | 3 | 8
(5 rows)
postgres=# SELECT
min(start_time) AS min_start_time,
max(end_time) AS max_end_time,
sum(user_time) AS total_user_time,
sum(system_time) AS total_system_time,
cpus_allowed,
cpus_online,
arch,
machine_id,
system_identifier
FROM pgpro_cpumeter()
WHERE start_time >= '2025-11-17' AND end_time < '2025-11-22'
GROUP BY cpus_allowed, cpus_online, arch, machine_id, system_identifier
ORDER BY min_start_time ASC;
min_start_time | max_end_time | total_user_time | total_system_time | cpus_allowed | cpus_online | arch | machine_id | system_identifier
-------------------------------+-------------------------------+-----------------+-------------------+--------------+-------------+--------+----------------------------------+---------------------
2025-11-18 14:20:18.83645+03 | 2025-11-21 12:15:30.438471+03 | 755332 | 43234 | 8 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
2025-11-18 18:31:08.321651+03 | 2025-11-21 13:25:53.491532+03 | 54526 | 3231 | 3 | 8 | x86_64 | 38ee3ff28a0044acbb18dd42c3c3b626 | 7574023672154028988
(2 rows)