同一 PostgreSQL 数据库的两个所有者

发布于 2024-08-17 08:10:03 字数 188 浏览 5 评论 0原文

是否可以使用 Postgresql 创建一个拥有 2 个用户(充当数据库所有者)的数据库?

我可以创建一个组角色并将两个用户添加到该组,然后使该组成为数据库的所有者,但这要求两个用户都必须在每个连接上手动设置其角色,以使他们创建的任何表都可以访问另一个用户。有什么方法可以使该组成为用户每次登录时的默认角色,或者有任何其他方法可以实现相同的效果?

Is it possible with Postgresql to create a database which has 2 users which act like owners to the database?

I can create a group role and add both users to that group, and then make the group the owner of the database, but this requires both users to be have to manually set their role on every connection to make any tables they have created accessible to the other user. Is there any way to make the group be the default role for a user each time they log in or any other way to achieve the same thing?

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

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

发布评论

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

评论(2

踏雪无痕 2024-08-24 08:10:03

不可以,每个数据库只能有一个所有者。如前所述,您可以拥有多个超级用户,或者您可以专门向随后继承的组角色授予权限。

您可能想查看 http://blog.hagander.net /archives/70-Faking-the-dbo-role.html,一种伪造类似于您所要求的内容的方法。它并不完美,但对您来说可能已经足够了。它至少应该能够解决对象所有权问题。

No, each database can only have one owner. As stated previously you can have more than one superuser, or you can grant permissions specifically to group roles that are then inherited.

You might want to look at http://blog.hagander.net/archives/70-Faking-the-dbo-role.html, for a way to fake something similar to what you're asking for. It's not perfect, but it might be good enough for you. It should be able to solve the object-ownership problem at least.

じ违心 2024-08-24 08:10:03

啊,找到了:PostgreSQL 文档:第 20 章数据库角色和权限

“具有 INHERIT 属性的成员角色自动拥有其所属角色的权限。”

CREATE ROLE joe LOGIN INHERIT;
CREATE ROLE admin NOINHERIT;
GRANT admin TO joe;

“以 joe 角色连接后,数据库会话将立即使用直接授予 joe 的权限以及授予 admin 的任何权限,因为 joe“继承”admin 的权限。”

Ah, found it: PostgreSQL Docs: Chapter 20. Database Roles and Privileges

"member roles that have the INHERIT attribute automatically have use of privileges of roles they are members of."

CREATE ROLE joe LOGIN INHERIT;
CREATE ROLE admin NOINHERIT;
GRANT admin TO joe;

"Immediately after connecting as role joe, a database session will have use of privileges granted directly to joe plus any privileges granted to admin, because joe "inherits" admin's privileges."

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