Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 5DC589FA1DE for ; Tue, 12 Dec 2006 04:12:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 57337-09 for ; Tue, 12 Dec 2006 04:12:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtp-vbr1.xs4all.nl (smtp-vbr1.xs4all.nl [194.109.24.21]) by postgresql.org (Postfix) with ESMTP id 627769F946C for ; Tue, 12 Dec 2006 04:12:44 -0400 (AST) Received: from [10.0.0.16] (a80-126-182-198.adsl.xs4all.nl [80.126.182.198]) (authenticated bits=0) by smtp-vbr1.xs4all.nl (8.13.8/8.13.8) with ESMTP id kBC8CYCs006498; Tue, 12 Dec 2006 09:12:34 +0100 (CET) (envelope-from nicky@valuecare.nl) Message-ID: <457E6472.9010707@valuecare.nl> Date: Tue, 12 Dec 2006 09:12:34 +0100 From: nicky User-Agent: Thunderbird 1.5.0.8 (X11/20061113) MIME-Version: 1.0 To: Jens Schipkowski CC: pgsql-performance@postgresql.org Subject: Re: really quick multiple inserts can use COPY? References: <87vekiqspr.fsf@meuh.mnc.lan> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/278 X-Sequence-Number: 22334 Jens Schipkowski wrote: > Thanks a lot to all for your tips. > > Of course, I am doing all the INSERTs using a transaction. So the cost > per INSERT dropped from 30 ms to 3 ms. > The improvement factor matches with the hint by Brian Hurt. > Sorry, I forgot to mention we are using PostgreSQL 8.1.4. > Thanks for the code snippet posted by mallah. It looks like you are > using prepared statements, which are not available to us. > But I will check our database access if its possible to do a > workaround, because this looks clean and quick to me. > > regards > Jens Schipkowski > > > On Mon, 11 Dec 2006 17:53:52 +0100, Guillaume Cottenceau > wrote: > >> "Jens Schipkowski" writes: >> >>> Hello! >>> >>> In our JAVA application we do multiple inserts to a table by data from >>> a Hash Map. Due to poor database access implemention - done by >>> another company (we got the job to enhance the software) - we cannot >>> use prepared statements. (We are not allowed to change code at >>> database access!) >>> First, we tried to fire one INSERT statement per record to insert. >>> This costs 3 ms per row which is to slow because normally we insert >>> 10.000 records which results in 30.000 ms just for inserts. >>> >>> for(){ >>> sql = "INSERT INTO tblfoo(foo,bar) >>> VALUES("+it.next()+","+CONST.BAR+");"; >>> } >> >> You should try to wrap that into a single transaction. PostgreSQL >> waits for I/O write completion for each INSERT as it's >> implicitely in its own transaction. Maybe the added performance >> would be satisfactory for you. >> > > > > --** > APUS Software GmbH > > ---------------------------(end of broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at > > http://www.postgresql.org/about/donate > > > This link might be what you are looking for, it has some information about implementing COPY in the JDBC driver. Check the reply message as well. http://archives.postgresql.org/pgsql-jdbc/2005-04/msg00134.php Another solution might be to have Java dump the contents of the HashMap to a CVS file and have it load through psql with COPY commands. Good luck, Nick