CPU time for pg_stat_statement - Mailing list pgsql-hackers

From Michail Nikolaev
Subject CPU time for pg_stat_statement
Date
Msg-id CANtu0ohSj7nOtJ_DVErt3b5Yj34eufQ=2Wv=aTqrExJ0FvP+Ag@mail.gmail.com
Whole thread Raw
Responses Re: CPU time for pg_stat_statement
Re: CPU time for pg_stat_statement
List pgsql-hackers
Hello, hackers.

Today I was doing some aggregates over pg_stat_statements in order to
find types of queries consuming most of the CPU. Aggregates were made
on two pg_state_statement snapshots within 30 sec delay.

The sum(total_time) had the biggest value for a very frequent query
with about 10ms execution. I was thinking it is the biggest CPU
consumer.

But after reducing the frequency of queries a lot I was unable to see
any significant difference in server CPU usage...

So, looks like clock_gettime is not so accurate to measure real CPU
usage for some OLTP workloads. I suppose it is caused by the wall time
vs CPU time difference (IO, thread switch, etc).

But what do you think about adding cpu_time (by calling getrusage) to
pg_stat_statements? Seems it could be very useful for CPU profiling.

I am probably able to prepare the patch, but it is always better to
get some feedback on the idea first :)

Best regards,
Michail.



pgsql-hackers by date:

Previous
From: Zhihong Yu
Date:
Subject: check for null value before looking up the hash function
Next
From: Stephen Frost
Date:
Subject: Re: Limiting memory allocation