Re: AW: postgresql long running query

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: liam saffioti <liam(dot)saffiotti(at)gmail(dot)com>
Cc: Mladen Gogala <gogala(dot)mladen(at)gmail(dot)com>, pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: AW: postgresql long running query
Date: 2021-12-10 05:25:56
Message-ID: CAMkU=1zSeiJCSexLKoy-jm_Y+oUkqRzRK1GN9Aadntoy4sGcKg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Wed, Dec 8, 2021 at 10:19 AM liam saffioti <liam(dot)saffiotti(at)gmail(dot)com>
wrote:

> Hi everyone,
>
> Thank you for your help. But my query is not always slow. It works fast
> under normal conditions, but in a way that I don't understand it works very
> slow at some times.
> I think there may be a different reason why a query that takes 800ms, in
> general, takes 18 minutes at a time.
>

As previously asked, do you have log_lock_waits turned on? If so, do you
see entries in the db server's log file?

Also, we really could use the plan capture of the slow execution, not of
the same query except when it is not slow. The only way of to get that
reliably while also getting the original output of the query (which I
assume you need) is with auto_explain, with settings like:

auto_explain.log_min_duration = '600s'
auto_explain.log_analyze=on
auto_explain.log_buffers=on
auto_explain.log_nested_statements=on

Then go trolling through the log file. Note that this does cause every
query run on your system to take detailed timings of each step, which can
slow down the entire system, especially if you are on a system with slow
user access to the clock (common with old hardware or old kernels). But I
think the extra info you get is well worth the extra load. You could
leave auto_explain.log_analyze=off
globally, then turn it on only in the specific script file you are seeing
the problem with.

Cheers,

Jeff

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message abbas alizadeh 2021-12-10 06:29:31 Last login time
Previous Message androxkentaki 2021-12-08 20:17:24 Re: AW: postgresql long running query