X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E14D75294D for ; Mon, 2 May 2005 12:30:06 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15866-10 for ; Mon, 2 May 2005 15:30:02 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id CF3C25351C for ; Mon, 2 May 2005 12:30:00 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j42FTxK1018687; Mon, 2 May 2005 11:29:59 -0400 (EDT) To: tim@se.linux.org Cc: pgsql-performance@postgresql.org Subject: Re: batch inserts are "slow" In-reply-to: References: Comments: In-reply-to =?iso-8859-1?Q?Tim_Terleg=E5rd?= message dated "Mon, 02 May 2005 15:52:31 +0200" Date: Mon, 02 May 2005 11:29:59 -0400 Message-ID: <18686.1115047799@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/7 X-Sequence-Number: 12171 =?iso-8859-1?Q?Tim_Terleg=E5rd?= writes: > There seems to be only one issue left, batch inserts in postgresql seem > significant slower than in oracle. I have about 200 batch jobs, each > consisting of about 14 000 inserts. > conn.setAutoCommit(false); > pst = conn.prepareStatement("INSERT INTO tmp (...) VALUES (?,?)"); > for (int i = 0; i < len; i++) { > pst.setInt(0, 2); > pst.setString(1, "xxx"); > pst.addBatch(); > } > pst.executeBatch(); > conn.commit(); Hmm. It's good that you are wrapping this in a transaction, but I wonder about doing it as a single "batch". I have no idea what the internal implementation of batches in JDBC is like, but it seems possible that it would have some performance issues with 14000 statements in a batch. Have you checked whether the bulk of the runtime is being consumed on the server or client side? Also, make sure that the JDBC driver is using "real" prepared statements --- until pretty recently, it faked them. I think build 311 is new enough, but it would be good to check in the docs or by asking on pgsql-jdbc. regards, tom lane