Re: Create Tables As Specific Role

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create Tables As Specific Role
Date: 2011-11-09 17:49:39
Message-ID: 1320860979.2120.14.camel@localhost.localdomain
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2011-11-09 at 12:20 -0500, Carlos Mennens wrote:
> I'm installing a calendar application called MRBS. The installation
> instructions require I create a role and database specifically for
> this web application. I'm currenlt logged in as my user account
> 'carlos' which is a superuser.
>
> postgres=# SELECT current_user;
> current_user
> --------------
> carlos
> (1 row)
>
> I've already created the role 'mrbs' for which will own the database
> and all it's tables:
>
> Role name | Attributes | Member of
> -----------+------------------------------------------------+-----------
> carlos | Superuser, Create role, Create DB, Replication | {}
> mrbs | | {}
> postgres | Superuser, Create role, Create DB, Replication | {}
>
> Now I'm creating the database & I've set the owner to the 'mrbs' role:
>
> Name | Owner | Encoding | Collate | Ctype | Access
> privileges
> -----------+----------+----------+-------------+-------------+-----------------------
> calendar | mrbs | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
>
> Now I need to have PostgreSQL run a file in my /tmp directory which
> will create the tables. The instructions from the MRBS documentation
> say:
>
> "Create the MRBS tables using the supplied tables.*.sql file:
>
> [PostgreSQL] $ psql -a -f tables.pg.sql mrbs"
>
> If I do the suggested above, my user 'carlos' will own all the tables
> in the database 'calendar' which is owned my 'mrbs'. How can I execute
> the command above but force PostgreSQL to create the files as a
> different user and not 'carlos'?
>

Use the -U command line switch:

psql -a -U mrbs -f tables.pg.sql mrbs

--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Kerr 2011-11-09 17:52:01 Re: Foreign Keys and Deadlocks
Previous Message Guillaume Lelarge 2011-11-09 17:48:07 Re: DB Dump