3

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!

Yasiru G
  • 6,886
  • 6
  • 23
  • 43

1 Answers1

7

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

Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94