Postgresql – Tool to find CPU utilization for a particular query in Postgres

postgresql

I just want to know is there any free tool to identify CPU utilization for a particular query in PostgreSQL.

Best Answer

You can use the CPU monitor of your operating system (e.g. top in Linux or ProcessExplorer in Windows).

Each connection to the database will create a new process on the server. The process id related to the connection is reported in the column pid of the system view pg_stat_activity.

With that process ID you can monitor the CPU usage of that process which is essentially the CPU usage of your query (while it's running of course)

More details in the manual: http://www.postgresql.org/docs/current/static/monitoring.html and the Postgres Wiki: https://wiki.postgresql.org/wiki/Performance_Analysis_Tools