[英]pg_stat_activity - how to see current activity inside a running stored procedure
I have a postgres environment where stored procedures are used extensively and these procedures are complex and call other stored procedures.我有一个 postgres 环境,其中广泛使用了存储过程,这些过程很复杂,并且会调用其他存储过程。
When I query the pg_stat_activity table, I get a record that shows the procedure being called, but no indication is given on what sql statements are being called within the procedure.当我查询 pg_stat_activity 表时,我得到一个显示正在调用的过程的记录,但没有给出在该过程中调用了哪些 sql 语句的指示。
eg.例如。 select myprocname($1,$2,$3,$4)
选择 myprocname($1,$2,$3,$4)
As a result, I am unable to isolate specific SQL statements which may be causing a performance issue.因此,我无法隔离可能导致性能问题的特定 SQL 语句。 The RDS in question is an amazon RDS instance, so OS level access to the process is not available (as far as I have been able to determine).
有问题的 RDS 是一个亚马逊 RDS 实例,因此无法访问该进程的操作系统级别(据我所知)。
I have searched for information on google on this subject without much luck to this point.到目前为止,我已经在谷歌上搜索了有关此主题的信息,但运气不佳。
This question is not about the specific scenario as the code is proprietary and I can't discuss it directly, but on how to perform such tuning when the main source I am used to using is not providing enough detail.这个问题不是关于特定场景,因为代码是专有的,我不能直接讨论它,而是关于当我习惯使用的主要来源没有提供足够的细节时如何执行这样的调整。
There are two ways to see how long SQL statements inside functions take:有两种方法可以查看函数内部的 SQL 语句花费的时间:
Enableauto_explain
with auto_explain.log_nested_statements = on
.使用
auto_explain.log_nested_statements = on
启用auto_explain
。 That will allow you to see the duration and the execution plans of the SQL statements inside the function in the PostgreSQL log file.这将允许您在 PostgreSQL 日志文件中查看函数内 SQL 语句的持续时间和执行计划。
Enable pg_stat_statements
and set the parameter pg_stat_statements.track = all
.启用
pg_stat_statements
并设置参数pg_stat_statements.track = all
。
Then pg_stat_statements
will track information for the SQL statements inside a function.然后
pg_stat_statements
将跟踪函数内 SQL 语句的信息。 That way you can see which of your statements consume how much time in the database.这样你就可以看到你的哪些语句在数据库中消耗了多少时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.