Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id EB4079FB302 for ; Tue, 16 Jan 2007 12:24:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 31166-04 for ; Tue, 16 Jan 2007 12:24:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 0F38D9FB1D3 for ; Tue, 16 Jan 2007 12:24:38 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 16 Jan 2007 16:24:30 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 16 Jan 2007 10:24:27 -0600 Subject: Re: Droping indexes From: Scott Marlowe To: Mario Behring Cc: pgsql-sql@postgresql.org In-Reply-To: <726736.33764.qm@web30001.mail.mud.yahoo.com> References: <726736.33764.qm@web30001.mail.mud.yahoo.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1168964667.9586.8.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 16 Jan 2007 10:24:27 -0600 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/59 X-Sequence-Number: 27211 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.