加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 仅记录Postgres中的用户查询

发布时间:2020-12-13 16:01:02 所属栏目:百科 来源:网络整理
导读:我在Postgres数据库中启用了日志记录(在Ubuntu 32位上运行),我只想记录用户应用程序执行的查询.我配置了postgres如下: log_destination = 'syslog'syslog_facility = 'L*emphasized text*OCAL0'syslog_ident = 'postgres'log_min_messages = noticelog_min_
我在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”).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读