pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steven Lembark <lembark@wrkhors.com>
To: pgsql-general@lists.postgresql.org
Cc: lembark@wrkhors.com
Subject: Re: large numbers of inserts out of memory strategy
Date: Fri, 1 Dec 2017 11:49:42 -0600
Message-ID: <20171201114942.177b394c@wrkhors.com> (raw)
In-Reply-To: <CAFPpqQG0D_jsLM8mKH=VgCfC1xkBcv=WA7mEV+4=Eq14iJ88xQ@mail.gmail.com>
References: <CAFPpqQGux3uT=CNN-z=zXr4qSmfBw9tDCURimELqEWUBrBpL7A@mail.gmail.com>
	<ad918f32-4913-3dee-281a-5a3fee576a14@2ndquadrant.com>
	<CAFPpqQHY39wDEQm7JeBD6JSN_UgNi-19kdGdZKmhQ2gxTpw8Qw@mail.gmail.com>
	<87d5d3c9-66e4-c29d-bece-79f2909cccb9@2ndquadrant.com>
	<CAFPpqQGJ9GkntRrjEqvHCRtkbHojmTy93LmCpfuMGJj5F2O7-A@mail.gmail.com>
	<8431416a-2ab2-d580-19bd-2c7e3353960d@2ndquadrant.com>
	<CAAQkdDoq2fXk+E1gtVh_rUuJ99iLGrbc7jWBNkZpGHjytf-3NA@mail.gmail.com>
	<26623.1511927991@sss.pgh.pa.us>
	<CAFPpqQH3BRYg9A5PGGTHh0SQrZEmFegOdPrPSrnJxg19nBB+QA@mail.gmail.com>
	<20171130102209.6q6djwimzzj5opge@hjp.at>
	<CAFPpqQG0D_jsLM8mKH=VgCfC1xkBcv=WA7mEV+4=Eq14iJ88xQ@mail.gmail.com>

On Thu, 30 Nov 2017 08:43:32 -0600
Ted Toth <txtoth@gmail.com> 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 <sequence>'.

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




view thread (27+ messages)  latest in thread

Message-ID: <20171201114942.177b394c@wrkhors.com>
Permalink:  ../20171201114942.177b394c@wrkhors.com/
Also on:    postgresql.org/message-id/20171201114942.177b394c@wrkhors.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: lembark@wrkhors.com
  Subject: Re: large numbers of inserts out of memory strategy
  In-Reply-To: <20171201114942.177b394c@wrkhors.com>
  References: <CAFPpqQGux3uT=CNN-z=zXr4qSmfBw9tDCURimELqEWUBrBpL7A@mail.gmail.com> <ad918f32-4913-3dee-281a-5a3fee576a14@2ndquadrant.com> <CAFPpqQHY39wDEQm7JeBD6JSN_UgNi-19kdGdZKmhQ2gxTpw8Qw@mail.gmail.com> <87d5d3c9-66e4-c29d-bece-79f2909cccb9@2ndquadrant.com> <CAFPpqQGJ9GkntRrjEqvHCRtkbHojmTy93LmCpfuMGJj5F2O7-A@mail.gmail.com> <8431416a-2ab2-d580-19bd-2c7e3353960d@2ndquadrant.com> <CAAQkdDoq2fXk+E1gtVh_rUuJ99iLGrbc7jWBNkZpGHjytf-3NA@mail.gmail.com> <26623.1511927991@sss.pgh.pa.us> <CAFPpqQH3BRYg9A5PGGTHh0SQrZEmFegOdPrPSrnJxg19nBB+QA@mail.gmail.com> <20171130102209.6q6djwimzzj5opge@hjp.at> <CAFPpqQG0D_jsLM8mKH=VgCfC1xkBcv=WA7mEV+4=Eq14iJ88xQ@mail.gmail.com> <20171201114942.177b394c@wrkhors.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox