Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two owners of the same PostgreSQL database

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?

like image 524
David Reynolds Avatar asked Jan 08 '10 09:01

David Reynolds


People also ask

Can a DB have multiple owners?

Also, each database can only have one owner, so you can't assign multiple owners to the same database.

Who is the owner of a Postgres database?

The owner is normally the role that executed the creation statement. For most kinds of objects, the initial state is that only the owner (or a superuser) can do anything with the object. To allow other roles to use it, privileges must be granted.

Can Postgres handle multiple connections?

PostgreSQL Connection Limits At provision, Databases for PostgreSQL sets the maximum number of connections to your PostgreSQL database to 115. 15 connections are reserved for the superuser to maintain the state and integrity of your database, and 100 connections are available for you and your applications.


1 Answers

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.

like image 188
Magnus Hagander Avatar answered Oct 13 '22 21:10

Magnus Hagander