PostgreSQL: Getting the owner of tables

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';

One thought on “PostgreSQL: Getting the owner of tables

  1. Pingback: PostgreSQL: Getting the owner of tables | Foxpro Access Database Maintenance in Singapore

Leave a Reply