Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E9464B5DBDC for ; Thu, 4 Aug 2011 19:32:44 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 41942-06 for ; Thu, 4 Aug 2011 22:32:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.catalyst.net.nz (bertrand.catalyst.net.nz [202.78.240.40]) by mail.postgresql.org (Postfix) with ESMTP id 27D87B5DBDB for ; Thu, 4 Aug 2011 19:32:37 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 8000E676AB for ; Fri, 5 Aug 2011 10:32:35 +1200 (NZST) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JQmySPI3LpNf for ; Fri, 5 Aug 2011 10:32:34 +1200 (NZST) Received: from [IPv6:2404:130:0:1000:222:15ff:fe5c:2471] (unknown [IPv6:2404:130:0:1000:222:15ff:fe5c:2471]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id BAB7A676A8 for ; Fri, 5 Aug 2011 10:32:34 +1200 (NZST) Message-ID: <4E3B1E02.1060704@catalyst.net.nz> Date: Fri, 05 Aug 2011 10:32:34 +1200 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Need to tune for Heavy Write References: <4E3A268C.9090409@orkash.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------090001010707030301060309" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.703 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, RP_MATCHES_RCVD=-0.804 X-Spam-Level: X-Archive-Number: 201108/84 X-Sequence-Number: 44531 This is a multi-part message in MIME format. --------------090001010707030301060309 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 05/08/11 05:40, Samuel Gendler wrote: > > > On Wed, Aug 3, 2011 at 9:56 PM, Adarsh Sharma > > wrote: > > Dear all, > > From the last few days, I researched a lot on Postgresql > Performance Tuning due to slow speed of my server. > My application selects data from mysql database about 100000 rows > , process it & insert into postgres 2 tables by making about 45 > connections. > > > It's already been mentioned, but is worth reinforcing, that if you are > inserting 100,000 rows in 100,000 transactions, you'll see a huge > performance improvement by doing many more inserts per transaction. > Try doing at least 500 inserts in each transaction (though you can > possibly go quite a bit higher than that without any issues, depending > upon what other traffic the database is handling in parallel). You > almost certainly don't need 45 connections in order to insert only > 100,000 rows. I've got a crappy VM with 2GB of RAM in which inserting > 100,000 relatively narrow rows requires less than 10 seconds if I do > it in a single transaction on a single connection. Probably much less > than 10 seconds, but the code I just tested with does other work while > doing the inserts, so I don't have a pure test at hand. Also worth mentioning is doing those 500 inserts in *fewer* than 500 INSERT operations is likely to be a huge improvement, e.g: INSERT INTO table VALUES (....),(....); instead of INSERT INTO table VALUES (....); INSERT INTO table VALUES (....); I'd be tempted to do all 500 row insertions in one INSERT statement as above. You might find that 1 connection doing this is fast enough (it is only doing 200 actual INSERT calls in that case to put in 100000 rows). regards Mark --------------090001010707030301060309 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 05/08/11 05:40, Samuel Gendler wrote:


On Wed, Aug 3, 2011 at 9:56 PM, Adarsh Sharma <adarsh.sharma@orkash.com> wrote:
Dear all,

From the last few days, I researched a lot on Postgresql Performance Tuning due to slow speed of my server.
My application selects data from mysql database about 100000 rows , process it & insert into postgres 2 tables by making about 45 connections.

It's already been mentioned, but is worth reinforcing, that if you are inserting 100,000 rows in 100,000 transactions, you'll see a huge performance improvement by doing many more inserts per transaction.  Try doing at least 500 inserts in each transaction (though you can possibly go quite a bit higher than that without any issues, depending upon what other traffic the database is handling in parallel).  You almost certainly don't need 45 connections in order to insert only 100,000 rows.  I've got a crappy VM with 2GB of RAM in which inserting 100,000 relatively narrow rows requires less than 10 seconds if I do it in a single transaction on a single connection.  Probably much less than 10 seconds, but the code I just tested with does other work while doing the inserts, so I don't have a pure test at hand.

Also worth mentioning is doing those 500 inserts in *fewer* than 500 INSERT operations is likely to be a huge improvement, e.g:

INSERT INTO table VALUES (....),(....);

instead of

INSERT INTO table VALUES (....);
INSERT INTO table VALUES (....);

I'd be tempted to do all 500 row insertions in one INSERT statement as above. You might find that 1 connection doing this is fast enough (it is only doing 200 actual INSERT calls in that case to put in 100000 rows).

regards

Mark




--------------090001010707030301060309--