Postgresql – how to list indexes on a table that is partitioned

partitioningpostgresqlpostgresql-11

This command works for non-partitioned tables:

select * from pg_indexes

But for partitioned tables, it does not list the original index, but the indexes that postgresql created for each partition.

To drop an index, I need the original name.

How do I list all indexes on a table that is partitioned (with the name it was created)?

Best Answer

Workaround:

create or replace view vw_list_indexes
as
    select i.relname as indexname, t.relname as tablename, t.OID, idx.indisprimary
    from pg_class i
    join pg_index idx on idx.indexrelid = i.oid
    join pg_class t on t.oid = idx.indrelid
    where i.relkind = 'I';

select * from vw_list_indexes where oid = 'schema.table'::regclass;