Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJtXa-0004ee-Jk for pgsql-general@arkaria.postgresql.org; Wed, 29 Nov 2017 04:00:06 +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 1eJtXZ-0004vA-Nr for pgsql-general@arkaria.postgresql.org; Wed, 29 Nov 2017 04:00:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJtXZ-0004ut-G3 for pgsql-general@lists.postgresql.org; Wed, 29 Nov 2017 04:00:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eJtXR-0003hs-Ht for pgsql-general@postgresql.org; Wed, 29 Nov 2017 04:00:04 +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 vAT3xp1a026624; Tue, 28 Nov 2017 22:59:51 -0500 From: Tom Lane To: Brian Crowell cc: Tomas Vondra , Ted Toth , pgsql-general Subject: Re: large numbers of inserts out of memory strategy In-reply-to: References: <87d5d3c9-66e4-c29d-bece-79f2909cccb9@2ndquadrant.com> <8431416a-2ab2-d580-19bd-2c7e3353960d@2ndquadrant.com> Comments: In-reply-to Brian Crowell message dated "Tue, 28 Nov 2017 21:16:51 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26622.1511927991.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 28 Nov 2017 22:59:51 -0500 Message-ID: <26623.1511927991@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Brian Crowell writes: > On Tue, Nov 28, 2017 at 12:38 PM, Tomas Vondra > wrote: >> So what does the script actually do? Because psql certainly is not >> running pl/pgsql procedures on it's own. We need to understand why >> you're getting OOM in the first place - just inserts alone should not >> cause failures like that. Please show us more detailed explanation of >> what the load actually does, so that we can try reproducing it. > Perhaps the script is one giant insert statement? It's pretty clear from the memory map that the big space consumption is inside a single invocation of a plpgsql function: SPI Proc: 2464408024 total in 279 blocks; 1672 free (1 chunks); 246440= 6352 used PL/pgSQL function context: 537911352 total in 74 blocks; 2387536 fre= e (4 chunks); 535523816 used So whatever's going on here, there's more to it than a giant client-issued INSERT (or COPY), or for that matter a large number of small ones. What would seem to be required is a many-megabyte-sized plpgsql function body or DO block. Actually, the truly weird thing about that map is that the "PL/pgSQL function context" seems to be a child of a "SPI Proc" context, whereas it's entirely clear from the code that it ought to be a direct child of TopMemoryContext. I have no idea how this state of affairs came to be, and am interested to find out. regards, tom lane