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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With