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 1kkqqp-00018y-CM for pgsql-admin@arkaria.postgresql.org; Thu, 03 Dec 2020 15:48:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkqqo-0001hC-CQ for pgsql-admin@arkaria.postgresql.org; Thu, 03 Dec 2020 15:48:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkqqo-0001gu-2m for pgsql-admin@lists.postgresql.org; Thu, 03 Dec 2020 15:48:58 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kkqqh-0007hm-Nn for pgsql-admin@lists.postgresql.org; Thu, 03 Dec 2020 15:48:57 +0000 Received: by mail-ot1-x330.google.com with SMTP id b62so2151368otc.5 for ; Thu, 03 Dec 2020 07:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=IZf9jDO9J6cvDAmkdTGr4FXWN7+WpszyY0f41NpM0BU=; b=kxXupvcnsIFtPGbi2/MN5JC7JPnbmU2+0c7kJPdCdmVTNbWpkvOJHbpyrU255gF590 tqWFnKt2UG7rnoXCvj6kHOwXz+Ff3MdSLZgrOJtkvnR+UEUVMlQPFiHJI8t7Pkna8Ddg 1ivb7/EbMAsmezCNa4NyJzlT9B7r3fV7/uqfEQKPgm1G95UJjuCp0RMmajRBMSaAk90k yWMhl9nzHZK0QPzqdo53PPZWbDVKX/schczNPVZblCpO/Ip8RPgkp+oLNconiJKgiHbW EsKJ9aNYljZHdvBU/YB6C7Yb3Somc+pFz6IAeOzA/LJ25iUCdbV8KR+YWWXkJ+tbXOdT rkUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=IZf9jDO9J6cvDAmkdTGr4FXWN7+WpszyY0f41NpM0BU=; b=nz+e+EW8bw8cHOvSC8wkeDfgShvbaApD8M+PW1R1X5sJjSDd6iE2SwpvOsyu7OWo9B okFjhJasL/MWG8mI4JtdDWBYtqlJJA4Oicex5NhQf/pKf2BwrPr2L2XGIlxDEOgRJ05b Wdbm2PrHo3Lu1pjlMoxrpTuDDBdyEQouLZuRAivECC/C2LSytMsjC3I5H7v/1Ew8KZso w9dqFtvoUHj0pb4waKEe2Adq/C/untIlDGr2cYRSH0t6+qyErwXnvVd6ZKNGtR9kKhBw hWiSvK7vTIB9A2bbE3Ten3Tz7emBM2SaaVmVcdZG26nbVOss+q81HjZp3RK7Hrcj51ct x66Q== X-Gm-Message-State: AOAM531F9NW1eoqzYKRX/2i7jKZN9sG2aPJN2P98bGNytlxyqSzxnBna lu+PV/EFxDSDiXVSQFa1SuJHdUuSNbrL8g== X-Google-Smtp-Source: ABdhPJwlIZPiY+b06EFTt9g0bRMrhZ46iUiOo9f3FdPlkvsGjL+jFtgbvbSO9q5ncM64M/EXBFhVmw== X-Received: by 2002:a05:6830:1411:: with SMTP id v17mr2463326otp.209.1607010528235; Thu, 03 Dec 2020 07:48:48 -0800 (PST) Received: from [192.168.1.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id a25sm285566oos.23.2020.12.03.07.48.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2020 07:48:47 -0800 (PST) Subject: Re: time taking deletion on large tables To: pgsql-admin@lists.postgresql.org References: From: Ron Message-ID: <5f37b65c-4b3a-9f5f-85fb-2fc3c7a6f530@gmail.com> Date: Thu, 3 Dec 2020 09:48:46 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/3/20 8:45 AM, Atul Kumar wrote: > Hi, > > The feed_posts table has over 50 Million rows. > > When I m deleting all rows of a certain type that are over 60 days old. > > When I try to do a delete like this: it hangs for an entire day, so I > need to kill it with pg_terminate_backend(pid). > > DELETE FROM feed_posts > WHERE feed_definition_id = 'bf33573d-936e-4e55-8607-72b685d2cbae' > AND created_at > '2020-05-11 00:00:00' > AND created_at < '2020-05-12 00:00:00'; > > So– I need help in figuring out how to do large deletes on a > production database during normal hours. Presumably there is an index on created_at? What about feed_definition_id? > explain plan is given below > > > > "Delete on feed_posts (cost=1156.57..195748.88 rows=15534 width=6)" > " -> Bitmap Heap Scan on feed_posts (cost=1156.57..195748.88 > rows=15534 width=6)" > " Recheck Cond: ((created_at >= '2020-05-11 00:00:00'::timestamp > without time zone) AND (created_at <= '2020-05-12 00:00:00'::timestamp > without time zone))" > " Filter: (feed_definition_id = 'bf33573d-936e-4e55-8607-72b685d2cbae'::uuid)" > " -> Bitmap Index Scan on feed_posts_created_at (cost=0.00..1152.68 > rows=54812 width=0)" > " Index Cond: ((created_at >= '2020-05-11 00:00:00'::timestamp without > time zone) AND (created_at <= '2020-05-12 00:00:00'::timestamp without > time zone))" Have you recently analyzed the table? -- Angular momentum makes the world go 'round.