From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Purging few months old data and vacuuming in production
Date: Sat, 7 Jan 2023 12:29:46 +0100
Message-ID: <20230107112946.pamp3ot44sa7aylk@hjp.at> (raw)
In-Reply-To: <SEZPR06MB56909FBE8EF32C717E40C210C2F89@SEZPR06MB5690.apcprd06.prod.outlook.com>
References: <SEZPR06MB569032257FDFACE5C906ADB4C2F09@SEZPR06MB5690.apcprd06.prod.outlook.com>
<6f623e3a-d93d-bc89-b553-d2f87a82bd73@gmail.com>
<SEZPR06MB56905EB1343165E6D1C8B5B4C2FB9@SEZPR06MB5690.apcprd06.prod.outlook.com>
<1984ec34-26fa-a585-3312-ef38814b5f42@gmail.com>
<SEZPR06MB5690F3A7AE31D9EA19DA0A28C2FB9@SEZPR06MB5690.apcprd06.prod.outlook.com>
<90262fac-d6c7-e253-6988-a081c9e47a15@gmail.com>
<SEZPR06MB56909FBE8EF32C717E40C210C2F89@SEZPR06MB5690.apcprd06.prod.outlook.com>
On 2023-01-07 05:33:33 +0000, Ranjith Paliyath wrote:
>
> > This is because the deletion step is executed record
> > by record in main table, with its connected record(s)
> > delete executions in rest of tables?
>
> > I don't know if you have ON DELETE CASCADE. Even if you do,
> > you'll have to manually delete the tables not linked by FK.
> > I'd write a PL/pgSQL procedure: pass in a PK and then delete
> > records from the 9 tables in the proper order so as to not
> > throw FK constraint errors.
>
> Ok, in the case of our specific 9 tables it would finding and deleting
> linked records in 8 tables based on the record chosen in the main
> table. That is going and deleting records one by one.
If I understood correctly, you have to delete about 3 million records
(worst case) from the main table each day. Including the other 8 tables
those are 27 million DELETE queries each of which deletes only a few
records. That's about 300 queries per second. I'd be worried about
impacting performance on other queries at this rate.
I'd go for a middle ground: Instead of expiring once per day, use a
shorter interval, maybe once per hour or once per minute. That will
(probably) make each expire job really quick but still create much less
load overall.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Attachments:
signature.asc (application/pgp-signature, 832B) download
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: hjp-pgsql@hjp.at
Subject: Re: Purging few months old data and vacuuming in production
In-Reply-To: <20230107112946.pamp3ot44sa7aylk@hjp.at>
References: <SEZPR06MB569032257FDFACE5C906ADB4C2F09@SEZPR06MB5690.apcprd06.prod.outlook.com> <6f623e3a-d93d-bc89-b553-d2f87a82bd73@gmail.com> <SEZPR06MB56905EB1343165E6D1C8B5B4C2FB9@SEZPR06MB5690.apcprd06.prod.outlook.com> <1984ec34-26fa-a585-3312-ef38814b5f42@gmail.com> <SEZPR06MB5690F3A7AE31D9EA19DA0A28C2FB9@SEZPR06MB5690.apcprd06.prod.outlook.com> <90262fac-d6c7-e253-6988-a081c9e47a15@gmail.com> <SEZPR06MB56909FBE8EF32C717E40C210C2F89@SEZPR06MB5690.apcprd06.prod.outlook.com> <20230107112946.pamp3ot44sa7aylk@hjp.at>
* 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