Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 9A3899FA286 for ; Tue, 6 Feb 2007 12:14:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 77341-09 for ; Tue, 6 Feb 2007 12:14:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 7FE889FB222 for ; Tue, 6 Feb 2007 12:14:45 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 6 Feb 2007 16:14:44 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 06 Feb 2007 10:14:44 -0600 Subject: Re: How long should it take to insert 200,000 records? From: Scott Marlowe To: Karen Hill Cc: pgsql-performance@postgresql.org In-Reply-To: <1170722158.973141.208230@j27g2000cwj.googlegroups.com> References: <1170722158.973141.208230@j27g2000cwj.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1170778484.5451.97.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 06 Feb 2007 10:14:44 -0600 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/66 X-Sequence-Number: 23120 On Mon, 2007-02-05 at 18:35, Karen Hill wrote: > I have a pl/pgsql function that is inserting 200,000 records for > testing purposes. What is the expected time frame for this operation > on a pc with 1/2 a gig of ram and a 7200 RPM disk? The processor is > a 2ghz cpu. So far I've been sitting here for about 2 million ms > waiting for it to complete, and I'm not sure how many inserts postgres > is doing per second. That really depends. Doing 200,000 inserts as individual transactions will be fairly slow. Since PostgreSQL generally runs in autocommit mode, this means that if you didn't expressly begin a transaction, you are in fact inserting each row as a transaction. i.e. this: for (i=0;i<200000;i++){ insert into table abc values ('test',123); } Is functionally equivalent to: for (i=0;i<200000;i++){ begin; insert into table abc values ('test',123); commit; } However, you can add begin / end pairs outside the loop like this: begin; for (i=0;i<200000;i++){ insert into table abc values ('test',123); } commit; and it should run much faster.