On Sun, Dec 15, 2013 at 2:18 PM, Yuri Levinsky <yuril@xxxxxxxxxxxx> wrote:
[1] http://www.postgresql.org/docs/current/static/auto-explain.html
[2] http://www.postgresql.org/docs/current/static/pgstatstatements.html
-- 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