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 1nfkRg-0001bZ-Oe for pgsql-general@arkaria.postgresql.org; Sat, 16 Apr 2022 15:34:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nfkRd-0007ho-Sz for pgsql-general@arkaria.postgresql.org; Sat, 16 Apr 2022 15:34:41 +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 1nfkRd-0007hA-I1 for pgsql-general@lists.postgresql.org; Sat, 16 Apr 2022 15:34:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nfkRb-00015F-Ah for pgsql-general@postgresql.org; Sat, 16 Apr 2022 15:34:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 23GFXvIM1939730; Sat, 16 Apr 2022 11:33:57 -0400 From: Tom Lane To: Perry Smith cc: "pgsql-general@postgresql.org" Subject: Re: Help with large delete In-reply-to: <3823FD54-2910-41E5-B908-869DA917DE82@easesoftware.com> References: <3823FD54-2910-41E5-B908-869DA917DE82@easesoftware.com> Comments: In-reply-to Perry Smith message dated "Sat, 16 Apr 2022 08:25:56 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1939728.1650123237.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 16 Apr 2022 11:33:57 -0400 Message-ID: <1939729.1650123237@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Perry Smith writes: > Currently I have one table that mimics a file system. Each entry has a = parent_id and a base name where parent_id is an id in the table that must = exist in the table or be null with cascade on delete. > I=E2=80=99ve started a delete of a root entry with about 300,000 descend= ants. The table currently has about 22M entries and I=E2=80=99m adding ab= out 1600 entries per minute still. Eventually there will not be massive a= mounts of entries being added and the table will be mostly static. The most obvious question is do you have an index on the referencing column. PG doesn't require one to exist to create an FK; but if you don't, deletes of referenced rows had better be uninteresting to you performance-wise, because each one will cause a seqscan. regards, tom lane