pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: alan <alan.miller3@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: delete/recreate indexes
Date: Wed, 19 Oct 2011 19:51:09 -0700
Message-ID: <1319079069.16256.42.camel@jdavis> (raw)
In-Reply-To: <727c5bc3-0bab-490f-add7-6eed47627ee5@ff5g2000vbb.googlegroups.com>
References: <727c5bc3-0bab-490f-add7-6eed47627ee5@ff5g2000vbb.googlegroups.com>

On Wed, 2011-10-19 at 08:03 -0700, alan wrote:
> So I thought I’d just run this once (via cron) every morning.
>     BEGIN;
>         DROP INDEX data_unique;
>         UPDATE data SET datum = (data.datum + interval '24 hours');
>         CREATE UNIQUE INDEX data_unique ON public.data USING BTREE
> (device, group, datum);
>     COMMIT;
> 
> But
> 1.	it’s taking forever and
> 2.	I’m seeing that my disk is filling up real fast.

An unrestricted update will end up rewriting the whole table. It's
advisable to run VACUUM afterward, so that the wasted space can be
reclaimed. What version are you on? Do you have autovacuum enabled?

Also, to take a step back, why do you try to keep the timestamps
changing like that? Why not store the information you need in the record
(e.g. insert time as well as the datum) and then compute the result you
need using a SELECT (or make it a view for convenience)? Fundamentally,
these records aren't changing, you are just trying to interpret them in
the context of the current day. That should be done using a SELECT, not
an UPDATE.

Regards,
	Jeff Davis





view thread (4+ messages)  latest in thread

Message-ID: <1319079069.16256.42.camel@jdavis>
Permalink:  ../1319079069.16256.42.camel@jdavis/
Also on:    postgresql.org/message-id/1319079069.16256.42.camel@jdavis

 · 

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-performance@postgresql.org
  Cc: pgsql@j-davis.com, alan.miller3@gmail.com
  Subject: Re: delete/recreate indexes
  In-Reply-To: <1319079069.16256.42.camel@jdavis>

* 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