pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mladen Gogala <gogala.mladen@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: WAL streaming and dropping a large table
Date: Sat, 23 Oct 2021 08:41:16 -0400
Message-ID: <b8b29eaa-31ad-8f9e-00a9-b0cb8c599b39@gmail.com> (raw)
In-Reply-To: <CANP_6+PuOvRxOrmEZH74vfRiQ00WtiJ3AQfd_rZ7507iuJkHPA@mail.gmail.com>
References: <CANP_6+PuOvRxOrmEZH74vfRiQ00WtiJ3AQfd_rZ7507iuJkHPA@mail.gmail.com>


On 10/21/21 16:23, Rory Falloon wrote:
> Hi,
>
> My postgres server setup is thus: a production database, which is 
> using WAL streaming (hot standby) to four other hosts of various 
> latencies. I Have a table that is ~200GB which has been backed up, and 
> now I Want to remove it. The table is not in use, it is a child table 
> to a parent table that _is_ in use but I foresee no issues here. The 
> total DB size is roughly 300GB.  The main reason for needing to remove 
> it is to recover the space back on the partition which is humming away 
> at 88% usage, and the table I wish to drop is better off in an archive 
> somewhere.
>
> I just removed around 10% of it with  'delete from', which of course 
> cascaded to the replication hosts. This increased the size of my 
> pg_xlog folder (from ~3GB to ~6.5GB) which of course increased my 
> partition usage. Obviously this is expected, but I wonder what would 
> happen if I had issued the 'drop table'?
>
> I expect the nature of enabling max_replication_slots would mean the 
> database would retain the wal segments until all have caught up; it 
> could take quite a long time to 'catch up' after the 'drop table' 
> command? It took about 10 minutes before the pg_xlog folder size had 
> 'settled down' to what I normally see as default which is ~3GB.
>
> > wal_keep_segments is defined as 128,
> > wal_max_size is not defined,
> > max_replication_slots is enabled
>
> I'd prefer to use 'drop table' as it would recover the data 
> immediately, but not if it will impact the production database in a 
> way that the partition will become full, which defeats the purpose. Is 
> it advisable to move the pg_xlog folder to another volume on the 
> system with more space (which I have) and symlink - obviously a stop & 
> start of the db required - and then let the WAL archives fill up as 
> need be? Or am I missing something obvious (likely)
>
> Thanks
>
Well, the difference between "drop table" and "delete" is that "drop 
table" is transaction on the data dictionary. PostgreSQL has 
transactional DDL, which means that "drop table" can be rolled back, so 
that transaction has to be protected by WAL, but it is just the log of 
the dictionary tables. There is the 3rd option, called "truncate" which 
is also a DDL which creates a new empty table with the same description 
and discards the old files.  Both 'drop" and "truncate" will not 
generate much WAL logs. On the other hand, "delete" is a regular DML 
transaction which will generate logs needed to recover the 200GB table.



-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com






view thread (2+ messages)

Message-ID: <b8b29eaa-31ad-8f9e-00a9-b0cb8c599b39@gmail.com>
Permalink:  ../b8b29eaa-31ad-8f9e-00a9-b0cb8c599b39@gmail.com/
Also on:    postgresql.org/message-id/b8b29eaa-31ad-8f9e-00a9-b0cb8c599b39@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: gogala.mladen@gmail.com
  Subject: Re: WAL streaming and dropping a large table
  In-Reply-To: <b8b29eaa-31ad-8f9e-00a9-b0cb8c599b39@gmail.com>
  References: <CANP_6+PuOvRxOrmEZH74vfRiQ00WtiJ3AQfd_rZ7507iuJkHPA@mail.gmail.com> <b8b29eaa-31ad-8f9e-00a9-b0cb8c599b39@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