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 1nflhA-00067i-8b for pgsql-general@arkaria.postgresql.org; Sat, 16 Apr 2022 16:54:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nflh7-0003mO-O7 for pgsql-general@arkaria.postgresql.org; Sat, 16 Apr 2022 16:54:45 +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 1nflh7-0003ht-1k for pgsql-general@lists.postgresql.org; Sat, 16 Apr 2022 16:54:45 +0000 Received: from crocodile.elm.relay.mailchannels.net ([23.83.212.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nflgz-0001jj-NW for pgsql-general@postgresql.org; Sat, 16 Apr 2022 16:54:43 +0000 X-Sender-Id: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id F396B121507 for ; Sat, 16 Apr 2022 16:54:35 +0000 (UTC) Received: from mi3-ss4.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 49A2A1216EF for ; Sat, 16 Apr 2022 16:54:35 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1650128075; a=rsa-sha256; cv=none; b=0k2tqmgafPzL5JLtcJ/aHP47rR1JhSIvCVp2QGafPFbZ0rxWcJNOni87dbkYzp0rMUj7L6 LvxyglblB+SRjiivHWPC6oU5JD9OUp4sqtvjp+gaxr3PcOFaYdp/rLoI6Reaefb6n12xMq OxDQIf5zdTeRgQrOwu8izujnLGX57zmaKmX6khrTvggYjSyVrR6uCAhQjET408Xuw0epHK fi+BFAUAAvxoAbOJlQodWZhguiibOmhiIKrj+nqQRYkRZOfxOc4PtbNagJuKJrvn7PBMyf PM1QXowQq+kj6vRq4aE3mb2CPRLAYRMbGs/JC0dlNnHMRkWKxNhLQJOojPDryQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1650128075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OYw+/3xfRUyFJaQIv4CKizEpXiQ4RCrXfLM1fslbLbU=; b=LSCSKfEEqk1BiEQH+gbOOU23nGPniAN6skl6cujDJkNPRZy3APfyK5ra1r7Yx3Bxdloz+W CXl2Xqq70LARJ5YE2HSdPBB9sKH0fZfdSsisgg4a3T46ckDhfMqEl8FMJk66bnF7lDyaEq unAovZejs/bPDf/e7O6946rwkMCVTILjih7bhMauEvXKLhBlvLZUUVYpHq8C0Rqrnmu9Cv 4djNhI41vYyqxELj8W2Yp1piyqsTqjQgJh1lsxSNtNwRN9rw5iOYQuUVUds/0Co8dpEhM1 MqPkGyrVZeOjMhdIoOSF2ZQ9MSYo6v2VujjYUa6weTkYNM5nw79YllRp6OGRVg== ARC-Authentication-Results: i=1; rspamd-5f678fb567-56lp6; auth=pass smtp.auth=a2hosting smtp.mailfrom=pedz@easesoftware.com X-Sender-Id: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com Received: from mi3-ss4.a2hosting.com (mi3-ss4.a2hosting.com [68.66.200.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.112.55.197 (trex/6.7.1); Sat, 16 Apr 2022 16:54:35 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com X-MailChannels-Auth-Id: a2hosting X-Squirrel-Arithmetic: 411d8aa44bfd3b1f_1650128075704_229047434 X-MC-Loop-Signature: 1650128075704:3362942919 X-MC-Ingress-Time: 1650128075703 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=easesoftware.com; s=default; h=Message-Id:In-Reply-To:To:References:Date: Subject:Mime-Version:Content-Type:From:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OYw+/3xfRUyFJaQIv4CKizEpXiQ4RCrXfLM1fslbLbU=; b=gcji+nv+WOB0vl52USCDuQTncM bPVYlxKZpz8iRWp2kQzPfIVKn//bXdwL08tscA0KRir+U6yF29iDxdGKZu+O783oIwdWxPRhoLer6 KDiPr3UFsgqzZxAoKRJ70Z5RJQ1ONzk+ga/fj1QHIpFVKqF/wy6AyB8bngTnVWPNjCjz+neKd2/Tl RXlsmqyeCu0YJMCV568fGTAelF9HRyN1RYDL2az/9p1YlBtv5ok6je/DWIE1d+C2kjF2oYXBXcDOG 0NP1GAGORUmzBVsJsjg6er7QjoBOyQVI6HT0Jso9+TDBufTZ6y5t9XemVxW6bqHWnwBZ8jgZCBHCs CI/b8m3w==; Received: from cpe-70-94-128-193.satx.res.rr.com ([70.94.128.193]:55466 helo=smtpclient.apple) by mi3-ss4.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nflgv-0007kQ-BL for pgsql-general@postgresql.org; Sat, 16 Apr 2022 12:54:33 -0400 From: Perry Smith Content-Type: multipart/signed; boundary="Apple-Mail=_6C7E7FBA-A193-4F7E-BA9C-EBF583F7D734"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: ***SPAM*** Re: Help with large delete Date: Sat, 16 Apr 2022 11:54:32 -0500 References: <3823FD54-2910-41E5-B908-869DA917DE82@easesoftware.com> <1939729.1650123237@sss.pgh.pa.us> To: "pgsql-general@postgresql.org" In-Reply-To: <1939729.1650123237@sss.pgh.pa.us> Message-Id: X-Mailer: Apple Mail (2.3696.80.82.1.1) X-AuthUser: pedz+easesoftware.com@mi3-ss4.a2hosting.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_6C7E7FBA-A193-4F7E-BA9C-EBF583F7D734 Content-Type: multipart/alternative; boundary="Apple-Mail=_75BF01DE-AA2F-4BB2-B91B-127B34E683D3" --Apple-Mail=_75BF01DE-AA2F-4BB2-B91B-127B34E683D3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Apr 16, 2022, at 10:33, Tom Lane wrote: >=20 > 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 = descendants. The table currently has about 22M entries and I=E2=80=99m = adding about 1600 entries per minute still. Eventually there will not = be massive amounts of entries being added and the table will be mostly = static. >=20 > 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. To try to reply to Peter=E2=80=99s question, I just now started: psql -c "explain analyze delete from dateien where basename =3D = '/mnt/pedz/Visual_Media'=E2=80=9D find_dups And it hasn=E2=80=99t replied yet. I hope you are not slapping your = head muttering =E2=80=9Cthis guy is an idiot!!=E2=80=9D =E2=80=94 in = that this would not give you the plan you are asking for... This is inside a BSD =E2=80=9Cjail=E2=80=9D on a NAS. I=E2=80=99m = wondering if the jail has a limited time and the other processes have = consumed it all. In any case, if / when it replies, I will post the = results. For Tom=E2=80=99s question, here is the description of the table: psql -c '\d dateien' find_dups Table "public.dateien" Column | Type | Collation | Nullable | = Default = ------------+--------------------------------+-----------+----------+-----= -------------------------------- id | bigint | | not null | = nextval('dateien_id_seq'::regclass) basename | character varying | | not null | parent_id | bigint | | | dev | bigint | | not null | ftype | character varying | | not null | uid | bigint | | not null | gid | bigint | | not null | ino | bigint | | not null | mode | bigint | | not null | mtime | timestamp without time zone | | not null | nlink | bigint | | not null | size | bigint | | not null | sha1 | character varying | | | created_at | timestamp(6) without time zone | | not null | updated_at | timestamp(6) without time zone | | not null | Indexes: "dateien_pkey" PRIMARY KEY, btree (id) "unique_dev_ino_for_dirs" UNIQUE, btree (dev, ino) WHERE ftype::text = =3D 'directory'::text "unique_parent_basename" UNIQUE, btree (COALESCE(parent_id, = '-1'::integer::bigint), basename) Foreign-key constraints: "fk_rails_c01ebbd0bf" FOREIGN KEY (parent_id) REFERENCES dateien(id) = ON DELETE CASCADE Referenced by: TABLE "dateien" CONSTRAINT "fk_rails_c01ebbd0bf" FOREIGN KEY = (parent_id) REFERENCES dateien(id) ON DELETE CASCADE --Apple-Mail=_75BF01DE-AA2F-4BB2-B91B-127B34E683D3 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Apr 16, 2022, at 10:33, Tom Lane <tgl@sss.pgh.pa.us> = wrote:

Perry Smith <pedz@easesoftware.com> 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 descendants.  The table currently has = about 22M entries and I=E2=80=99m adding about 1600 entries per minute = still.  Eventually there will not be massive amounts 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.

To try to = reply to Peter=E2=80=99s question, I just now started:

psql -c "explain analyze delete from dateien where = basename =3D '/mnt/pedz/Visual_Media'=E2=80=9D find_dups

And it hasn=E2=80=99t replied yet.  I hope = you are not slapping your head muttering =E2=80=9Cthis guy is an = idiot!!=E2=80=9D =E2=80=94 in that this would not give you the plan you = are asking for...

This is inside a = BSD =E2=80=9Cjail=E2=80=9D on a NAS.  I=E2=80=99m wondering if the = jail has a limited time and the other processes have consumed it all. =  In any case, if / when it replies, I will post the = results.

For Tom=E2=80=99s question, = here is the description of the table:

psql -c '\d dateien' = find_dups 
            =                     =           Table "public.dateien"
   Column   |      =         Type          =     | Collation | Nullable |       =         Default        =        
------------+--------------------------------+-----------+-----= -----+-------------------------------------
 id         | = bigint                 =         |         =   | not null | nextval('dateien_id_seq'::regclass)
 basename   | character varying  =             |     =       | not null | 
 parent_id  | bigint       =                 =   |           |  =         | 
 dev  =       | bigint         =               =   |           | not null = | 
 ftype      | character = varying            =   |           | not null = | 
 uid        | = bigint                 =         |         =   | not null | 
 gid    =     | bigint           =               |   =         | not null | 
 ino        | = bigint                 =         |         =   | not null | 
 mode   =     | bigint           =               |   =         | not null | 
 mtime      | timestamp without time = zone    |           | = not null | 
 nlink      | = bigint                 =         |         =   | not null | 
 size   =     | bigint           =               |   =         | not null | 
 sha1       | character = varying            =   |           |  =         | 
 created_at = | timestamp(6) without time zone |         =   | not null | 
 updated_at | = timestamp(6) without time zone |         =   | not null | 
Indexes:
 =   "dateien_pkey" PRIMARY KEY, btree (id)
  =   "unique_dev_ino_for_dirs" UNIQUE, btree (dev, ino) WHERE = ftype::text =3D 'directory'::text
  =   "unique_parent_basename" UNIQUE, btree (COALESCE(parent_id, = '-1'::integer::bigint), basename)
Foreign-key = constraints:
    "fk_rails_c01ebbd0bf" = FOREIGN KEY (parent_id) REFERENCES dateien(id) ON DELETE CASCADE
Referenced by:
    TABLE = "dateien" CONSTRAINT "fk_rails_c01ebbd0bf" FOREIGN KEY (parent_id) = REFERENCES dateien(id) ON DELETE CASCADE


= --Apple-Mail=_75BF01DE-AA2F-4BB2-B91B-127B34E683D3-- --Apple-Mail=_6C7E7FBA-A193-4F7E-BA9C-EBF583F7D734 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE5yOa/gCtQpb3oCpljxzk9yzE+MAFAmJa9MgACgkQjxzk9yzE +MDvPw/+NnuEU3epFhejKEerSe2f+HjHhc7qLwvtZZJ1cywbIWZBzEiG60LiMndJ Di6bFaadUAZ7GIKpNerzaV3AGzri9egSkxrBwoDNZfffhYTpIpnDpm0CGQ+jpJEX geyOxQX4uMiAyVLvdNOaYIa8JKfD/x/Glm7HARAbQ03YstsC/LE34SoNJ0XJOJgf aGWHDpHECOLeNnW58DrONSakHjzjsujG+xQyfe8oKgUJnt69dn13jXBm9O9wKuqc czGn2dZmhXkS5WCa6CWghFHDCf8458Jv1f5JNMuMYn++cU7BI/FET+1s0dl+0GM3 mHqtHlKC7TSLmCEeXamPb08nqZZb0OOe5PtYlF8GPivGX1Ufni3h4XBrMzqPd1u/ USpFZW1Ez7Fa/UEFdh2PgpMqAqnNUCRL9RTZ07OZyspcAUaW8GVReTWD46cs1yNg 4h74TwLv7VHcxWqp8H/Zh0qjLSVFoqbc6sNrvCW3DK8BAFgwFYJ/2WnkWHrLvn49 QDcndoo2c4/IqCbmXytmP3NFyU/ZFoi7DhtDx+VI22zJms4W1X6pddX3EPdkucVn 7pc452nFwuoEKe8/ZLJ8tC3eZUy21dY2Zu+4Nx1oyI32PIlkIKO6qKFKzuDAihTk v+2s0h6VqglsIR6dcFlvqDu2DR7HysUIma0QpzDG/dLrs+0guSk= =f4Qu -----END PGP SIGNATURE----- --Apple-Mail=_6C7E7FBA-A193-4F7E-BA9C-EBF583F7D734--