<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: PostgreSQL: Script to find all Objects of a Particular User	</title>
	<atom:link href="https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 23 Oct 2019 00:10:23 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>
		By: bucket		</title>
		<link>https://www.dbrnd.com/2018/09/postgresql-script-to-find-all-objects-of-a-particular-user/#comment-7827</link>

		<dc:creator><![CDATA[bucket]]></dc:creator>
		<pubDate>Wed, 23 Oct 2019 00:10:23 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7708#comment-7827</guid>

					<description><![CDATA[with owned_objects as (
  select 
      nsp.nspname as SchemaName
      ,cls.relname as ObjectName 
      ,rol.rolname as ObjectOwner
      ,case cls.relkind
          when &#039;r&#039; then &#039;TABLE&#039;
          when &#039;m&#039; then &#039;MATERIALIZED_VIEW&#039;
          when &#039;i&#039; then &#039;INDEX&#039;
          when &#039;S&#039; then &#039;SEQUENCE&#039;
          when &#039;v&#039; then &#039;VIEW&#039;
          when &#039;c&#039; then &#039;TYPE&#039;
          else cls.relkind::text
      end as ObjectType
  from pg_class cls
  join pg_roles rol 
    on rol.oid = cls.relowner
  join pg_namespace nsp 
    on nsp.oid = cls.relnamespace
  where nsp.nspname not in (&#039;information_schema&#039;, &#039;pg_catalog&#039;)
      and nsp.nspname not like &#039;pg_toast%&#039;
      and rol.rolname = &#039;postgres&#039;  
  order by nsp.nspname, cls.relname
)
select
  case 
    when oo.ObjectType = &#039;TABLE&#039; then
      &#039;alter table &#039; &#124;&#124; oo.ObjectName &#124;&#124; &#039; owner to NEW_ROLE;&#039;
    when oo.ObjectType = &#039;MATERIALIZED_VIEW&#039; then
      &#039;alter materialized view &#039; &#124;&#124; oo.ObjectName &#124;&#124; &#039; owner to NEW_ROLE;&#039;
    when oo.ObjectType = &#039;INDEX&#039; then
      &#039;alter index &#039; &#124;&#124; oo.ObjectName &#124;&#124; &#039; owner to NEW_ROLE;&#039;
    when oo.ObjectType = &#039;INDEX&#039; then
      &#039;alter index &#039; &#124;&#124; oo.ObjectName &#124;&#124; &#039; owner to NEW_ROLE;&#039;
    when oo.ObjectType = &#039;SEQUENCE&#039; then
      &#039;alter sequence &#039; &#124;&#124; oo.ObjectName &#124;&#124; &#039; owner to NEW_ROLE;&#039;
    when oo.ObjectType = &#039;VIEW&#039; then
      &#039;alter view &#039; &#124;&#124; oo.ObjectName &#124;&#124; &#039; owner to NEW_ROLE;&#039;
    else &#039;dunno: &#039; &#124;&#124; oo.ObjectType
  end
from owned_objects oo
;


an easy way to generate sql to change owners]]></description>
			<content:encoded><![CDATA[<p>with owned_objects as (<br />
  select<br />
      nsp.nspname as SchemaName<br />
      ,cls.relname as ObjectName<br />
      ,rol.rolname as ObjectOwner<br />
      ,case cls.relkind<br />
          when &#8216;r&#8217; then &#8216;TABLE&#8217;<br />
          when &#8216;m&#8217; then &#8216;MATERIALIZED_VIEW&#8217;<br />
          when &#8216;i&#8217; then &#8216;INDEX&#8217;<br />
          when &#8216;S&#8217; then &#8216;SEQUENCE&#8217;<br />
          when &#8216;v&#8217; then &#8216;VIEW&#8217;<br />
          when &#8216;c&#8217; then &#8216;TYPE&#8217;<br />
          else cls.relkind::text<br />
      end as ObjectType<br />
  from pg_class cls<br />
  join pg_roles rol<br />
    on rol.oid = cls.relowner<br />
  join pg_namespace nsp<br />
    on nsp.oid = cls.relnamespace<br />
  where nsp.nspname not in (&#8216;information_schema&#8217;, &#8216;pg_catalog&#8217;)<br />
      and nsp.nspname not like &#8216;pg_toast%&#8217;<br />
      and rol.rolname = &#8216;postgres&#8217;<br />
  order by nsp.nspname, cls.relname<br />
)<br />
select<br />
  case<br />
    when oo.ObjectType = &#8216;TABLE&#8217; then<br />
      &#8216;alter table &#8216; || oo.ObjectName || &#8216; owner to NEW_ROLE;&#8217;<br />
    when oo.ObjectType = &#8216;MATERIALIZED_VIEW&#8217; then<br />
      &#8216;alter materialized view &#8216; || oo.ObjectName || &#8216; owner to NEW_ROLE;&#8217;<br />
    when oo.ObjectType = &#8216;INDEX&#8217; then<br />
      &#8216;alter index &#8216; || oo.ObjectName || &#8216; owner to NEW_ROLE;&#8217;<br />
    when oo.ObjectType = &#8216;INDEX&#8217; then<br />
      &#8216;alter index &#8216; || oo.ObjectName || &#8216; owner to NEW_ROLE;&#8217;<br />
    when oo.ObjectType = &#8216;SEQUENCE&#8217; then<br />
      &#8216;alter sequence &#8216; || oo.ObjectName || &#8216; owner to NEW_ROLE;&#8217;<br />
    when oo.ObjectType = &#8216;VIEW&#8217; then<br />
      &#8216;alter view &#8216; || oo.ObjectName || &#8216; owner to NEW_ROLE;&#8217;<br />
    else &#8216;dunno: &#8216; || oo.ObjectType<br />
  end<br />
from owned_objects oo<br />
;</p>
<p>an easy way to generate sql to change owners</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
