Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)

From: Kris Jurka <books(at)ejurka(dot)com>
To: Haifeng Liu <liuhaifeng(at)live(dot)com>
Cc: dmp <danap(at)ttc-cmc(dot)net>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Date: 2012-12-14 16:51:14
Message-ID: alpine.BSO.2.00.1212141147030.30031@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general pgsql-jdbc

On Sat, 15 Dec 2012, Haifeng Liu wrote:

> I did a simple test and found that if one of the batch failed, the other
> update may be execute partially. when I test with 10 updates a batch,
> none of them are updated, when I test with 1000 updates a batch, about
> 700+ of them are executed, but the failed update should be the last one,
> which means 999 executed updates is more reasonable than 700+. But
> really weird thing is the getUpdateCounts method returns the reasonable
> information.
>
> I don't know what happened inside this driver. Currently I have to
> setAutoCommit to false and use commit/rollback to achieve my goal.
>

Internally the driver splits each batch into sub-batches of 250 to send to
the server to reduce the possibility of deadlocking the network
connection. When auto-commit is enabled in the driver, the auto-commit
setting affects the whole sub-batch of 250 because of how the
frontend/backend protocol works. So you are seeing some oddities because
of some implementation details and you should not use auto-commit with
batch statements.

Kris Jurka

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Shams Khan 2012-12-14 17:51:56 PostgreSQL Performance Tuning / Postgresql.conf and on OS Level
Previous Message Haifeng Liu 2012-12-14 16:50:08 Fwd: [JDBC] Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2012-12-14 16:54:29 Re: XML Schema for PostgreSQL database
Previous Message Haifeng Liu 2012-12-14 16:50:08 Fwd: [JDBC] Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)

Browse pgsql-jdbc by date

  From Date Subject
Next Message dmp 2012-12-14 17:23:32 Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Previous Message Haifeng Liu 2012-12-14 16:50:08 Fwd: [JDBC] Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)