pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Parker <dparker@tazznetworks.com>
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: tim@se.linux.org
Cc: pgsql-performance@postgresql.org
Subject: Re: batch inserts are "slow"
Date: Mon, 2 May 2005 11:53:33 -0400
Message-ID: <07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com> (raw)

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 

Hope that helps!

- DAP

>-----Original Message-----
>From: pgsql-performance-owner@postgresql.org 
>[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of 
>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 = 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();
>> 
>> This snip takes 1.3 secs in postgresql. How can I lower that?
>
>You're batching them as one transaction, and using a prepared 
>query both of which are good.  I guess the next step for a 
>great performance improvement is to use the COPY command.  
>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 
>support it and you may have to apply a patch.
>
>Ask on pgsql-jdbc@postgresql.org perhaps.
>
>Chris
>
>---------------------------(end of 
>broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to 
>majordomo@postgresql.org
>



view thread (15+ messages)  latest in thread

Message-ID: <07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com>
Permalink:  ../07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com/
Also on:    postgresql.org/message-id/07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: dparker@tazznetworks.com, chriskl@familyhealth.com.au, tim@se.linux.org
  Subject: Re: batch inserts are "slow"
  In-Reply-To: <07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com>
  References: <07FDEE0ED7455A48AC42AC2070EDFF7C67EF1F@corpsrv2.tazznetworks.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox