我想我在文档中遗漏了一些简单的东西,但对于我来说,我无法弄清楚如何在 PostgreSQL 的日志文件中添加运行查询的机器的用户 ID 和 IP 地址。一旦它发生,我可以在 pg_stat_activity
中清楚地看到它,但是在对数据库问题进行事后分析时,在日志中看到它们会非常有帮助。
我怀疑这是否重要,但我的服务器启动是这样的:
$BIN/pg_ctl -D /apps/pgdata9.5.0 -l /apps/logs/postgresql start
我希望在 postgresql.conf 中有一个设置,但如果有的话,我却找不到。
最佳答案
https://www.postgresql.org/docs/current/static/runtime-config-logging.html
将 %u %h
添加到 postgres.conf 的 log_line_prefix
上面的文档中有一个包含其他选项的表格
更新:
查询pg_settings.context
检查是否需要重启
https://www.postgresql.org/docs/current/static/view-pg-settings.html
Context required to set the parameter's value (see below)
例如:
t=# select context from pg_settings where name = 'log_line_prefix';
context
---------
sighup
关于postgresql - 将用户、IP 地址添加到 PostgreSQL 日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46321465/