This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a script for getting the list of objects of a particular User (Owner of the Object) in PostgreSQL.
Generally, PostgreSQL DBAs are using this kind of script for auditing purpose and object tracking purpose.
Using the below script, you can get the list object for a particular user:
I used a ‘postgres’ default user in WHERE condition, which you can edit as per your user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
select nsp.nspname as SchemaName ,cls.relname as ObjectName ,rol.rolname as ObjectOwner ,case cls.relkind when 'r' then 'TABLE' when 'm' then 'MATERIALIZED_VIEW' when 'i' then 'INDEX' when 'S' then 'SEQUENCE' when 'v' then 'VIEW' when 'c' then 'TYPE' 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 ('information_schema', 'pg_catalog') and nsp.nspname not like 'pg_toast%' and rol.rolname = 'postgres' order by nsp.nspname, cls.relname |