Create Tables As Specific Role

From: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Create Tables As Specific Role
Date: 2011-11-09 17:20:13
Message-ID: CAAQLLO5RwT1BfJNiFPwD-G_qOMJLWvmcHtsKd2=+NBLoOJGgHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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'?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2011-11-09 17:48:07 Re: DB Dump
Previous Message Bob Pawley 2011-11-09 16:58:01 DB Dump