Change Ownership Recursively

From: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
To: "PostgreSQL (SQL)" <pgsql-sql(at)postgresql(dot)org>
Subject: Change Ownership Recursively
Date: 2012-03-01 16:23:28
Message-ID: CAAQLLO7gqap3zYUGGd0fuTZjS8OWt86OUtvNQubLEGf40AyNfA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a database that I must assign ownership to a new role. I want
this new role to own the entire database and all of it's tables,
views, triggers, & all. When I run the ALTER DATABASE command below,
it only changes the database role but the tables are all still owned
by the previous role. Is there a way I can assign the 27 tables to
Lauren rather than doing the command one by one for each table?

postgres=# ALTER DATABASE iamunix OWNER TO lauren;
ALTER DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype |
Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
iamunix | lauren | UTF8 | en_US.UTF-8 | en_US.UTF-8 |

All tables still owned by Carlos:

iamunix=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+----------+--------
public | dept | table | carlos
public | dept_id_seq | sequence | carlos
public | employees | table | carlos
public | employees_id_seq | sequence | carlos
public | manager_lookup | view | carlos
public | managers | table | carlos
public | managers_id_seq | sequence | carlos

**PS**
I did do a Google search for "PostgreSQL 9.1 change ownership
recursively" but either couldn't find what I was looking for or
missed it.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Carlos Mennens 2012-03-01 17:04:17 Re: Change Ownership Recursively
Previous Message Oliveiros d'Azevedo Cristina 2012-03-01 11:04:28 Re: Aggregate and join problem