X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BD2E852968 for ; Wed, 13 Jul 2005 08:31:41 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97145-08 for ; Wed, 13 Jul 2005 11:31:31 +0000 (GMT) Received: from mailserver.gpmd.co.uk (unknown [217.8.241.55]) by svr1.postgresql.org (Postfix) with ESMTP id 6A27D52B5E for ; Wed, 13 Jul 2005 08:31:28 -0300 (ADT) Received: (qmail 1133 invoked by uid 107); 13 Jul 2005 11:31:31 -0000 Received: from unknown (HELO gvickrage) (graham@gpmd.net@84.9.13.245) by mailserver.gpmd.co.uk with SMTP; 13 Jul 2005 11:31:31 -0000 From: "Graham Vickrage" To: Subject: Re: Copy user privileges Date: Wed, 13 Jul 2005 12:31:29 +0100 Message-ID: <001a01c5879e$69e7ab20$0c67a8c0@gvickrage> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 In-Reply-To: <20050712192915.GA86199@winnie.fuhr.org> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.031 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/109 X-Sequence-Number: 22087 Thanks for the suggestions but as you guessed I do need to keep the old user and also groups would be unsuitable as I don't want either user to be able to see data on the other database. Thought there would be some SQL statement I could run on the sys tables but I don't know enough about the internals to attempt it. Thanks again, Graham -----Original Message----- From: Michael Fuhr [mailto:mike@fuhr.org] Sent: 12 July 2005 20:29 To: Tom Lane Cc: Graham Vickrage; pgsql-sql@postgresql.org Subject: Re: [SQL] Copy user privileges On Tue, Jul 12, 2005 at 03:12:50PM -0400, Tom Lane wrote: > "Graham Vickrage" 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/