public inbox for [email protected]  
help / color / mirror / Atom feed
High latency and profiling
2+ messages / 2 participants
[nested] [flat]

* High latency and profiling
@ 2025-10-09 17:25 Roberto Nunnari <[email protected]>
  2025-10-09 19:21 ` Re: High latency and profiling Laurenz Albe <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Roberto Nunnari @ 2025-10-09 17:25 UTC (permalink / raw)
  To: [email protected]

Hello.

Hope this email will keep the formatting this time..

I was notified about high latency on one of our PostgreSQL clusters.
This latency is observed from the application and has been increasing. 
There is no indication about the exact database as the application uses 
several DBs, but the largest and most used is 'mydb'.
So, a couple of months ago I installed pg_profile and configured it as 
follows:

shared_preload_libraries = 
'pg_stat_statements,dblink,pg_stat_kcache,pg_wait_sampling'
pg_profile.max_sample_age = 90

\c postgres
CREATE SCHEMA extensions;
CREATE EXTENSION dblink SCHEMA extensions;
CREATE EXTENSION pg_profile SCHEMA extensions;

\c mydb
CREATE SCHEMA extensions;
CREATE EXTENSION dblink SCHEMA extensions;
CREATE EXTENSION pg_stat_statements SCHEMA extensions;
CREATE EXTENSION pg_stat_kcache schema extensions;
CREATE EXTENSION pg_wait_sampling schema extensions;
CREATE EXTENSION pg_profile SCHEMA extensions;
select extensions.set_server_size_sampling('local','23:00+01',interval 
'2 hour',interval '8 hour');

CREATE USER collector_user with password '';
GRANT pg_read_all_stats TO collector_user;
grant connect on database mydb to collector_user;
ALTER ROLE collector_user SET search_path = extensions,public;

The postgres user had the following crontab:
13,43 * * * * psql -d mydb -c 'SELECT extensions.take_sample()' > 
/dev/null 2>&1

I made sure autovacuum works correctly and after that, just to make 
sure, I run vacuum analyze on all DBs. This has not lead to any notable 
improvement in the latency as seen by the application.

I access pg_profile data from grafana, but I cannot see anything that 
looks wrong.
Overall Hit Ratio is always between 99.3% and 100%.
The only strange thing I see in grafana, are the following:

Overall statement times sais "No data" and 'db query error: pq: column 
"blk_read_time" does not exist'. Also the graph "Statement time" says 
"No data" and "db query error: pq: column sst.blk_read_time does not exist".

Wait event types (statements) graph: N/A was quite stable at about 0.200 
s/s until 2nd september and then grow regularly and sharply up 4 s/s 
until 22nd september when it dropped back to 0.7 s/s and is stable at 
that value till now.

Developers report that their software is already optimized and database 
size is not a problem. They suggest the issue might be inside PostgreSQL 
itself.

Could somebody help me understand what is causing the growing latency?

Also, but more related to pg_profile, what does the N/A data in the 
"Wait event types (statements)" graph represent?

Thank you and best regards.
Robi






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: High latency and profiling
  2025-10-09 17:25 High latency and profiling Roberto Nunnari <[email protected]>
@ 2025-10-09 19:21 ` Laurenz Albe <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Laurenz Albe @ 2025-10-09 19:21 UTC (permalink / raw)
  To: Roberto Nunnari <[email protected]>; [email protected]

On Thu, 2025-10-09 at 19:25 +0200, Roberto Nunnari wrote:
> I was notified about high latency on one of our PostgreSQL clusters.
> This latency is observed from the application and has been increasing. 
> There is no indication about the exact database as the application uses 
> several DBs, but the largest and most used is 'mydb'.
>
> Developers report that their software is already optimized and database 
> size is not a problem. They suggest the issue might be inside PostgreSQL 
> itself.

That may be true, but it need not be true.  The developers' statement
sounds a bit overconfident.

> Could somebody help me understand what is causing the growing latency?

For that, you have to identify the statements that run longer than they
should.  Then examine them with EXPLAIN (ANALYZE, BUFFERS), figure out what
makes them slow and improve them.

Yours,
Laurenz Albe






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-10-09 19:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-10-09 17:25 High latency and profiling Roberto Nunnari <[email protected]>
2025-10-09 19:21 ` Laurenz Albe <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox