Retrieve username inside a trigger function

一个人想着一个人 提交于 2019-12-23 16:34:06

问题


In our database we have a login table featuring coloumns username and password. How can this username be retrieved inside a trigger function so that it can also be audited. user keyword inside the trigger function retrieves the postgresql username, what I need is the application username. Any suggestions?


回答1:


You can set a custom GUC up in postgresql.conf. Use it to store the application username at login using SET myapp_username. Access that in triggers with current_setting(myapp_username)

Alternately, create a TEMPORARY table at user login and INSERT the user's application username into it at login. SELECT it in triggers where required.

Both of these require that the user cannot run custom SQL directly, of course, but that's generally a requirement of application-level authentication like you're using anyway.

More detail in Passing user id to PostgreSQL triggers



来源:https://stackoverflow.com/questions/13066376/retrieve-username-inside-a-trigger-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!