From: Tom Lane <tgl@sss.pgh.pa.us>
To: tim@se.linux.org
Cc: pgsql-performance@postgresql.org
Subject: Re: batch inserts are "slow"
Date: Mon, 02 May 2005 11:29:59 -0400
Message-ID: <18686.1115047799@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.44.0505021526450.7150-100000@naskur.se.linux.org>
References: <Pine.LNX.4.44.0505021526450.7150-100000@naskur.se.linux.org>
=?iso-8859-1?Q?Tim_Terleg=E5rd?= <tim@se.linux.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
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, tim@se.linux.org
Subject: Re: batch inserts are "slow"
In-Reply-To: <18686.1115047799@sss.pgh.pa.us>
* 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