Using a application_name is great idea. It has a two steps:
- logging application name - set log_line_prefix in postgresql.conf
log_line_prefix = '%a %u %d'
- use application name - use SQL configuration statement or variable in connection string or environment variable
SET application_name = 'myapp';
orpostgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
orPGAPPNAME=splunk psql -c "select application_name from pg_stat_activity where pid = pg_backend_pid();" postgres
some documentation