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 1jaLPO-0007vP-E3 for pgsql-bugs@arkaria.postgresql.org; Sun, 17 May 2020 15:40: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 1jaLPN-0007OS-3X for pgsql-bugs@arkaria.postgresql.org; Sun, 17 May 2020 15:40:57 +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 1jaLPM-0007Nb-TW for pgsql-bugs@lists.postgresql.org; Sun, 17 May 2020 15:40:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaLPK-0008Bs-Lv for pgsql-bugs@lists.postgresql.org; Sun, 17 May 2020 15:40:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 04HFerHq001361; Sun, 17 May 2020 11:40:53 -0400 From: Tom Lane To: kurt@roeckx.be cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16443: Too much memory usage on insert query In-reply-to: <16443-030629aae2859708@postgresql.org> References: <16443-030629aae2859708@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 17 May 2020 14:42:09 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1359.1589730053.1@sss.pgh.pa.us> Date: Sun, 17 May 2020 11:40:53 -0400 Message-ID: <1360.1589730053@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > I was executing this query: > insert into ct_entry_chain (ct_entry_id, certificate_id) select id, > unnest(certificate_chain_id) from ct_entry; How much data is that? > The process was using at least 14 GB, of the 8 GB of RAM that's available. My first guess is that the space was being eaten by trigger list entries to verify the foreign-key constraints on the target table. You might be better advised to fill the new table first and then create its FK constraints. (Building the indexes afterwards wouldn't be a bad idea, either.) We are looking at better mechanisms for handling FK verification, but that won't see the light of day before v14 at the earliest. regards, tom lane