[英]Adding user, IP Address to PostgreSQL logging
I assume I'm missing something easy in the docs, but for the life of me I can't figure out how to add the user id and IP address of the machine running the query in the log files in PostgreSQL. 我假设我在文档中遗漏了一些简单的东西,但对于我的生活,我无法弄清楚如何在PostgreSQL的日志文件中添加运行查询的机器的用户ID和IP地址。 I can see it clearly in pg_stat_activity
once it's happening, but when doing post mortems on database issues, it would be very helpful to see these in the logs. 一旦发生这种情况,我就可以在pg_stat_activity
清楚地看到它,但是当对数据库问题进行验证时,在日志中查看这些内容会非常有帮助。
I doubt it matters, but my server startup is this: 我怀疑这很重要,但我的服务器启动是这样的:
$BIN/pg_ctl -D /apps/pgdata9.5.0 -l /apps/logs/postgresql start
I was hoping there was a setting in postgresql.conf, but if there it it's eluded me. 我希望在postgresql.conf中有一个设置,但是如果它在那里我就躲过了。
https://www.postgresql.org/docs/current/static/runtime-config-logging.html https://www.postgresql.org/docs/current/static/runtime-config-logging.html
add %u %h
to the log_line_prefix
in postgres.conf 将%u %h
添加到postgres.conf中的log_line_prefix
there's a table with other options in docs above 在上面的文档中有一个包含其他选项的表
update: 更新:
query pg_settings.context
to check if you need to restart https://www.postgresql.org/docs/current/static/view-pg-settings.html 查询pg_settings.context
以检查是否需要重新启动https://www.postgresql.org/docs/current/static/view-pg-settings.html
Context required to set the parameter's value (see below) 设置参数值所需的上下文(见下文)
eg: 例如:
t=# select context from pg_settings where name = 'log_line_prefix';
context
---------
sighup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.