Could you tell me how to check what indexes are created for some table in postgresql ?
5 Answers
The view pg_indexes provides access to useful information about each index in the database, eg.
select *
from pg_indexes
where tablename not like 'pg%';

- 112,967
- 15
- 204
- 232
if you're in psql, then:
\d tablename
show Indexes, Foreign Keys and references...

- 1,923
- 1
- 10
- 9
-
3For case sensitive table names, use `\d "Tablename"` – Chiel May 06 '22 at 12:03
-
2Much easier to use than having to construct a query! – evantkchong Aug 05 '22 at 08:36
-
i tried `\d tablename` in dbeaver and its not working - `SQL Error [42601]: ERROR: syntax error at or near "\" Position: 1 Error position: line: 56` . Is there a way to run it in GUI/DBeaver. – samshers Dec 25 '22 at 15:36
-
1@samshers : No, it is client feature of `psql`. – helvete Jan 16 '23 at 14:12
You can use this query:
select tablename,indexname,tablespace,indexdef from pg_indexes where tablename = 'your_table_name'
;
where has tablename is a field in pg_indexes ,you an get an accurate indices by matching user defined table at 'your_table_name' at WHERE clause . This will give you the desired details.

- 833
- 8
- 20

- 501
- 4
- 3
You can find all the index related information inside the pg_indexes
view. Sometimes, a table may be part of some schema ("owner") or might have had a different name in the past (see: PostgreSQL Rename Table).
So first find out what is the schema ("owner") of the table:
SELECT schemaname, tablename FROM pg_tables WHERE tablename='table_name';
and then query indexes on the table with either of these queries:
SELECT tablename, indexname FROM pg_indexes WHERE tablename='table_name';
-- or
SELECT * FROM pg_indexes WHERE tablename='schema_name.table_name';
As an alternative to all the above, you can also use \d:
\d table_name;

- 14,003
- 3
- 51
- 63

- 598
- 6
- 4