Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJk7i-00047i-QD for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 17:56:46 +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 1eJk7i-0000sO-E6 for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 17:56:46 +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 1eJk7i-0000sE-72 for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 17:56:46 +0000 Received: from 23-25-19-49-static.hfc.comcastbusiness.net ([23.25.19.49] helo=jeeves.wrkhors.com) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eJk7d-0007ak-Vk for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 17:56:45 +0000 Received: from wrkhors.com (localhost [127.0.0.1]) by jeeves.wrkhors.com (Postfix) with ESMTP id D520710EDE8; Tue, 28 Nov 2017 11:56:37 -0600 (CST) Date: Tue, 28 Nov 2017 12:04:22 -0600 From: Steven Lembark To: pgsql-general@lists.postgresql.org Cc: lembark@wrkhors.com Subject: Re: large numbers of inserts out of memory strategy Message-ID: <20171128120422.73776fc9@wrkhors.com> In-Reply-To: References: Organization: Workhorse Computing MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 28 Nov 2017 11:17:07 -0600 Ted Toth wrote: > I'm writing a migration utility to move data from non-rdbms data > source to a postgres db. Currently I'm generating SQL INSERT > statements involving 6 related tables for each 'thing'. With 100k or > more 'things' to migrate I'm generating a lot of statements and when I > try to import using psql postgres fails with 'out of memory' when > running on a Linux VM with 4G of memory. If I break into smaller > chunks say ~50K statements then thde import succeeds. I can change my > migration utility to generate multiple files each with a limited > number of INSERTs to get around this issue but maybe there's > another/better way? Chunking the loads has a number of advantages other than avoiding OOM errors, not the least of which are possibly parallel loading and being able to restart after other failures without re-processing all of the input data. Note that 4GiB of core is not all that much by today's standards. You might want to run top/vmstat and ask if the PG daemons are using all/most of the available memory. If PG is sucking up all of the core as it is then tuning the database may not have much of an effect; if there is lots of spare memory then it'll be worth looking at ways to tune PG. Note also that "out of memory" frequently means virutal memory. Q: Does the VM have swap configured? If not then add 8GiB and see if that solves your problem; if so then how much swap is in use when you get the OOM error? -- Steven Lembark 1505 National Ave Workhorse Computing Rockford, IL 61103 lembark@wrkhors.com +1 888 359 3508