Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKpK8-0005d9-Nn for pgsql-general@arkaria.postgresql.org; Fri, 01 Dec 2017 17:42:04 +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 1eKpK7-0007e8-Nl for pgsql-general@arkaria.postgresql.org; Fri, 01 Dec 2017 17:42:03 +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 1eKpK7-0007dz-Ge for pgsql-general@lists.postgresql.org; Fri, 01 Dec 2017 17:42:03 +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 1eKpK4-0002fT-8G for pgsql-general@lists.postgresql.org; Fri, 01 Dec 2017 17:42:02 +0000 Received: from wrkhors.com (localhost [127.0.0.1]) by jeeves.wrkhors.com (Postfix) with ESMTP id 838E610EE03; Fri, 1 Dec 2017 11:41:56 -0600 (CST) Date: Fri, 1 Dec 2017 11:49:42 -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: <20171201114942.177b394c@wrkhors.com> In-Reply-To: References: <87d5d3c9-66e4-c29d-bece-79f2909cccb9@2ndquadrant.com> <8431416a-2ab2-d580-19bd-2c7e3353960d@2ndquadrant.com> <26623.1511927991@sss.pgh.pa.us> <20171130102209.6q6djwimzzj5opge@hjp.at> 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 Thu, 30 Nov 2017 08:43:32 -0600 Ted Toth wrote: > What is the downside of using a DO block? I'd have to do a nextval on > each sequence before I could use currval, right? Or I could do 'select > last_value from '. You are creating a piece of code that has to be parsed, tokenized, and compiled prior to execution. What's biting you is that you've created a function the size of your dataset. If you like do-blocks then write a short block to insert one record using placeholders and call it a few zillion times. That or (in DBI-speak): eval { $dbh->{ RaiseError } = 1; $dbh->{ AutoCommit } = 0; my $sth = $dbh->prepare ( 'insert into yourtable ( field field ) values ( $1, $2 )' ); $sth->do( @$_ ) for @rows; $dbh->commit } or die "Failed execution: $@"; which will be nearly as effecient in the long run. That or just import the data from a csv/tsv (there are good examples of data import available in the PG docs). -- Steven Lembark 1505 National Ave Workhorse Computing Rockford, IL 61103 lembark@wrkhors.com +1 888 359 3508