Re: batch inserts are "slow"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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:29:59
Message-ID: 18686.1115047799@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

=?iso-8859-1?Q?Tim_Terleg=E5rd?= <tim(at)se(dot)linux(dot)org> 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message David Parker 2005-05-02 15:53:33 Re: batch inserts are "slow"
Previous Message Christopher Petrilli 2005-05-02 15:27:37 Re: batch inserts are "slow"