Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id EF6C81336FA7 for ; Thu, 28 Oct 2010 00:09:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 58426-09 for ; Thu, 28 Oct 2010 03:08:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from nm17-vm1.bullet.mail.ac4.yahoo.com (nm17-vm1.bullet.mail.ac4.yahoo.com [98.139.53.209]) by mail.postgresql.org (Postfix) with SMTP id 984811335B36 for ; Thu, 28 Oct 2010 00:08:54 -0300 (ADT) Received: from [98.139.52.197] by nm17.bullet.mail.ac4.yahoo.com with NNFMP; 28 Oct 2010 03:08:53 -0000 Received: from [98.139.52.171] by tm10.bullet.mail.ac4.yahoo.com with NNFMP; 28 Oct 2010 03:08:53 -0000 Received: from [127.0.0.1] by omp1054.mail.ac4.yahoo.com with NNFMP; 28 Oct 2010 03:08:53 -0000 X-Yahoo-Newman-Property: ymail-5 X-Yahoo-Newman-Id: 898989.96118.bm@omp1054.mail.ac4.yahoo.com Received: (qmail 89467 invoked by uid 60001); 28 Oct 2010 03:08:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1288235333; bh=YiyqRe1MoZ7YFi6GodZgX+ETTAGHj8Mi2247aWQ0sHM=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:References:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=BaXBii+xCdNkF0I/tIXk3wSTt4w3ne8ILDbCE0/bXaAkZI6tYAWLep7FHzwb/tzn580zk6tOQ0f7j02ybaQegKvaC9GCIj5m0TEvtoXJMP5nvgCwnJhmi9XoEUWSpPhAHX+xiLqIR8rRd7+3zBKF77JBEmBBZfW62Kvw8FtUzB4= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:References:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=L3OIgS/yVeE2b1DjvLwf69u3bhuzDBGklh+b1MeDCEzUePIbROJCwBlt8JqYrZVfV7u0wVPQ5HdF9aKUcC/P+CNIJHIkwq/rRcZBfXUqUcxM48ay15fxYuHgNeBwLEs4D2VXrUotYglN1AEIz6E+BDLTAmepnt9FDK3LUbyVdO4=; Message-ID: <604758.88084.qm@web65414.mail.ac4.yahoo.com> X-YMail-OSG: 3QmMYrMVM1n0ZRr_3jEylZuEn5EfdOcdXXQAfLyiISahRbs YUQkimtq0OqJSqZHNstRF0psnUz90txjQv29MBl9L5sB2xLBs7OZwDNmqbZO uw_KlyT7nN0bI2QIOm9WPYb8vWWUDCkbAeiyebe6ta.OIyf4p_8UwP7da0Z4 3go15hSIHivEZAcBc62N07IPyH94Wud52PycLo97U13kDbXGkPJESRYeYmyw 1VGDyEZ6P61Tlco7wH35_WvWF9r7O5gIto1_j9W0bz4CC7OLQ8tbkQ4mY8da j.FVE.j9ytoDBDNI.XWR938IM_mVvhASQsGIfbAv7VOzSLOp2b9aL8nDzXOP i3lu24n6RRXDtf6u3l2z_ZXCYU49eBBfPIcI- Received: from [194.237.142.17] by web65414.mail.ac4.yahoo.com via HTTP; Wed, 27 Oct 2010 20:08:53 PDT X-Mailer: YahooMailRC/504.5 YahooMailWebService/0.8.107.284920 References: <132275.30531.qm@web65411.mail.ac4.yahoo.com> Date: Wed, 27 Oct 2010 20:08:53 -0700 (PDT) From: Divakar Singh Subject: Re: Postgres insert performance and storage requirement compared to Oracle To: Alex Hunsaker Cc: Steve Singer , jd@commandprompt.com, pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-148472624-1288235333=:88084" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.909 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/526 X-Sequence-Number: 40944 --0-148472624-1288235333=:88084 Content-Type: text/plain; charset=us-ascii 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 To: Divakar Singh Cc: Steve Singer ; 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 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 ): 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); ] --0-148472624-1288235333=:88084 Content-Type: text/html; charset=us-ascii
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); ]

--0-148472624-1288235333=:88084--