简体   繁体   中英

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. 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.

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.

https://www.postgresql.org/docs/current/static/runtime-config-logging.html

add %u %h to the log_line_prefix in postgres.conf

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

Context required to set the parameter's value (see below)

eg:

t=# select context from pg_settings where name = 'log_line_prefix';
 context
---------
 sighup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM