Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyKA6-00052p-3H for pgsql-admin@arkaria.postgresql.org; Sun, 14 May 2023 22:25:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pyKA4-0006Lt-LQ for pgsql-admin@arkaria.postgresql.org; Sun, 14 May 2023 22:25:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyKA4-0006Lj-9b for pgsql-admin@lists.postgresql.org; Sun, 14 May 2023 22:25:52 +0000 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pyK9x-002l9a-Jl for pgsql-admin@lists.postgresql.org; Sun, 14 May 2023 22:25:51 +0000 Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-b9a6eec8611so55215272276.0 for ; Sun, 14 May 2023 15:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684103144; x=1686695144; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=niFrqBVbPs4H/kfXfySuNu57SAj2GvgPSN2UabesIjE=; b=hd+AV/jaZjQsmWsqy41Dh8PwkbqnfyZr1z6z9tBfAhXMhOEWFszzTB7oN1Fxp+JyGd klXLtrjU1PqKALgrnKRM4E1hAUpnGIa+2Os4sVHH2NNGBODie30784q8xqLjDeaAsd6J nrawqXoHAR57AjXvhuNark6J+WcAri+oWpetJQRptiJr0OcsS8bJsNw3Ayps0aAvXpgz AoAz7QjFSvO0DTxBA3nWA188mXt3VyXWgZEVbAlelOCl9Y6eo45iMBylVXHHtCGmRO+3 +Rfh6ACAenqfmzx9+Se95A9ODaDrJSWgc+wkTvzVKoevsNm9DgPkQa11EiPANr5xbnvy m53Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684103144; x=1686695144; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=niFrqBVbPs4H/kfXfySuNu57SAj2GvgPSN2UabesIjE=; b=itsYlBGSvY7JJCmj6X/UBQk2Tma3dqTPmBZRjDcu8ev1mGizms64SACiff7bjdPPPL 4AID5igMiE0taOZcvTM8xPoqJR2V2m8TCOfkjB5dw+ZcuMBuVHNBZWeVQr7DUChnWKCQ /V/ZzTd9jhKqFBi32g4ns+zFGEYQYDgXVUCwQInCwX6jVqmqN6QHQKWuOYKmC20vSHVw DsFPvcq/LQ66NkapzEgjyGL4nVZLC0o4E6Ojh2yhO1z2gfZsvM6HUt42BWyvMZi7+m/c WwibNh6R4QairjUC8hHdoXcyzLhV0V3ve/ePAxeBq/0B4Mh+Ue4uI3jGryXZtZP9wmV2 ZJyQ== X-Gm-Message-State: AC+VfDwlR1f7UZhJmJnzZNE/mHdqc1jmxLRJmY09E7q8YHpxMPveKC3P LgEqoQjaUmDzOmG31HA2cTWjM0HDHuY= X-Google-Smtp-Source: ACHHUZ4M2mXpLgQX6ZrTafUrL9Crc2g2OtPUVQDEdPpLTPi84U6S5dMg3TLxVtiwh9BFP/RsPa2rGg== X-Received: by 2002:a25:c78d:0:b0:ba1:24a5:55ae with SMTP id w135-20020a25c78d000000b00ba124a555aemr30033340ybe.24.1684103143757; Sun, 14 May 2023 15:25:43 -0700 (PDT) Received: from ?IPV6:2600:1700:bd2c:b810:80f6:4741:9863:ef90? ([2600:1700:bd2c:b810:80f6:4741:9863:ef90]) by smtp.googlemail.com with ESMTPSA id x4-20020a056902102400b00b9def138173sm6514234ybt.1.2023.05.14.15.25.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 May 2023 15:25:43 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------aPmg39gAh4njc79ZuBDTR4BJ" Message-ID: Date: Sun, 14 May 2023 17:25:41 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: Options for more aggressive space reclamation in vacuuming? Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------aPmg39gAh4njc79ZuBDTR4BJ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit We regularly vacuum, and *definitely* vacuum after an archive-delete. On 5/14/23 16:02, Wells Oliver wrote: > I think our use-case here is nothing special: just very large tables that > are deleted from and re-inserted with some frequency. They store monthly > data and exist as partitions. As an example, July of 2022 (summer months > are peak) had 1,630,558,336 rows. We delete from this and insert daily. We > rarely get new, relevant data once the month is over. The n_dead_tup > from pg_stat_all_tables here was over 7m rows, and clearing that out gave > us back nearly 50GB, and the file size estimate on this partition was ~200 > GB. These tables get auto-vacuumed but clearly it's not, well, > aggressively reclaiming space. > > Given that they are partitions, VACUUM FULL locks the parent table, so new > writes/deletes can't happen, and anyway people like to run queries against > these tables quite frequently. > > Glad to add any detail I can. > > On Sun, May 14, 2023 at 11:32 AM Jeff Janes wrote: > > On Sun, May 14, 2023 at 1:46 PM Wells Oliver > wrote: > > Noticed over the last few days how much more space VACUUM FULL > reclaims (for obvious reasons) and I am wondering if there are any > solutions for a more fruitful VACUUM without the locks of FULL? > > > There are lots of theories which are all compatible with the minimal > amount of info given here.  If the space is freed from the indexes, > then just reindexing (which can be done concurrently in recent > versions) could reclaim the space. If it is from the table itself then > something like pg_squeeze > (https://github.com/cybertec-postgresql/pg_squeeze/) might help. Or > you can implement your own squeezing, by using a CTE with a ctid scan > to delete tuples from the end of the table and reinsert them in the > front, then use regular vacuum to truncate the now-free space off the > end of the table. > > I would think the more fruitful VACUUM would be to prevent the bloat > from occuring in the first place but without knowing the root cause I > can't offer anything but platitudes there. > > Cheers, > > Jeff > > > > -- > Wells Oliver > wells.oliver@gmail.com -- Born in Arizona, moved to Babylonia. --------------aPmg39gAh4njc79ZuBDTR4BJ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit We regularly vacuum, and definitely vacuum after an archive-delete.

On 5/14/23 16:02, Wells Oliver wrote:
I think our use-case here is nothing special: just very large tables that are deleted from and re-inserted with some frequency. They store monthly data and exist as partitions. As an example, July of 2022 (summer months are peak) had 1,630,558,336 rows. We delete from this and insert daily. We rarely get new, relevant data once the month is over. The n_dead_tup from pg_stat_all_tables here was over 7m rows, and clearing that out gave us back nearly 50GB, and the file size estimate on this partition was ~200 GB. These tables get auto-vacuumed but clearly it's not, well, aggressively reclaiming space.

Given that they are partitions, VACUUM FULL locks the parent table, so new writes/deletes can't happen, and anyway people like to run queries against these tables quite frequently.

Glad to add any detail I can.

On Sun, May 14, 2023 at 11:32 AM Jeff Janes <jeff.janes@gmail.com> wrote:
On Sun, May 14, 2023 at 1:46 PM Wells Oliver <wells.oliver@gmail.com> wrote:
Noticed over the last few days how much more space VACUUM FULL reclaims (for obvious reasons) and I am wondering if there are any solutions for a more fruitful VACUUM without the locks of FULL?

There are lots of theories which are all compatible with the minimal amount of info given here.  If the space is freed from the indexes, then just reindexing (which can be done concurrently in recent versions) could reclaim the space. If it is from the table itself then something like pg_squeeze (https://github.com/cybertec-postgresql/pg_squeeze/) might help. Or you can implement your own squeezing, by using a CTE with a ctid scan to delete tuples from the end of the table and reinsert them in the front, then use regular vacuum to truncate the now-free space off the end of the table.

I would think the more fruitful VACUUM would be to prevent the bloat from occuring in the first place but without knowing the root cause I can't offer anything but platitudes there.

Cheers,

Jeff


--

--
Born in Arizona, moved to Babylonia.
--------------aPmg39gAh4njc79ZuBDTR4BJ--