pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Nikander <rob.nikander@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: reclaiming space from heavily used tables?
Date: Mon, 18 Dec 2017 14:03:14 -0500
Message-ID: <8034843E-CB75-4272-B89D-B9462161275B@gmail.com> (raw)

Hi,

I've got a large table from which I'd like to completely reclaim space. I read the docs and it sounds like I can’t run `vacuum full`, because this table is accessed constantly and can’t have downtime. Assuming that’s true, what do you think of the following idea? Is there a better alternative?

1. Replace the table T with two tables T1 and T2 and a view T that is `select * from T1 union T2`.
2. Write only to T1, and slowly move records from T2 to T1. 
3. When T2 is empty, redefine the view T to be simply `select * from T1`.
4. Recreate or vacuum full T2, so space is fully reclaimed.
5. Redefine view as the union select and repeat process going other direction from T1 to T2, as needed.

I guess one question is whether I can do 1 and 3 (renaming tables, redefining views) atomically without disturbing concurrent select queries.

Rob





view thread (7+ messages)  latest in thread

Message-ID: <8034843E-CB75-4272-B89D-B9462161275B@gmail.com>
Permalink:  ../8034843E-CB75-4272-B89D-B9462161275B@gmail.com/
Also on:    postgresql.org/message-id/8034843E-CB75-4272-B89D-B9462161275B@gmail.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rob.nikander@gmail.com
  Subject: Re: reclaiming space from heavily used tables?
  In-Reply-To: <8034843E-CB75-4272-B89D-B9462161275B@gmail.com>
  References: <8034843E-CB75-4272-B89D-B9462161275B@gmail.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