查询某个schema下所有的主键信息请参考:
SELECT result.TABLE_SCHEM schem, result.TABLE_NAME 表名, result.COLUMN_NAME 主键列, result.KEY_SEQ
FROM (SELECT n.nspname AS TABLE_SCHEM,
ct.relname AS TABLE_NAME,
a.attname AS COLUMN_NAME,
(information_schema._pg_expandarray(i.indkey)).n AS KEY_SEQ,
ci.relname AS PK_NAME,
information_schema._pg_expandarray(i.indkey) AS KEYS,
a.attnum AS A_ATTNUM
FROM pg_catalog.pg_class ct
JOIN pg_catalog.pg_attribute a ON (ct.oid = a.attrelid)
JOIN pg_catalog.pg_namespace n ON (ct.relnamespace = n.oid)
JOIN pg_catalog.pg_index i ON (a.attrelid = i.indrelid)
JOIN pg_catalog.pg_class ci ON (ci.oid = i.indexrelid)
WHERE true
AND n.nspname = 'public'
AND i.indisprimary) result
where result.A_ATTNUM = (result.KEYS).x
ORDER BY result.table_name, result.pk_name, result.key_seq;