Siddhant Sukhatankar
Siddhant Sukhatankar

Reputation: 55

How can we get list of default indexes on primary keys used by PostgreSQL?

I want a list of default indexes built on primary keys of table used by PostgreSQL for query processing.

Upvotes: 0

Views: 837

Answers (2)

Mahmmoud Kinawy
Mahmmoud Kinawy

Reputation: 891

SELECT RELNAME,
    RELKIND
FROM PG_CLASS
WHERE RELKIND = 'i';

This is command is in PostgreSQL DB, and it Will list all the indexes that got created by default when you created a Unique column or Primary Key.

Upvotes: 0

Adrian Klaver
Adrian Klaver

Reputation: 19665

From here:

https://www.postgresql.org/docs/current/catalog-pg-constraint.html

SELECT 
    conname, contype, conindid::regclass 
FROM 
    pg_constraint 
WHERE 
    contype = 'p';

Where conindid::regclass is the index name.

Upvotes: 1

Related Questions