Re: batch inserts are "slow"

From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: tim(at)se(dot)linux(dot)org
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: batch inserts are "slow"
Date: 2005-05-02 15:10:33
Message-ID: 427642E9.2080500@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> 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(at)postgresql(dot)org perhaps.

Chris

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Christopher Petrilli 2005-05-02 15:17:18 Re: batch inserts are "slow"
Previous Message Tim Terlegård 2005-05-02 13:52:31 batch inserts are "slow"