1

I'm developing a system using NHibernate and PostgreSQL, with Npgsql data provider. I need to get the logged in user in my system in a trigger in order to run an audit function. Is there any way to set the user in the NHibernate session or to get it directly from the database? Please help!

Daniel O
  • 13
  • 3

1 Answers1

1

Here's a detailed explanation of how to get application-level user identity into triggers that I wrote a while ago. Essentially you can use a temporary table to store the user login or a custom GUC. Either way, your application must explicitly set that up when it creates a session so that it can be accessed later.

Personally I think you should usually be using PostgreSQL users and SET ROLE as explained here, but I realise that's not always an option.

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778