CPU time for pg_stat_statement

From: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: CPU time for pg_stat_statement
Date: 2022-05-20 18:50:32
Message-ID: CANtu0ohSj7nOtJ_DVErt3b5Yj34eufQ=2Wv=aTqrExJ0FvP+Ag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2022-05-20 19:50:52 Re: Limiting memory allocation
Previous Message Zhihong Yu 2022-05-20 18:41:57 check for null value before looking up the hash function