Good afternoon,
I have a trigger in my database that records every change, inclusion or deletion in the tables, but instead of using the user ID connected to Postgres, I would like to pass the user ID of my application, as it is an application SASS, I will have "a user" for the database, and "n" for the application.
Is there any way to pass this user to my connection? where can I retrieve it in the trigger by executing select * from pg_stat_activity?
I know the solution may seem inelegant, but it provides a lot of reliability when auditing data in the database
I'm using:
- Django 4.2
- DRF 3.14.0
- Postgres 16.1
I tried to change the DATABASE parameters of settings.py, before the connection and I even managed to change the application_name, but when two users execute their requests "at the same time", there is a conflict and the two connections have the same value in the application_name.