Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJkCH-0004at-63 for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 18:01:29 +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 1eJkCG-0005ad-9I for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 18:01:28 +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 1eJkCF-0005aT-SK for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 18:01:28 +0000 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eJkC8-0007hZ-9t for pgsql-general@postgresql.org; Tue, 28 Nov 2017 18:01:27 +0000 Received: by mail-wr0-x232.google.com with SMTP id h1so905327wre.12 for ; Tue, 28 Nov 2017 10:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=7eBB1lG48aM06czfYk38HYoNVm8HjnEK6hBhEwOzjqQ=; b=Nvrkdx4e/BoMtP1KxVUtE0Gv0YR0ahaOT8JG9/EzrMmuYuQbkiwsKuLt6k3nCwhMkR LIvnYhY7n6oK4vwk4c95RWylGB5oqbm7bs8Wvyw7dz0OjdRScF48xQj7BVrxtaQ5e7Vq JUB8egCDfyql1UsbAoB/eMX620s9UNrd/7NXb0i0n3N/+OeewJIbTbikCqYLTkLTetdO XG4Y9EOYsxadOZDDVL9ydk1gEiJ/zNn8U21ytp2+Ej9PxgN6BFMSYO+DUCwqjyvD/rft 7ySrABumqKDWm5jbfk5FC4TrMkkdD909BmNsju4R/3PA/4OWZ0dX1vUDEU1esXTl7e+W rCKg== 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-language :content-transfer-encoding; bh=7eBB1lG48aM06czfYk38HYoNVm8HjnEK6hBhEwOzjqQ=; b=R//xQAH1H4myyVXnVhy4VIg95yIU1jl+xfs1AFTUGto80LLiJmgb9vHEpNdGWR/NGT WvjyH87OalQ94oVwqC40JQIsx1wpyra4IewkIdEwIo6ihOfuLbUBLwgNWarOqaZARfHm r3JFyj1Uqpuq06eFAsLCA8iJTUHeHiDh2z9xCRbcubiWRMcz+iqMAL66aRGfjNaZuLYG rB5iZm8ygJ8U2uoYBCEyK+dXruIzsLXXzwiTqho2EIWYr7hxy8iu6osKfvb1vkGIwI1H ayd7isnm/JXhdYHgcpBh9ZaC07wEiDgxiAEI5zZGhilnL1MPDbEJaggo15Q7mn+wbb7T eSYQ== X-Gm-Message-State: AJaThX7VkxKfU7bJuzv3dede4rGpSjApkAaf7ZC0SQ0cpY1nYSl6qS5A k0JECJYJIGQueAuWcf3T56DnBSv2q7m0ez+RPdAu648DtvbjNE8mbobc4FuRaMbtAovAkVdTQrq WjGaGg6T1t0UyIirBKgljkHQlm3iQO4A8bEaLFJcshJdH0xTQ7XETzcNcVVKSw1EWi8n4dINFaC v4RqVgmddx X-Google-Smtp-Source: AGs4zMZAfzafrfHFINwjGcOO9jFUkuxRgaMoEkXRS9IAMUtsFEgpX1+/JrwUgfGbHWC3pGOS2i9Mfg== X-Received: by 10.223.153.162 with SMTP id y31mr35303591wrb.216.1511892078474; Tue, 28 Nov 2017 10:01:18 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id t19sm18133085wrb.58.2017.11.28.10.01.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2017 10:01:17 -0800 (PST) Subject: Re: large numbers of inserts out of memory strategy To: Ted Toth Cc: pgsql-general References: From: Tomas Vondra Message-ID: <87d5d3c9-66e4-c29d-bece-79f2909cccb9@2ndquadrant.com> Date: Tue, 28 Nov 2017 19:01:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/28/2017 06:54 PM, Ted Toth wrote: > On Tue, Nov 28, 2017 at 11:22 AM, Tomas Vondra > wrote: >> Hi, >> >> On 11/28/2017 06:17 PM, 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? >>> >> >> The question is what exactly runs out of memory, and how did you modify >> the configuration (particularly related to memory). >> >> regards >> >> -- >> Tomas Vondra http://www.2ndQuadrant.com >> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services > > I'm pretty new to postgres so I haven't changed any configuration > setting and the log is a bit hard for me to make sense of :( > The most interesting part of the log is this: SPI Proc: 2464408024 total in 279 blocks; 1672 free (1 chunks); 2464406352 used PL/pgSQL function context: 537911352 total in 74 blocks; 2387536 free (4 chunks); 535523816 used That is, most of the memory is allocated for SPI (2.4GB) and PL/pgSQL procedure (500MB). How do you do the load? What libraries/drivers? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services