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 1emmyE-0003Q9-0m for pgsql-general@arkaria.postgresql.org; Fri, 16 Feb 2018 20:51:02 +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 1emmyD-0002NQ-36 for pgsql-general@arkaria.postgresql.org; Fri, 16 Feb 2018 20:51:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1emmyC-0002NG-M5 for pgsql-general@lists.postgresql.org; Fri, 16 Feb 2018 20:51:00 +0000 Received: from mail-oi0-x22a.google.com ([2607:f8b0:4003:c06::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1emmy8-0002My-RJ for pgsql-general@postgresql.org; Fri, 16 Feb 2018 20:51:00 +0000 Received: by mail-oi0-x22a.google.com with SMTP id l124so3273329oib.0 for ; Fri, 16 Feb 2018 12:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pgsqlrocket-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=z8W2WDu2a8ULxUWZjzutvgYPQdFNDwKMYddhqrfgmgM=; b=X7JmfHn/wiCn69JsdwnS/pXMUPIqCwmj6nZHHhw6a4rqs/RpD5onofO2PLplJ7XSd+ QtzsguQoeclrjpOrpnc8AxITz2qby7HJNNoFA2xdiHgwRIeMuZExKhFwnsGKfEgcM6Se 4VbgvMHOhFEA3hJ2JGdq0f/DDdZI+AVMrk/fOMk7KT1wsB4gHmbh2+qslHAWLF//WH2p Y9kcujRbqNEAFn/nFjUBhiMkb9zFvXt2pu0t0m6hVa73BA0bKO21YEmsu/gRD1+UgGfJ nZDoXsYR01in9XuFAejlsey3/9Z7Cr3Wv39bxnQzfVs9l7iw6dolxpaUacBhmZL+ZZz9 mxzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=z8W2WDu2a8ULxUWZjzutvgYPQdFNDwKMYddhqrfgmgM=; b=fZxAScUhdGDdvqtKAGqrNqb3Gkez82gQH9tSNSyob+l0933diQEQbZowkYUYClvlEO x8TGI3W4xHFk6RVcjl6QjxaDiK8kuiAfM9yBcDSusavteOfc8hnjkwP18gbch2r44Ve7 SXeupoNGz1cNcLZzlPPSFr7bwFsB2r2eu3ZqNiOJPIsz/8E0inlJ7hJwS3iHQKwoQ/Wu BVqEI3LChJjd3iZGadLfmH7ZqSMWKiBUJFwF+saxGBU0MLfcGpyDk7fVhZWYOcAFYDVM CzoQYDhYaT4kbW3BTFrtNf+Wk+Vqx1I2J0GXDK1tBeZ3irVrWTzXApfgJUq3cB+XMVAJ KAfw== X-Gm-Message-State: APf1xPB51fy/RAX900cGeDWyCtL3LVHwfQnf6jCG7kH5D+GnDGbsYv7s xVhQVXe+M6yw5wJwy7HdZ0lWJi/s020= X-Google-Smtp-Source: AH8x2278sseGdw8f5njjFiRpverTaqXZwCjXoj+Wa/fMwK8LIWeaRYy7XpuNUHagKcVK4tssxxRAsQ== X-Received: by 10.202.19.13 with SMTP id e13mr4927161oii.154.1518814254667; Fri, 16 Feb 2018 12:50:54 -0800 (PST) Received: from localhost.localdomain ([65.132.155.214]) by smtp.gmail.com with ESMTPSA id k32sm10669167otb.69.2018.02.16.12.50.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 12:50:54 -0800 (PST) Subject: Re: gathering ownership and grant permissions From: chris To: Melvin Davidson Cc: Postgres General References: <2bc1e56d-74ea-3590-a253-970f0e564467@pgsqlrocket.com> <15f84768-27ce-593f-9120-bc85ec7a4fdf@pgsqlrocket.com> Message-ID: <0c307f7a-56ae-cee8-61cb-a1ebcf6c2fde@pgsqlrocket.com> Date: Fri, 16 Feb 2018 13:50:53 -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: <15f84768-27ce-593f-9120-bc85ec7a4fdf@pgsqlrocket.com> Content-Type: multipart/alternative; boundary="------------4286CF14BF19FD8BECBF48D3" 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. --------------4286CF14BF19FD8BECBF48D3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit I'm sorry I realized that I only need to know which users have permissions to the table which I can do through $ psql -t SELECT grantee FROM information_schema.role_table_grants WHERE table_name='table_name' GROUP BY grantee; thanks! On 02/16/2018 01:13 PM, chris wrote: > > 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. > --------------4286CF14BF19FD8BECBF48D3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

I'm sorry I realized that I only need to know which users have permissions to the table which I can do through

$ psql -t

SELECT grantee                                               
FROM information_schema.role_table_grants
WHERE table_name='table_name'  
GROUP BY grantee;

thanks!



On 02/16/2018 01:13 PM, chris wrote:

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.



--------------4286CF14BF19FD8BECBF48D3--