Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMGaS-00079V-FR for pgsql-performance@arkaria.postgresql.org; Tue, 05 Dec 2017 17:00:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMGaR-00014A-Qg for pgsql-performance@arkaria.postgresql.org; Tue, 05 Dec 2017 17:00:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMGaR-00013z-Eb for pgsql-performance@lists.postgresql.org; Tue, 05 Dec 2017 17:00:51 +0000 Received: from mail-qt0-x231.google.com ([2607:f8b0:400d:c0d::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eMGaN-0005ws-SK for pgsql-performance@lists.postgresql.org; Tue, 05 Dec 2017 17:00:49 +0000 Received: by mail-qt0-x231.google.com with SMTP id e2so2391539qti.0 for ; Tue, 05 Dec 2017 09:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=bu4cUHGIKATjLxHxqJ0Qq8r3QHaC+Px1zjVqrWYRkdY=; b=g0ssFvwwOVXEKYnSFAD5ZyWLprxZRtGY5gcUz+ORDzAkEpwFyky6OLf5ARSWwnFT+p l+Z1Vfmqp8w8nX/Ycu/B5k7MdaV9UV38WJTNF4jCIQQ6E5UrgReiSWNtFoRg7EI9FeAh O6fxXce78Kq1rmyq+kPS3FwL7+k/MoVFu2wsqd7Lu/j7wy9bojafHwq4Qc3TE27QjA0F PQ8Mz7h9BTkxDTmN8ClgiNThkDkV2E2WQS3WmVvJCj5A23scHwuH2rLdgf3nCfLmhvvQ 1QbyPilWgOj8+hZF2slCcOX68dZ03pxyhwfk97v5jHQiptErnytICWtXs/f+5rA4lu26 FbFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=bu4cUHGIKATjLxHxqJ0Qq8r3QHaC+Px1zjVqrWYRkdY=; b=V1FrWf8EC4wfLbCr7gFzm2vGKBPdu1WlGVat4ttdplvOrqXaeL29IeqMspr0MJduB5 BuCpy7I2JHma94DBJGF0b7zl2Lo/RKTNSouJ01znGnFjQX/Gp1lzn6jDBDQtgspGfJxx K+PO6eBFs+JH2LcIvzmaoag8nF0PZckJEkQCN0zrvy9B+WGpIfpzZy71xRjpnh0E912B vSlgz5Bqb9CJUrBMRXtnSgRIIJzB6hKUtb789+MqcMWJ9k+fLIZf8MpkbS9tXjjTZLu8 xFOjDOpUxXrgZqdJGyZ8WhneVkadw387WVaBaayrjNkBT3jDuSg3ix5gdnrpv6A8N5Z2 54ZA== X-Gm-Message-State: AKGB3mJ/bgIQZDibnFcyLuWTTHgnxhXi06sA1M+sy1cbDLpt3+Gin0mP NTM8phvvMNLfe4nF2pAytafbwQ== X-Google-Smtp-Source: AGs4zMadx7hPGZOvtHjTxKC39/Yjvi9kzswtZyzPSUgivfn/jDgn/CAlxTPGiVktZmUSmaG7XyuLuA== X-Received: by 10.55.5.139 with SMTP id 133mr21487280qkf.220.1512493246541; Tue, 05 Dec 2017 09:00:46 -0800 (PST) Received: from [192.168.1.6] ([181.213.88.188]) by smtp.gmail.com with ESMTPSA id h32sm392286qtk.8.2017.12.05.09.00.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 09:00:45 -0800 (PST) Subject: Re: Extremely slow DELETE with cascade foreign keys To: Tom Lane Cc: pgsql-performance@lists.postgresql.org References: <8f569ed9-fde9-1fe7-4beb-01945009e040@gmail.com> <7973.1512491234@sss.pgh.pa.us> From: Rodrigo Rosenfeld Rosas Message-ID: <311dd1bb-1295-bf0d-eed7-55742a18484a@gmail.com> Date: Tue, 5 Dec 2017 15:00:41 -0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <7973.1512491234@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: pt-BR List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Em 05-12-2017 14:27, Tom Lane escreveu: > Rodrigo Rosenfeld Rosas writes: >> Hi, I think something changed recently in my development environment as >> I don't recall deletes being so slow before. >> I've created a new dump and restored to a new database, ran VACUUM FULL >> ANALYSE and a simple delete takes forever as you can see here: > The usual suspect for this is not having an index on some FK referencing > column, thus forcing the FK check trigger to seq-scan the entire > referencing table for each referenced row that is to be deleted. > > regards, tom lane Thanks, indeed that was the case. I manually inspected about a dozen tables referencing field_values and the last one ("references") was referenced by another table ("highlighted_texts") and the reference_id column that has a foreign key on "references"(id) was missing an index. Good job :) Best, Rodrigo.