Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1emmO3-0001N1-M7 for pgsql-general@arkaria.postgresql.org; Fri, 16 Feb 2018 20:13:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emmO2-000251-6U for pgsql-general@arkaria.postgresql.org; Fri, 16 Feb 2018 20:13:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1emmO1-00024r-RX for pgsql-general@lists.postgresql.org; Fri, 16 Feb 2018 20:13:37 +0000 Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1emmNy-0001e4-NM for pgsql-general@postgresql.org; Fri, 16 Feb 2018 20:13:36 +0000 Received: by mail-oi0-x231.google.com with SMTP id t145so3180585oif.8 for ; Fri, 16 Feb 2018 12:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pgsqlrocket-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=qYFZF5crUOC7nVUFkmYuEsqFHcokclgIIWfe1IAjvhs=; b=TddfhqyuBVpANsLSdwkDeqRP1XKQ6pDsXj7nPaNqVZzOewOAFqAL8D0ZO/7OISQx6K wY4e6ZYTbPghcJeiS/l9ZXgeKCS5qh1ysmnRwHcAyWo2zxyElQzQk6Wh1qAvBfbjVclP tPeAlps/T5x7N9SU0+AhHLzGZDKOb7PHsE8IT3qtSjUjc3yYCQ6+s1NCZ/XC/2yo2WzR SZuMVxKEmPiJbLyWoBvCrbCK3qENRCcKirH953K8uAY3JOh7+VxHOJIPI4zLc/4uFVd+ P+1f9GxPkjB3YqEyLL7FDHgCy+1SbA7tKP/9cnfUZihH3EuwNoob+5KUyuLM7GsFo+yV uzNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=qYFZF5crUOC7nVUFkmYuEsqFHcokclgIIWfe1IAjvhs=; b=Nue+lKHoE85gWRYvawY8LCj2yueFvF0rlThxJqeh8HwrOqFWaTsXuwj5JO3elUdtsN Fr+vmZsMnxITDcfnI2MCpykP+Xu0MrZu1MtVVApxkltA3oRXk+aLe7XXzZu5kv/I5e0X q1qW+SFwaqLB7Ras3Q9tTU1NaSivSw3f1m+RDmTlHxkTyZBB/GyHzCE97WXRUukJdlaZ iAX1G7Eku7z3KFTFIxUISKGfXHYm/gCy1CfE5gTUjS+W3GMCfW+ZLdVBHcWA3mdSb8I3 dFpy8gVOB0xco5+6+F/a0/k5xs7EfGZJM01kiMtMaM993Wj3Fb7nHrpV5g+kVZGC0s22 by+Q== X-Gm-Message-State: APf1xPBuqusCcUwS/LK1f8ZtPvX5rdpHrhd6qrCpcNA87fO1+y11Wrgj PoRG6xZPIUokCLCZ4z+ld4XZJkxFHyA= X-Google-Smtp-Source: AH8x227QZBJPt72qmV6pIOBSc+iKCsqG+ghKmL9sxV5HgGItzQiQ7HJC/u7RswMI9XmrZbrdIqB8EA== X-Received: by 10.202.205.209 with SMTP id d200mr5281021oig.253.1518812013553; Fri, 16 Feb 2018 12:13:33 -0800 (PST) Received: from localhost.localdomain ([65.132.155.214]) by smtp.gmail.com with ESMTPSA id c40sm1821991otc.20.2018.02.16.12.13.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 12:13:33 -0800 (PST) Subject: Re: gathering ownership and grant permissions To: Melvin Davidson Cc: Postgres General References: <2bc1e56d-74ea-3590-a253-970f0e564467@pgsqlrocket.com> From: chris Message-ID: <15f84768-27ce-593f-9120-bc85ec7a4fdf@pgsqlrocket.com> Date: Fri, 16 Feb 2018 13:13:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------E7DB532C3188D76A4F255131" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------E7DB532C3188D76A4F255131 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Thanks for the quick response. That does not work for what I need because I only need the owner and permissions of one table, I need the grant to look like the output that pg_dump displays. ex: GRANT ALL ON TABLE testing_cdc TO bob; -- -- PostgreSQL database dump complete -- I need a way which my script can isolate the owner's name and set it to a variable on its own. Same with grant. Thanks On 02/16/2018 01:05 PM, Melvin Davidson wrote: > > > On Fri, Feb 16, 2018 at 2:47 PM, chris > wrote: > > HI, > > I would like to know if there is a better way to grab the grant > permissions  as well as the "owner to" of a table. > > I can currently do this through a pg_dumb with greps for "^grant" > and "^alter" but than I need to do a word search of those lines > looking for the specific answers which gets much more involved. > > I essentially need to know what grant command was ran and use that > grant permission to set to a variable for a script. > > Ex: GRANT ALL ON TABLE testing TO bob; then set only the "all" to > a variable. > > And then same for the ALTER .... OWNER TO bob. > > This is on postgresl 9.6. > > Thank you, > > Chris > > > > *>... is a better way to grab the grant permissions  as well as the > "owner to" of a table. > > * > *Chris, see if the query below will help. Note, you need to execute as > a superuser. > > SELECT n.nspname, >                c.relname, >                o.rolname AS owner, >                array_to_string(ARRAY[c.relacl], '|') as permits >   FROM pg_class c >     JOIN pg_namespace n ON (n.oid = c.relnamespace) >     JOIN pg_authid o ON (o.oid = c.relowner) > WHERE n.nspname not like 'pg_%' >      AND n.nspname not like 'inform_%' >      AND relkind = 'r' > ORDER BY 1;* > > > > > -- > *Melvin Davidson* > I reserve the right to fantasize.  Whether or not you > wish to share my fantasy is entirely up to you. --------------E7DB532C3188D76A4F255131 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Thanks for the quick response.

That does not work for what I need because I only need the owner and permissions of one table, I need the grant to look like the output that pg_dump displays.

ex:

GRANT ALL ON TABLE testing_cdc TO bob;


--
-- PostgreSQL database dump complete
--

I need a way which my script can isolate the owner's name and set it to a variable on its own. Same with grant.

Thanks


On 02/16/2018 01:05 PM, Melvin Davidson wrote:


On Fri, Feb 16, 2018 at 2:47 PM, chris <chrisk@pgsqlrocket.com> wrote:
HI,

I would like to know if there is a better way to grab the grant permissions  as well as the "owner to" of a table.

I can currently do this through a pg_dumb with greps for "^grant" and "^alter" but than I need to do a word search of those lines looking for the specific answers which gets much more involved.

I essentially need to know what grant command was ran and use that grant permission to set to a variable for a script.

Ex: GRANT ALL ON TABLE testing TO bob; then set only the "all" to a variable.

And then same for the ALTER .... OWNER TO bob.

This is on postgresl 9.6.

Thank you,

Chris



>... is a better way to grab the grant permissions  as well as the "owner to" of a table.

Chris, see if the query below will help. Note, you need to execute as a superuser.

SELECT n.nspname,
               c.relname,
               o.rolname AS owner,
               array_to_string(ARRAY[c.relacl], '|') as permits
  FROM pg_class c
    JOIN pg_namespace n ON (n.oid = c.relnamespace)
    JOIN pg_authid o ON (o.oid = c.relowner)
WHERE n.nspname not like 'pg_%'
     AND n.nspname not like 'inform_%'
     AND relkind = 'r'
ORDER BY 1;





--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.


--------------E7DB532C3188D76A4F255131--