Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJk6b-00042b-9D for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 17:55:37 +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 1eJk6a-0004qg-PF for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 17:55:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJk6a-0004qJ-9w for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 17:55:36 +0000 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eJk6X-0002DK-7a for pgsql-general@postgresql.org; Tue, 28 Nov 2017 17:55:35 +0000 Received: by mail-pf0-x235.google.com with SMTP id l24so258492pfj.6 for ; Tue, 28 Nov 2017 09:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=1gttdpDcjGn+Bixech4YuB192Lp63suRVcufDLIFdTk=; b=ZFKl912/+HVE6QMp+LsTmO5BUckWPVX7O8PbKT/3XnVJLEOhQU7vNC96SbT2FY9L4C KkbnMPcab3QwCVmqQuq9XDrhH6hJh3AQjnDRDYWBWvihBe8xUnmG1bRqphrRLpxaT31F pfdzr+QPkjixO/KiPm8m7p6mbiCjXHg5CA8Ao9ob2rUY1I7Nffho9Ok2lcran1Z1l2y0 WR3TEOSI8jyUn1o6mO4aE/tbPmfPZQJ2eHhMDHZqGNXweHZJTMjtC5VovqQPh1T9p3zT xvxDc4ciS/fxVF8JfBxLlYAqXuKuAikbkQlETwEreuOSxkCIX7kaxxOcr/o/2nwT1fjQ AngA== 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:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=1gttdpDcjGn+Bixech4YuB192Lp63suRVcufDLIFdTk=; b=Y2M1K7BmVa7iS2hN5BrZ1xgwVwRJo8nAd4Y9aG8o+UWfCM3+mIGdizEy7Ox/enOm9M 3baUG1f5aWLtZtL//x0VctcWckUZj0qfucoU6ssnJNmZ4f9iBCjgtmZoGPAfqBEyfEjV zUBbw1ABSg2iA1NmP7ODDfsiTG/DgJK10KeI2cf60tl0fae0nl8neOinvOeV382OFlUu ghWG2RU/YNszlp4nf2PqE2Jzk+xsajU4s3SEczerkuKIlOgQY7d4Jfr7OooXgjJSpT1g bw8z0UGvDUtJ5i9mif3yY8WYl/UOskI2ocTu7KBV7v3WWy+XCzJojmNetFkdY5ENLtvs m/Zw== X-Gm-Message-State: AJaThX5hwnT52VWLAK/HZTK+aIfYc5OoJb+K1L9CDSrumXNxaGxLwNAC ulnMo2gyqpekJFILZFPe5Ikmimyz X-Google-Smtp-Source: AGs4zMY8xsm7amzSjPSMsM3JCNKM9O4ishxOH9aZ5bn+be7VuScpnMYkf7s1l29sLiOHdgn1Ypnc5Q== X-Received: by 10.99.115.26 with SMTP id o26mr22334858pgc.233.1511891731390; Tue, 28 Nov 2017 09:55:31 -0800 (PST) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id z25sm34664862pfe.121.2017.11.28.09.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2017 09:55:30 -0800 (PST) Subject: Re: large numbers of inserts out of memory strategy To: Ted Toth References: <74C96E30-97C3-45D1-887F-F876602355DE@gmail.com> Cc: pgsql-general From: Rob Sargent Message-ID: <5570090c-885b-73ad-529d-f217fd197b2b@gmail.com> Date: Tue, 28 Nov 2017 10:55:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/28/2017 10:50 AM, Ted Toth wrote: > On Tue, Nov 28, 2017 at 11:19 AM, Rob Sargent wrote: >>> On Nov 28, 2017, at 10:17 AM, 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? >>> >>> Ted >>> >> what tools / languages ate you using? > I'm using python to read binary source files and create the text files > contains the SQL. Them I'm running psql -f . If you're going out to the file system, I would use COPY of csv files (if number of records per table is non-trivial). Any bulk loading python available?