From: | Scott Marlowe <smarlowe(at)g2switchworks(dot)com> |
---|---|
To: | Mario Behring <mariobehring(at)yahoo(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Droping indexes |
Date: | 2007-01-16 16:24:27 |
Message-ID: | 1168964667.9586.8.camel@state.g2switchworks.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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)
CREATE INDEX 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Frank Bax | 2007-01-16 16:27:43 | Re: Droping indexes |
Previous Message | Tom Lane | 2007-01-16 16:23:36 | Re: Removing CONTEXT message |