更新时间:2023-01-17 23:35:40
有两种方法可以查看函数中的SQL语句花费多长时间:
There are two ways to see how long SQL statements inside functions take:
启用 auto_explain
,其中 auto_explain.log_nested_statements = on
.这样您就可以在PostgreSQL日志文件中的函数中查看SQL语句的持续时间和执行计划.
Enable auto_explain
with auto_explain.log_nested_statements = on
. That will allow you to see the duration and the execution plans of the SQL statements inside the function in the PostgreSQL log file.
启用 pg_stat_statements
和设置参数 pg_stat_statements.track = all
.
然后 pg_stat_statements
将跟踪函数中SQL语句的信息.这样,您可以查看哪些语句消耗了数据库中的时间.
Then pg_stat_statements
will track information for the SQL statements inside a function. That way you can see which of your statements consume how much time in the database.