Принятый ответ не сработал (ошибка при выполнении).
В любом случае, вы можете перечислить все столбцы в базе данных и пометить все индексированные каким-либо образом столбцы (возможности ограничения набора строк результатов упоминаются как комментарии):
WITH
table_select as (
select row_number() over(ORDER BY relname) as rownum,
c.relname, c.oid, c.reltuples
FROM pg_class c
JOIN pg_namespace n ON (n.oid = c.relnamespace)
WHERE c.relkind = 'r'::"char"
--AND n.nspname = '%MyNameSpaceHere%'
ORDER BY c.relname
),
indxs as (
select distinct t.relname as table_name, a.attname as column_name
from pg_class t, pg_class i, pg_index ix, pg_attribute a
where
t.oid = ix.indrelid
and i.oid = ix.indexrelid
and a.attrelid = t.oid
and a.attnum = ANY(ix.indkey)
and t.relkind = 'r'
--and t.relname like 'mytable here'
and cast (i.oid::regclass as text) like '%MyNameSpaceHere%'
order by
t.relname --, i.relname
),
cols as (
select a.attname, a.attrelid, c.oid, col.TABLE_NAME, col.COLUMN_NAME
FROM table_select c
JOIN pg_attribute a ON (a.attrelid = c.oid) AND (a.attname <> 'tableoid')
LEFT JOIN information_schema.columns col ON
(col.TABLE_NAME = c.relname AND col.COLUMN_NAME = a.attname )
WHERE
( a.attnum >= 0 ) --attnum > 0 for real columns
)
--select * from table_select t
select c.TABLE_NAME, c.COLUMN_NAME,
case when i.column_name is not null then 'Y' else '' end as is_indexed
from cols c
left join indxs i on (i.table_name = c.table_name and i.column_name = c.column_name)
Пример результата:
table_name column_name is_indexed
'events id "Y"
events type "Y"
events descr "" '