Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REASSIGN OWNED BY for 1 specified database

Tags:

postgresql

I want to change owner of all tables in one particular database using

REASSIGN OWNED BY postgres TO myuser

but it shows:

ERROR:  cannot reassign ownership of objects owned by role postgres because they are required by the database system

I think it's because there are more databases in this system, but I want to reassign owners only in one specified databse (database1).

Is there a way?

like image 508
pawel Avatar asked Jun 06 '13 10:06

pawel


People also ask

How do you change the owner of a database?

To alter the owner, you must own the database and also be a direct or indirect member of the new owning role, and you must have the CREATEDB privilege. (Note that superusers have all these privileges automatically.) The fourth form changes the default tablespace of the database.

How do I change the owner of a table in PostgreSQL?

You must own the table to use ALTER TABLE. To change the schema of a table, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the table's schema.


1 Answers

Because the postgres user owns system catalogs, you cannot reassign all objects owned by postgres. You will have to sort out this situation by hand in this case. In the future, avoid using postgres for non-administrative tasks.

like image 84
Peter Eisentraut Avatar answered Sep 17 '22 06:09

Peter Eisentraut