Re: Current query of the PL/pgsql procedure.

From: Matheus de Oliveira <matioli(dot)matheus(at)gmail(dot)com>
To: Yuri Levinsky <yuril(at)celltick(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Current query of the PL/pgsql procedure.
Date: 2013-12-16 12:47:52
Message-ID: CAJghg4KUFm07QYWieDE8B4YmqXHiM3DTp7kis-ELcP4R0Z4Gng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sun, Dec 15, 2013 at 2:18 PM, Yuri Levinsky <yuril(at)celltick(dot)com> wrote:

> Dear ALL,
>
> I am running PL/pgsql procedure with sql statements that taking a long
> time. I able to see them in the log just after their completion. How can I
> see currently running SQL statement? I am able to see in pg_stat_activity
> only my call to function. Many thanks in advance.
>
>
>

As noticed, pg_stat_activity will only be able to see the call to that
function, not the queries been executed inside the function itself. The
same will happen with the logs (configuring GUCs like log_statements or
log_min_duration_statement). A solution I have used to solve this issue is
either the contrib auto_explain [1] or pg_stat_statements [2]. Both will be
able to get the queries executed inside the functions. For that, you will
have to configure then (by default they will not track the queries inside):

* for auto_explain: `auto_explain.log_nested_statements = on`
* for pg_stat_statements: `pg_stat_statements.track = all`

The problem you stated about the logs, that it only logs after the
execution not during or before, will still remain. Both will "get the
query" right after the execution. In your use case auto_explain seems
better to use to track, as it can grows with no limit (you will have to
control your log file size and auto_explain.log_min_duration to avoid a log
flood, though).

[1] http://www.postgresql.org/docs/current/static/auto-explain.html
[2] http://www.postgresql.org/docs/current/static/pgstatstatements.html

Best regards,
--
Matheus de Oliveira
Analista de Banco de Dados
Dextra Sistemas - MPS.Br nível F!
www.dextra.com.br/postgres

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Andrew Dunstan 2013-12-16 13:29:27 Re: Current query of the PL/pgsql procedure.
Previous Message Yuri Levinsky 2013-12-16 11:42:30 Re: Current query of the PL/pgsql procedure.