Domanda

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

È stato utile?

Soluzione

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';

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top