Two owners of the same PostgreSQL database

允我心安 提交于 2019-12-05 16:31:25

问题


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?


回答1:


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.




回答2:


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."



来源:https://stackoverflow.com/questions/2026655/two-owners-of-the-same-postgresql-database

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