PostgreSQL: Getting the owner of tables

Posted December 11, 2013

This one was a head scratcher for me. How do you get the proper owner of the tables in PostgreSQL? I finally cobbled together a script that returns a list of tables and the owner name. I am using this to help me build a PostgreSQL migration tool that will display the changes of two different databases and help me by writing a script to overcome the differences.

I hope this helps people out in the future.

select t.table_name, t.table_type, c.relname, c.relowner, u.usename
from information_schema.tables t
join pg_catalog.pg_class c on (t.table_name = c.relname)
join pg_catalog.pg_user u on (c.relowner = u.usesysid)
where t.table_schema='public';

Posted in Linux, Software

Tags: , ,

One Response to “PostgreSQL: Getting the owner of tables”

Leave a Reply