Re: Droping indexes - Mailing list pgsql-sql

From Scott Marlowe
Subject Re: Droping indexes
Date
Msg-id 1168964667.9586.8.camel@state.g2switchworks.com
Whole thread Raw
In response to Droping indexes  (Mario Behring <mariobehring@yahoo.com>)
List pgsql-sql
On Tue, 2007-01-16 at 07:51, Mario Behring wrote:
> Hi all,
> 
> Please, if I drop all indexes from a table, can I recreate them after
> performing a vacuum full at this table? I mean, I do not know details
> about the indexes, so what I am asking is if I issue a REINDEX on this
> table, will it  create the proper indexes again?

The bad news:  No.  Once you drop an index it's just gone.
More bad news:  If it's a primary key index, you probably can't drop it
either.

Very good news:  PostgreSQL stores an index definition for easy index
recreation.  Let's say your tablename is "mytable"

This query will get you all the index creation statements for mytable:

select indexdef from pg_indexes where tablename='mytable';
CREATE UNIQUE INDEX mytable_pkey ON mytable USING btree (id)CREATE UNIQUE INDEX mytable_i1_key ON mytable USING btree
(i1)CREATEINDEX mytable_i1_i2 ON mytable USING btree (i1, i2)
 

Note that if you're using a schema other than the public one, you might
need to add 

tablespace='tablespacename' to the where clause.


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Removing CONTEXT message
Next
From: Frank Bax
Date:
Subject: Re: Droping indexes