pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Divakar Singh <dpsmails@yahoo.com>
To: Alex Hunsaker <badalex@gmail.com>
Cc: Steve Singer <ssinger@ca.afilias.info>
Cc: jd@commandprompt.com
Cc: pgsql-performance@postgresql.org
Subject: Re: Postgres insert performance and storage requirement compared to Oracle
Date: Wed, 27 Oct 2010 20:08:53 -0700 (PDT)
Message-ID: <604758.88084.qm@web65414.mail.ac4.yahoo.com> (raw)
In-Reply-To: <AANLkTi=0PkVscoYkMn-nETn16LAL4N-C8jzwGWffn7uV@mail.gmail.com>
References: <132275.30531.qm@web65411.mail.ac4.yahoo.com>
	<AANLkTi=0PkVscoYkMn-nETn16LAL4N-C8jzwGWffn7uV@mail.gmail.com>

So another question pops up: What method in PostgreSQL does the stored proc use 
when I issue multiple insert (for loop for 100 thousand records) in the stored 
proc?
It takes half the time compared to the consecutive "insert" using libpq.
In the backend, does it use COPY or prepared statement? or something else?

 Best Regards,
Divakar




________________________________
From: Alex Hunsaker <badalex@gmail.com>
To: Divakar Singh <dpsmails@yahoo.com>
Cc: Steve Singer <ssinger@ca.afilias.info>; jd@commandprompt.com; 
pgsql-performance@postgresql.org
Sent: Thu, October 28, 2010 1:15:06 AM
Subject: Re: [PERFORM] Postgres insert performance and storage requirement 
compared to Oracle

On Wed, Oct 27, 2010 at 08:00, Divakar Singh <dpsmails@yahoo.com> wrote:
> I am attaching my code below.
> Is any optimization possible in this?
> Do prepared statements help in cutting down the insert time to half for this
> kind of inserts?

In half? not for me.  Optimization possible? Sure, using the code you
pasted (time ./a.out 100000 <method>):
PQexec: 41s
PQexecPrepared: 36s
1 insert statement: 7s
COPY: 1s
psql: 256ms

Basically the above echoes the suggestions of others, use COPY if you can.

Find the source for the above attached.  Its just a very quick
modified version of what you posted. [ disclaimer the additions I
added are almost certainly missing some required error checking... ]

[ psql is fast because the insert is really dumb: insert into aaaa (a,
b, c, d, e, f, g, h, j, k, l, m, n, p) select 1, 'asdf', 'asdf',
'asdf', 'asdf', 'asdf', 'asdf', 'asdf', 'asdf', 'asdf', 'asdf',
'asdf', 'asdf', 'asdf' from generate_series(1, 100000); ]



      

view thread (53+ messages)  latest in thread

Message-ID: <604758.88084.qm@web65414.mail.ac4.yahoo.com>
Permalink:  ../604758.88084.qm@web65414.mail.ac4.yahoo.com/
Also on:    postgresql.org/message-id/604758.88084.qm@web65414.mail.ac4.yahoo.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: dpsmails@yahoo.com, badalex@gmail.com, ssinger@ca.afilias.info, jd@commandprompt.com
  Subject: Re: Postgres insert performance and storage requirement compared to Oracle
  In-Reply-To: <604758.88084.qm@web65414.mail.ac4.yahoo.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