Skip to content

Instantly share code, notes, and snippets.

@garethrees
Last active February 16, 2020 17:34
Show Gist options
  • 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;
@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