2

My app which connects to PostgreSQL DB using same credentials (db provider requirement...) However I need to recognize what app user is connecting to DB (eg for udates auditing etc)

I wonder if there is any way I can set some variable (which life is limited to session only), which then I can somehow read via DDLs.

** EDIT **

Ive also did some experiments using application_name in conneciton string and putting there simple user login - but this is not most elegant way...

SET application_name TO 'user_login';
select current_setting('application_name');

Any idea how to archive that ?

Maciej
  • 9,740
  • 16
  • 61
  • 89

1 Answers1

4

Don't abuse application_name, there are custom variables ("customized options") for that:

SET my.app_user = 'user_login';
SELECT current_setting('my.app_user');

See:

Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137