PostgreSQL日志用户或角色更改活动

发布于 2025-02-10 02:05:35 字数 533 浏览 0 评论 0 原文

我需要在用户和角色中记录所有更改(示例:将超级用户授予用户),日志添加新的用户/角色,日志删除用户/角色。这是为了监视我们的数据的安全性,并确保用户/角色更改登录到表甚至日志文件中。

我尝试通过在 pg_roles pg_user 上创建触发器,

CREATE TRIGGER pg_roles_trigger BEFORE INSERT OR UPDATE OR DELETE ON pg_roles
FOR EACH ROW EXECUTE PROCEDURE user_access_log_trigger();

但我得到了错误错误:“ pg_roles”是一个视图。详细信息:视图在触发器之前或之后不能具有行级别,

因此尝试在基本表上创建触发器 pg_authid 。但这也给出了错误: 错误:拒绝权限:“ PG_AUTHID”是系统目录SQL状态:42501

PostgreSQL中是否有任何选项?

I need to log all changes(example: granting superuser to user) in user and role, log adding new user/roles, log dropping the user/role. This is regarding to monitor the security of our data and ensure user/roles changes are logged into table or even in log file.

I tried by creating a trigger on pg_roles and pg_user

CREATE TRIGGER pg_roles_trigger BEFORE INSERT OR UPDATE OR DELETE ON pg_roles
FOR EACH ROW EXECUTE PROCEDURE user_access_log_trigger();

But I got error Error:"pg_roles" is a view. DETAIL: Views cannot have row-level BEFORE or AFTER triggers

So tried to create a trigger on base table pg_authid. but it also gave error:
ERROR: permission denied: "pg_authid" is a system catalog SQL state: 42501

Is there any option in Postgresql ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喵星人汪星人 2025-02-17 02:05:35

Postgres官方文档在这里很有帮助。您可以通过将文件中的 log_statement 键配置为 ALL 来配置 postgresql.conf 来记录所有查询和ddl。

如果需要加载到表中并备份需要审核的日志。

The official postgres docs are helpful here. You can configure postgresql.conf to log all queries and ddl by configuring log_statement key in the file to all.

https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT

If it needs to be loaded into a table you can parse the logs and write that information back into a table or just rotate and back up the logs for when they need to be audited.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文