pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Graham Vickrage <graham@gpmd.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: Copy user privileges
Date: Tue, 12 Jul 2005 13:29:16 -0600
Message-ID: <20050712192915.GA86199@winnie.fuhr.org> (raw)
In-Reply-To: <21463.1121195570@sss.pgh.pa.us>
References: <013301c586dc$369ad110$0c67a8c0@gvickrage>
	<21463.1121195570@sss.pgh.pa.us>

On Tue, Jul 12, 2005 at 03:12:50PM -0400, Tom Lane wrote:
> "Graham Vickrage" <graham@gpmd.co.uk> writes:
> > I want to keep all the privileges but assign them to a new user. 
> 
> > What is the best way of doing this?
> 
> How about just renaming the old user to a new name?
> 
> I don't think we have an ALTER command for that, but an UPDATE on
> pg_shadow would get the job done just as well.

What about ALTER USER RENAME TO?

test=# CREATE USER user1;
CREATE USER
test=# CREATE TABLE foo (x integer);
CREATE TABLE
test=# GRANT SELECT ON foo TO user1;
GRANT
test=# \z foo
                Access privileges for database "test"
 Schema | Name | Type  |              Access privileges               
--------+------+-------+----------------------------------------------
 public | foo  | table | {postgres=arwdRxt/postgres,user1=r/postgres}
(1 row)

test=# ALTER USER user1 RENAME TO user2;
ALTER USER
test=# \z foo
                Access privileges for database "test"
 Schema | Name | Type  |              Access privileges               
--------+------+-------+----------------------------------------------
 public | foo  | table | {postgres=arwdRxt/postgres,user2=r/postgres}
(1 row)

Renaming the user is only useful if you no longer need the old user.
If you need to keep the old user and copy its privileges, then consider
granting privileges to groups instead of to users -- then you could
just add the new user to a group.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



view thread (4+ messages)  latest in thread

Message-ID: <20050712192915.GA86199@winnie.fuhr.org>
Permalink:  ../20050712192915.GA86199@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050712192915.GA86199@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, tgl@sss.pgh.pa.us, graham@gpmd.co.uk
  Subject: Re: Copy user privileges
  In-Reply-To: <20050712192915.GA86199@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox