gpt4 book ai didi

postgresql - 在 Postgres 中仅记录用户查询

转载 作者:行者123 更新时间:2023-11-29 11:28:45 24 4
gpt4 key购买 nike

我已经在我的 Postgres 数据库中启用了日志记录(在 Ubuntu 32 位上运行),我只想记录用户应用程序重新执行的查询。我已经按如下方式配置了 postgres:

log_destination = 'syslog'
syslog_facility = 'L*emphasized text*OCAL0'
syslog_ident = 'postgres'
log_min_messages = notice
log_min_duration_statement = 0
log_duration = off
log_line_prefix = 'user=%u,db=%d '
log_statement = 'none'

syslog.conf 中,我配置了将发送到 local0 的每个日志重定向到 /var/log/pgsql

但是,Postgres 记录了很多我不关心的查询,例如:

WHEN typbasetype=0 THEN oid else typbasetype END AS
Sep 16 12:22:28 or-ubuntu postgres[14086]: [11-2] basetype
Sep 16 12:22:28 or-ubuntu postgres[14086]: [11-3] ^I FROM pg_type WHERE oid=1043
Sep 16 12:22:28 or-ubuntu postgres[14086]: [12-1] user=postgres,db=prueba LOG: duración: 0.361 ms sentencia: SELECT format_type(oid,-1) as typname FROM pg_type WHERE oid = 2950
Sep 16 12:22:28 or-ubuntu postgres[14086]: [13-1] user=postgres,db=prueba LOG: duración: 0.348 ms sentencia: SELECT CASE WHEN typbasetype=0 THEN oid else typbasetype END AS
Sep 16 12:22:28 or-ubuntu postgres[14086]: [13-2] basetype
Sep 16 12:22:28 or-ubuntu postgres[14086]: [13-3] ^I FROM pg_type WHERE oid=2950
Sep 16 12:22:28 or-ubuntu postgres[14086]: [14-1] user=postgres,db=prueba LOG: duración: 0.451 ms sentencia: SELECT format_type(oid,104) as typname FROM pg_type WHERE oid =
Sep 16 12:22:28 or-ubuntu postgres[14086]: [14-2] 1043
Sep 16 12:22:28 or-ubuntu postgres[14086]: [15-1] user=postgres,db=prueba LOG: duración: 0.353 ms sentencia: SELECT CASE WHEN typbasetype=0 THEN oid else typbasetype END AS
Sep 16 12:22:28 or-ubuntu postgres[14086]: [15-2] basetype
Sep 16 12:22:28 or-ubuntu postgres[14086]: [15-3] ^I FROM pg_type WHERE oid=1043

有什么方法可以防止记录这些行吗?

提前致谢

迭戈

最佳答案

如果您的应用程序使用它们自己的角色(它们应该如此),您只能使用 "ALTER ROLE" 更改这些角色的适当设置。 :

ALTER ROLE <account> SET log_statement = 'all';

(或您的配置中的“log_min_duration_statement = 0”)。

关于postgresql - 在 Postgres 中仅记录用户查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1433704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com