Postgres auto_explain 模块不提供节点-postgres 查询计划

问题描述 投票:0回答:1

我正在尝试使用 PostgreSQL 10 提供的

auto_explain
模块来优化来自 fastify(node) 后端的查询。但是,尽管在日志中看到了通过我的服务传入的查询,但没有生成查询信息.

我通过在容器中运行以下 psql 命令来启用该模块:

LOAD 'auto_explain';
SET auto_explain.log_min_duration=0;
SET auto_explain.log_analyze=true;
SET auto_explain.log_verbose = true;
SET auto_explain.log_nested_statements = true;

我还在

log_statement = 'all'
中设置了
postgresql.conf

这似乎有效,因为如果我通过 psql 运行一个简单的选择,我会看到类似的内容:

postgresql-1  | 2024-04-26 22:21:54.630 UTC [384] LOG:  statement: select * from user;
postgresql-1  | 2024-04-26 22:21:54.631 UTC [384] LOG:  duration: 0.200 ms  plan:
postgresql-1  |         Query Text: select * from user;
postgresql-1  |         Seq Scan on user  (cost=0.00..1.03 rows=3 width=1367) (actual time=0.016..0.022 rows=3 loops=1)
postgresql-1  |           Output: (a bunch of columns...)

但是,当我从后端服务触发查询时(使用

node-postgres
@types/pg
),我没有得到任何计划信息。我看到一个
LOG:  execute <unnamed>:
条目显示了我的参数化查询,还有一个
DETAILS
条目显示了查询的参数及其值。

如果有任何有关为我的查询正确启用此模块的信息,我们将不胜感激。

postgresql fastify
1个回答
0
投票

您所显示的只是针对一个会话进行设置。

要为每个人激活它,您应该在 postgresql.conf 文件中配置它,就像您对 log_statement 所做的那样。为此,您可以将扩展名称放入shared_preload_libraries中(而不是使用LOAD命令),同时以postgresql.conf的通常方式设置其他设置。

© www.soinside.com 2019 - 2024. All rights reserved.