Postgresql trigger on user logon

故事扮演 提交于 2021-02-10 16:12:14

问题


I'm trying to figure out of a way of knowing as soon as a user logs into a Postgres database. Is there a way to define a trigger to fire when a user logs into the DB? Or is there a table or a system view that gets updated whenever anyone logs into the DB?


回答1:


I don't think there's anything at the SQL level which can identify a logon event (i.e. no view you can query, and no trigger you can create).

You can, however, write a server-side module (in C) which intercepts logon events via the ClientAuthentication_hook. This hook is invoked after the server has attempted to authenticate a user, but before it has sent its response.

There is a worked example of a ClientAuthentication_hook on the Postgres wiki. You can also find a couple of examples of this hook in action within Postgres' own contrib modules.




回答2:


login_hook

Postgres database extension to execute som code on user login, comparable to Oracle's after logon trigger.



来源:https://stackoverflow.com/questions/48104368/postgresql-trigger-on-user-logon

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