Disable an index in postgres

If you have got one index on a table that you would like to temporarily disable you can do following steps.

You can poke the system catalogue to disable an index:

update pg_index set indisvalid = false where indexrelid = 'test_pkey'::regclass

This means that the index won’t be used for queries but will still be updated. It’s one of the flags used for concurrent index building.

If you want to run a single query without using index, you can use following query.

begin;
drop index mytable_index;

explain analyze select * from mytable;
rollback;

I don’t think there is a way to disable just one, though you can do this in a transaction to make recovering from it very simple. You can also disable indexscan to disable all indices.

Reference : http://stackoverflow.com/questions/6146024/is-it-possible-to-temporarily-disable-an-index-in-postgres

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s