Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id B37FC9F946C for ; Tue, 12 Dec 2006 03:46:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 45039-02 for ; Tue, 12 Dec 2006 03:46:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 8554B9F931E for ; Tue, 12 Dec 2006 03:46:04 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mx.inode.at (lb01nat07.inode.at [62.99.145.7]) by svr4.postgresql.org (Postfix) with ESMTP id CB00A5AF027 for ; Tue, 12 Dec 2006 07:46:03 +0000 (GMT) Received: from [83.64.182.18] (port=4809 helo=panettone.apus.local) by smartmx-07.inode.at with esmtp (Exim 4.50) id 1Gu2Kv-0008F7-Fl; Tue, 12 Dec 2006 08:46:01 +0100 Received: from xjens.apus.local ([193.1.1.148]) by panettone.apus.local with esmtp (Exim 3.35 #1 (Debian)) id 1Gu2Kj-0000jn-00; Tue, 12 Dec 2006 08:45:49 +0100 Date: Tue, 12 Dec 2006 08:45:49 +0100 To: "Guillaume Cottenceau" Subject: Re: really quick multiple inserts can use COPY? From: "Jens Schipkowski" Organization: APUS Software GmbH Cc: pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <87vekiqspr.fsf@meuh.mnc.lan> Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <87vekiqspr.fsf@meuh.mnc.lan> User-Agent: Opera Mail/9.02 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.173 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200612/277 X-Sequence-Number: 22333 Thanks a lot to all for your tips. Of course, I am doing all the INSERTs using a transaction. So the cost p= er = 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 usin= g = 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 wro= te: > "Jens Schipkowski" writes: > >> Hello! >> >> In our JAVA application we do multiple inserts to a table by data fro= m >> 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 =3D "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