Skip to content

Instantly share code, notes, and snippets.

@garethrees
Last active February 16, 2020 17:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save garethrees/42ca8dd64182515d6aa90000463ebfe1 to your computer and use it in GitHub Desktop.
Save garethrees/42ca8dd64182515d6aa90000463ebfe1 to your computer and use it in GitHub Desktop.
List all indexes in postgres database
SELECT indexname FROM pg_indexes;
@petercelentano
Copy link

I think you mean "select" instead of "selext".

Copy link

ghost commented Jan 16, 2018

πŸ™‰

@dmcmulle
Copy link

This is the #1 Google result for "list all indexes postgres" 🐱

@sainnr
Copy link

sainnr commented Feb 26, 2018

@dmcmulle but still has a typo πŸ˜ƒ

Btw, if anyone wants to specify a schema: select indexname from pg_indexes where schemaname = 'public';

@PeteDevoy
Copy link

PeteDevoy commented Jul 25, 2018

FIXED:

SELECT indexname FROM pg_indexes;

@runekaagaard
Copy link

@finete
Copy link

finete commented Sep 13, 2018

FIXED:

runekaagaard/postgres@d22492d

πŸ‘ for taking the time to do this

@axelson
Copy link

axelson commented Nov 7, 2018

You can also type \di

@IvanAnishchuk
Copy link

You can also type \di

πŸ‘ πŸ‘ πŸ‘ It also shows you additional info that way. On the other hand, if you use select * from pg_indexes; you also get to see the index definitions.

@and800
Copy link

and800 commented Jan 4, 2019

@runekaagaard is it possible to make the parser handle both versions?

@WesternGun
Copy link

WesternGun commented Feb 18, 2019

-- select indexes of tables in schema "public" --
select * from pg_indexes where schemaname = 'public'; 

The table has columns schemaname, tablename, indexname, tablespace, and SQL query of creation in indexdef.

@lzambarda
Copy link

Excluding pg_catalog may be a more useful approach if you are looking for some particular indices:

SELECT indexname FROM pg_indexes WHERE schemaname!='pg_catalog'

@garethrees
Copy link
Author

Wow, didn't realise this was getting so much attention. I don't think I'd been getting emails about gists until this week – perhaps its a new GitHub thing. Anyway, fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment