How to reduce SQL planning time? Planning time 8 seconds, execution time 35 ms

On PostgreSQL 15.6 and TimescaleDB 2.14.2 self-host on prem time to time I see spike in queries times. I have analyzed one of the query and I see planning time is the cause of the problem.
In explain I see 8 seconds for planning and 35 mili-seconds for execution.

Details:

I have executed the following SQL:
https://justpaste.it/fmjqv

The following explain is returned:
https://justpaste.it/fcmjb

And table/index definition:
https://justpaste.it/dm2pq

Questions:

  1. How to reduce the SQL planning time?
  2. Is there some TimescaleDB parameter to set e.g. per session like IBM Db2 database has “query optimization class” with values between 0 and 9. Setting per session parameter for specific SQL to lower optimization and planning is drastically reduced.

Hi @ts101 , have you tried to check if you have too many chunks to analyze?

Do you have enough memory to keep all metadata in memory?

Can you share what is the hypertable chunk time interval?