DBA Hub

📋Steps in this guide1/1

List down index details in postgres

--- It wil find the indexes present on a table 'test'

postgresql configurationintermediate
by PostgreSQL
13 views
1

List down index details in postgres

--- It wil find the indexes present on a table 'test' -- All indexes present in database: -- It will show all index details including size: -- Find indexes with respective column name for table( here table name is test)

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
postgres=#
select * from pg_indexes where tablename='test';
schemaname  | tablename | indexname | tablespace  | indexdef
------------+-----------+-----------+-------------+----------------------------------------------------------
public.     | test      | tes_idx1  | ts_postgres | CREATE INDEX tes_idx1 ON public.test USING btree (datid)
(1 row)
postgres#
select * from pg_indexes
postgres=#
\di+
List of relations
Schema  | Name     | Type  | Owner    | Table  | Size   | Description
--------+----------+-------+----------+--------+--------+-------------
public  | tes_idx  | index | postgres | test56 | 64 kB |
public  | tes_idx1 | index | postgres | test   | 472 MB |
(2 rows)
REFERENCE
- https://stackoverflow.com/questions/2204058/list-columns-with-indexes-in-postgresql
select
t.relname as table_name,
i.relname as index_name,
array_to_string(array_agg(a.attname), ', ') as column_names
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 ='
test
'
group by
t.relname,
i.relname
order by
t.relname,
i.relname;

Comments (0)

Please to add comments

No comments yet. Be the first to comment!