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 8CA785E485C for ; Mon, 6 Sep 2004 07:24:57 +0100 (BST) 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 75856-08 for ; Mon, 6 Sep 2004 06:24:55 +0000 (GMT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id B389D5E484A for ; Mon, 6 Sep 2004 07:24:52 +0100 (BST) Received: from lfix.demon.co.uk ([80.177.205.209] helo=cerberus.lfix.co.uk) by anchor-post-35.mail.demon.net with esmtp (Exim 3.35 #1) id 1C4Cvt-00002Y-0Z; Mon, 06 Sep 2004 06:24:53 +0000 Received: from linda.lfix.co.uk ([192.168.1.1]) by cerberus.lfix.co.uk with esmtp (Exim 4.34) id 1C4Cvo-0005o2-IY; Mon, 06 Sep 2004 07:24:48 +0100 Subject: Re: Full access to a DB with a second user? From: Oliver Elphick Reply-To: olly@lfix.co.uk To: Erik Wasser Cc: pgsql-sql@postgresql.org In-Reply-To: <200409051453.57182.erik.wasser@iquer.net> References: <200409051453.57182.erik.wasser@iquer.net> Content-Type: text/plain Organization: LFIX Limited Message-Id: <1094451888.6360.168.camel@linda> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Mon, 06 Sep 2004 07:24:48 +0100 Content-Transfer-Encoding: 7bit X-LFIX-MailScanner: Found to be clean X-MailScanner-From: olly@lfix.co.uk X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/36 X-Sequence-Number: 18882 On Sun, 2004-09-05 at 13:53, Erik Wasser wrote: > Hello pgsql-sql@postgresql.org, > > how can I gave a user full access (SELECT, INSERT,...) to a database > that he doesn't own? I used google to find a solution and I find a > Statement[1] that will the do the trick. But it looks very cryptical to > me. B-) What does this statement do? > > > \a This is a psql directive to urn off output alignment. > > \t Don't show column headers or the row count > > \o /tmp/grant.sql Redirect output to the named file > > SELECT 'GRANT ALL ON ' || n.nspname || '.' || c.relname || > > ' TO joe;' > > FROM pg_catalog.pg_class AS c > > LEFT JOIN pg_catalog.pg_namespace AS n > > ON n.oid = c.relnamespace > > WHERE c.relkind IN ('r','v','S') AND > > n.nspname NOT IN ('pg_catalog', 'pg_toast') AND > > pg_catalog.pg_table_is_visible(c.oid) > > ORDER BY n.nspname, c.relname; Read the system catalog for a list of relations and construct a GRANT command for each one to give ALL access to user joe. The output looks like this: GRANT ALL ON prod.address TO joe; GRANT ALL ON prod.address_id_seq TO joe; GRANT ALL ON prod.address_telephone TO joe; GRANT ALL ON prod.area TO joe; ... and is written into the file /tmp/grant.sql as directd earlier. > > \o Stop sending output to the file. > > \i /tmp/grant.sql Run the output file as a script, thus granting the permissions to joe. -- Oliver Elphick olly@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA ======================================== "Behold, I stand at the door, and knock; if any man hear my voice, and open the door, I will come in to him, and will sup with him, and he with me." Revelation 3:20