Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup postgres application_name logging

I'm not much familiar with postgresql. I like to setup postgres application_name feature to log database changes (update/delete) in a history table.

I tried to find any help from online but couldn't find any article with basic steps. Could someone give me any kind of help.

Thanks alot!

like image 823
Yasiru G Avatar asked Nov 06 '25 07:11

Yasiru G


1 Answers

Using a application_name is great idea. It has a two steps:

  1. logging application name - set log_line_prefix in postgresql.conf
    log_line_prefix = '%a %u %d' 
  2. use application name - use SQL configuration statement or variable in connection string or environment variable
    SET application_name = 'myapp';
    or
    postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
    or
    PGAPPNAME=splunk psql -c "select application_name from pg_stat_activity where pid = pg_backend_pid();" postgres

some documentation

  • related PostgreSQL doc
  • Overwriting a application name in psql (for psql based script identificati
like image 66
Pavel Stehule Avatar answered Nov 09 '25 09:11

Pavel Stehule