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 DC3D7535EC for ; Mon, 2 May 2005 12:53:43 -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 20317-05 for ; Mon, 2 May 2005 15:53:36 +0000 (GMT) Received: from corpsrv2.tazznetworks.com (wsip-66-210-115-146.ri.ri.cox.net [66.210.115.146]) by svr1.postgresql.org (Postfix) with ESMTP id 6DD855352A for ; Mon, 2 May 2005 12:53:34 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: batch inserts are "slow" Date: Mon, 2 May 2005 11:53:33 -0400 Message-ID: <07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] batch inserts are "slow" Thread-Index: AcVPK2Bx0b+ax4tLToiQSjMlMTnD0QAAtUgQ From: "David Parker" To: "Christopher Kings-Lynne" , Cc: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.088 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200505/8 X-Sequence-Number: 12172 We ran into the need to use COPY, but our application is also in Java. We wrote a JNI bridge to a C++ routine that uses the libpq library to do the COPY. The coding is a little bit weird, but not too complicated - the biggest pain in the neck is probably getting it into your build system. Here's the Java tutorial on JNI: http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html=20 Hope that helps! - DAP >-----Original Message----- >From: pgsql-performance-owner@postgresql.org=20 >[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20 >Christopher Kings-Lynne >Sent: Monday, May 02, 2005 11:11 AM >To: tim@se.linux.org >Cc: pgsql-performance@postgresql.org >Subject: Re: [PERFORM] batch inserts are "slow" > >> conn.setAutoCommit(false); >> pst =3D conn.prepareStatement("INSERT INTO tmp (...) VALUES=20 >(?,?)"); for=20 >> (int i =3D 0; i < len; i++) { >> pst.setInt(0, 2); >> pst.setString(1, "xxx"); >> pst.addBatch(); >> } >> pst.executeBatch(); >> conn.commit(); >>=20 >> This snip takes 1.3 secs in postgresql. How can I lower that? > >You're batching them as one transaction, and using a prepared=20 >query both of which are good. I guess the next step for a=20 >great performance improvement is to use the COPY command. =20 >However, you'd have to find out how to access that via Java. > >I have a nasty suspicion that the release JDBC driver doesn't=20 >support it and you may have to apply a patch. > >Ask on pgsql-jdbc@postgresql.org perhaps. > >Chris > >---------------------------(end of=20 >broadcast)--------------------------- >TIP 1: subscribe and unsubscribe commands go to=20 >majordomo@postgresql.org >