I am trying to find the cause for a query that is slow, but only sometimes.
I have slow query logging active, and I see the query being logged, for example:
timescaledb-2 timescaledb 2023-08-04 13:43:12 UTC : [64ccfe56.7f72-3] device_monitoring@postgres,app=PostgreSQL JDBC Driver LOG: duration: 27178.742 ms bind S_9:
Sometimes the query times out, my client timeout is set to 30s, so I get:
timescaledb-2 timescaledb 2023-08-04 13:33:23 UTC : [64ccf76c.745c-3] device_monitoring@postgres,app=PostgreSQL JDBC Driver ERROR: canceling statement due to statement timeout
Running [explain on the query](https://explain.dalibo.com/plan/5e36b5b82fd1d661#plan) , I don't see any immediate problems () and the query runs fast most of the times.
I have pg_stat_statement
active, but these slow executions are never stored:
postgres=# select max(max_exec_time) from pg_stat_statements ;
-[ RECORD 1 ]----
max | 2286.040693
That is only about 2 seconds. Do I need to activate any setting for slow queries to be included in pg_stat_statement
?
I have log_lock_waits
set to on
, but no slow locks are logged.
What else can be the cause of these slow queries?
Asked by simao
(127 rep)
Aug 4, 2023, 01:54 PM
Last activity: Mar 7, 2025, 06:03 PM
Last activity: Mar 7, 2025, 06:03 PM