Re: reclaiming space from heavily used tables?

From: Jeremy Finzel <finzelj(at)gmail(dot)com>
To: Rob Nikander <rob(dot)nikander(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: reclaiming space from heavily used tables?
Date: 2017-12-18 19:08:11
Message-ID: CAMa1XUiUAXeugw2e9we9o9r+Ucg5_L38rZ9Zok4WdX4wYPokMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Dec 18, 2017 at 1:03 PM, Rob Nikander <rob(dot)nikander(at)gmail(dot)com>
wrote:

> 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.
>
>
This is what you want: https://github.com/reorg/pg_repack

This has been around for many years and is a very trusted extension (when
will it be in core????).

> Rob
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2017-12-18 19:19:58 Re: reclaiming space from heavily used tables?
Previous Message Rob Nikander 2017-12-18 19:03:14 reclaiming space from heavily used tables?