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 1pE7Og-00080a-KF for pgsql-general@arkaria.postgresql.org; Sat, 07 Jan 2023 11:29:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pE7Oe-0001UJ-2N for pgsql-general@arkaria.postgresql.org; Sat, 07 Jan 2023 11:29:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pE7Od-0001TS-N0 for pgsql-general@lists.postgresql.org; Sat, 07 Jan 2023 11:29:55 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pE7OX-00040S-Ra for pgsql-general@lists.postgresql.org; Sat, 07 Jan 2023 11:29:53 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 6FEC9BED7; Sat, 7 Jan 2023 12:29:46 +0100 (CET) Date: Sat, 7 Jan 2023 12:29:46 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Purging few months old data and vacuuming in production Message-ID: <20230107112946.pamp3ot44sa7aylk@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <6f623e3a-d93d-bc89-b553-d2f87a82bd73@gmail.com> <1984ec34-26fa-a585-3312-ef38814b5f42@gmail.com> <90262fac-d6c7-e253-6988-a081c9e47a15@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="dsu5qfuq67ei3rno" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --dsu5qfuq67ei3rno Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-01-07 05:33:33 +0000, Ranjith Paliyath wrote: >=20 > > 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?=20 >=20 > > I don't know if you have ON DELETE CASCADE.=A0 Even if you do, > > you'll have to manually delete the tables not linked by FK.=A0 > > 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.=20 >=20 > 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 --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --dsu5qfuq67ei3rno Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmO5V6UACgkQ8g5IURL+ KF0Q5A//TszEkgJTBXaYhC7wqB21T5CcTLXL76WXEh3nPwg7+coiIng+Bc9GcSVr 9yMCi9XL6Y27dMJY4pfSfrKkEjXny7fL6VC8D56/5f0wOg1Rfn5+dZP4GTQbVI75 ePjEjhNfJOTga9nEPDbgnemc1jS062zNnM7sEBisb6Dh47Xd9IfqEAYgljJQZx8a ka50ywwL8a04WTsLjfHR0mUPX5xcjotB5M37C+xO/mnajHq8tA3xlcCJEa5FJM3U LWbU9BCXFCl7dyjgp6btVsOgEspIO5CBYWoTc77B9igo8968i6XEuu6SKtAdi2sr CDT3Y5r7Zdc5iTCEl0ded8iEF/LvlDhcPjTRh06p3PSHVhfpcENHiVWl85Jb62ua Cp3cp+cUhBMyL7lHQDATi4x5TC0LFANMgWoTOlg79dmwBLk2RV1uhsoCBg4dO84w mgNvO0wwxs44UZMSH5Fox+scB9g/qb13z9l7Wf8dbi/ESxRMe/LebBuQEw9hXOMx xc7y6QsyDKsh7lasdTwUlI0bXHmZm4i5GoUdBaPhro6jMRnCjC3C0Jc/6UhMe8To YjGP6XTynh+pVHzXw4d/ghyzQEslNye+Z5whUYwkkgcShZANdX7OJLfNLo54xB1Q GL0nWfC1LrRuJbzNrBQkMth7dMJ4QhD3joLEIpbyhqu4RrKbIsI= =BJG4 -----END PGP SIGNATURE----- --dsu5qfuq67ei3rno--