4

how can I detect GIN and GiST indexes in postgresql? I am looking for if an database of postgres use fulltext. I think that a table use GIN o GiST then is using fulltext.

I accept that GIN or GiST indexes does not necessarily mean that they are used for full text search, but how can I differentiate them of other indexes type? I want to list Gin an Gist indexes

Charles
  • 50,943
  • 13
  • 104
  • 142
  • Presence of GIN or GiST indexes does not necessarily mean that they are used for full text search. – mvp Feb 06 '13 at 05:51

2 Answers2

3

Index definitions can be recreated with pg_get_indexdef() from the System Catalog Information Functions, fed by the pg_index system view. The output is theorically non-trivial to parse but in practice, a simple regexp is good enough to filter these definitions on certain index types.

For example, to find gist or gin indexes, you may use a query like this:

SELECT pg_get_indexdef(indexrelid) from pg_index
 WHERE pg_get_indexdef(indexrelid) ~ 'USING (gin |gist )';

To find if a certain database uses fulltext, I'd probably search for tsvector columns instead, with a query like this:

SELECT table_schema,table_name, column_name
 FROM information_schema.columns
 WHERE data_type='tsvector';
Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
3

I dug around in the Postgres source code and found that this information is stored in the pg_am table:

select i.relname, a.amname
from pg_index ix
left join pg_class i on ix.indexrelid = i.oid
left join pg_class t on ix.indrelid = t.oid
left join pg_am a on i.relam = a.oid
Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111