pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Mario Behring <mariobehring@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Droping indexes
Date: Tue, 16 Jan 2007 10:24:27 -0600
Message-ID: <1168964667.9586.8.camel@state.g2switchworks.com> (raw)
In-Reply-To: <726736.33764.qm@web30001.mail.mud.yahoo.com>
References: <726736.33764.qm@web30001.mail.mud.yahoo.com>

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.



view thread (8+ messages)  latest in thread

Message-ID: <1168964667.9586.8.camel@state.g2switchworks.com>
Permalink:  ../1168964667.9586.8.camel@state.g2switchworks.com/
Also on:    postgresql.org/message-id/1168964667.9586.8.camel@state.g2switchworks.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: smarlowe@g2switchworks.com, mariobehring@yahoo.com
  Subject: Re: Droping indexes
  In-Reply-To: <1168964667.9586.8.camel@state.g2switchworks.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox