Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hETil-0003lm-Lw for pgsql-general@arkaria.postgresql.org; Thu, 11 Apr 2019 07:02:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hETik-0002fD-CR for pgsql-general@arkaria.postgresql.org; Thu, 11 Apr 2019 07:02:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hETij-0002f6-W8 for pgsql-general@lists.postgresql.org; Thu, 11 Apr 2019 07:02:02 +0000 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hETic-0004uq-U3 for pgsql-general@lists.postgresql.org; Thu, 11 Apr 2019 07:02:01 +0000 Received: by mail-oi1-x241.google.com with SMTP id v84so4026866oif.4 for ; Thu, 11 Apr 2019 00:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=aAzn4WZy3z6h9NA8f1h7vjch7bH9dV6LYbD5++Ydas8=; b=Vncy0H6TiPwZrmLzbJgk6J7TjongrFDLgQJnZZ0jYOqP/OS5S3MVbhsQBuTWkzXgZB 2PQtjCiVBjAL3s2dXjMxeGcLsNGq1jj/pIcWDcWdqzjR2GyqHA4fKuL+7jkBjPRUREnZ +hW/YNkyTZ5M6V2dO8/oEZJjaFgW86tBpKUlHgGgnfcmCr3uVCTJdjlmWugq2w+AKTWZ TI5Gr0x4iPz/nLq+YO6RAeSJe5LAaTKGgdbjRm75cI4Ff1CC0cVoYQM5lQ7f8xqUAOv2 9gWt81UgR12R05Yo569icwyeOYIchhidgA5cqt5YXfbj2IrG3a4jtn/Xe1y4nz2buzki Thzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=aAzn4WZy3z6h9NA8f1h7vjch7bH9dV6LYbD5++Ydas8=; b=t91w6D4tdSySqQHD8HSMeQaaMgCBTjJarmZ74ZhST/ID3VGjwOeZGIo3IjN2iq6tkV At0Tea3B/lqHMdR+A4e5CXI0D1GzGoTcApuRLt1k9ptzeirlciAWbh7497YGUPmhllWo EMTsmqBUHgprh6BI/acOTdbBeKlzsv5YtBD5oz/xUwjm7vWxt7tL5Sk+vXVP+cWiPIUP A5dx0StLKZNW2GkogvHc2jgeHrs3HxnP7jwSXeDBn3nurEZvGZiDl0TG+pKpPRtFXiIk ikxBE/cen0sMkp+A90QBG57N0+BTe2tpDBew+J7L8UQcWtb4Okck2R27Wj8twfFnLz+4 0b/Q== X-Gm-Message-State: APjAAAVUuh4g/uo42g8/NT54nUcx77SHA14D4FRt0wD0hesfOdpiKt9z xwHy/smCW5jab37e8L/KQElBhxoNaNc= X-Google-Smtp-Source: APXvYqxRs6FoFhgM+0pDzb+2YwadIop9iaxNNTODPF1pNnxhP9sUjTdkORBiW3Q0H2zJjsCYwMeomw== X-Received: by 2002:aca:d8c5:: with SMTP id p188mr4816454oig.144.1554966112690; Thu, 11 Apr 2019 00:01:52 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id b140sm16102265oih.57.2019.04.11.00.01.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 00:01:51 -0700 (PDT) Subject: Re: Recommendation to run vacuum FULL in parallel To: pgsql-general@lists.postgresql.org References: <9ed59ae2-6eb1-549d-eb05-d1546fd11515@mail.ru> From: Ron Message-ID: Date: Thu, 11 Apr 2019 02:01:50 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------00882743846E1820C50FF4B9" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------00882743846E1820C50FF4B9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Look also at pg_stat_all_tables.n_dead_tup for tables which are candidates for vacuuming. On 4/10/19 11:49 PM, Perumal Raj wrote: > Thanks Kevin for the inputs, > > In my Case there are 500+ Tables and biggest chunk 30GB ( Table only) + > its indexes. > So i have created 6 batches and executed in parallel . All my scripts > completed in 2 Hours and my DB size came down from 500GB to 300GB. > > Yes i do see CPU spike, But i did whole activity with full apps down time. > > Going forward i am going to run vacuum daily basis to maintain the DB size. > > Also Table/DB Age came down drastically. > > Thanks > Raj > > On Thu, Apr 4, 2019 at 12:53 PM Kevin Brannen > wrote: > > *From:* Perumal Raj > > > ** > > So conclude the requirement here , The only way to parallelism is > multiple script. And no need to do REINDEX exclusively. > > Question : Do we need to consider  Table dependencies while preparing > script in order to avoid table locks during vacuum full ? > > We have a small bash script (see below) that get the list of tables > and their sizes, sorted smallest to largest, and do “vacuum full” one > at a time because (as someone else pointed out) this is very I/O > intensive. That order also helps to ensure we finish because some of > our installs are at the edge of running out of space (an issue we’re > dealing with). I probably wouldn’t have a problem doing 2 at a time, > but we do this in the middle of the night when activity is lowest and > it only takes 1-2 hours, so we’re good with it. It sounds like you > have a lot more data though. > > You might also consider putting the data into different tablespaces > which are spread over multiple disks to help I/O. If you can, use SSD > drives, they help with speed quite a bit. 😊 > > Don’t worry about table dependencies. This is a physical operation, > not a data operation. > > HTH, > > Kevin > >     $PGPATH/psql -t -c " > >         WITH s AS (SELECT nspname || '.' || relname AS TABLE_NAME, > pg_total_relation_size(c.oid) AS total_bytes > >                   FROM pg_class c > >                   LEFT JOIN pg_namespace n ON n.oid = c.relnamespace > >                   WHERE relkind = 'r' AND nspname NOT IN ( > 'pg_catalog', 'information_schema' ) > >                   ORDER BY 2 ) > >         SELECT table_name FROM s > >         " | > >     while read t ; do echo "" ; echo $t; $PGPATH/vacuumdb -w -z -f -t > $t ; done > > ### > > This e-mail transmission, and any documents, files or previous e-mail > messages attached to it, may contain confidential information. If you > are not the intended recipient, or a person responsible for delivering > it to the intended recipient, you are hereby notified that any > disclosure, distribution, review, copy or use of any of the > information contained in or attached to this message is STRICTLY > PROHIBITED. If you have received this transmission in error, please > immediately notify us by reply e-mail, and destroy the original > transmission and its attachments without reading them or saving them > to disk. Thank you. > -- Angular momentum makes the world go 'round. --------------00882743846E1820C50FF4B9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Look also at pg_stat_all_tables.n_dead_tup for tables which are candidates for vacuuming.

On 4/10/19 11:49 PM, Perumal Raj wrote:
Thanks Kevin for the inputs,

In my Case there are 500+ Tables and biggest chunk 30GB ( Table only) + its indexes.
So i have created 6 batches and executed in parallel . All my scripts completed in 2 Hours and my DB size came down from 500GB to 300GB.

Yes i do see CPU spike, But i did whole activity with full apps down time.

Going forward i am going to run vacuum daily basis to maintain the DB size.

Also Table/DB Age came down drastically.

Thanks
Raj

On Thu, Apr 4, 2019 at 12:53 PM Kevin Brannen <KBrannen@efji.com> wrote:

From: Perumal Raj <perucinci@gmail.com>

So conclude the requirement here , The only way to parallelism is multiple script. And no need to do REINDEX exclusively.

Question : Do we need to consider  Table dependencies while preparing script in order to avoid table locks during vacuum full ?

 

We have a small bash script (see below) that get the list of tables and their sizes, sorted smallest to largest, and do “vacuum full” one at a time because (as someone else pointed out) this is very I/O intensive. That order also helps to ensure we finish because some of our installs are at the edge of running out of space (an issue we’re dealing with). I probably wouldn’t have a problem doing 2 at a time, but we do this in the middle of the night when activity is lowest and it only takes 1-2 hours, so we’re good with it. It sounds like you have a lot more data though.

 

You might also consider putting the data into different tablespaces which are spread over multiple disks to help I/O. If you can, use SSD drives, they help with speed quite a bit. 😊

 

Don’t worry about table dependencies. This is a physical operation, not a data operation.

 

HTH,

Kevin

 

    $PGPATH/psql -t -c "

        WITH s AS (SELECT nspname || '.' || relname AS TABLE_NAME, pg_total_relation_size(c.oid) AS total_bytes

                  FROM pg_class c

                  LEFT JOIN pg_namespace n ON n.oid = c.relnamespace

                  WHERE relkind = 'r' AND nspname NOT IN ( 'pg_catalog', 'information_schema' )

                  ORDER BY 2 )

        SELECT table_name FROM s

        " |

    while read t ; do echo "" ; echo $t; $PGPATH/vacuumdb -w -z -f -t $t ; done

###

This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain confidential information. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, distribution, review, copy or use of any of the information contained in or attached to this message is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify us by reply e-mail, and destroy the original transmission and its attachments without reading them or saving them to disk. Thank you.

--
Angular momentum makes the world go 'round.
--------------00882743846E1820C50FF4B9--