Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id D82E82D4D06 for ; Wed, 4 Jan 2012 08:34:20 -0400 (AST) Received: from 77-111-9-161.ipv4.tusmobil.si ([77.111.9.161] helo=mail2.over.net) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RiQ2p-000212-GW for pgsql-sql@postgresql.org; Wed, 04 Jan 2012 12:34:20 +0000 Received: by mail2.over.net (Postfix, from userid 506) id 6D10EF9AC13; Wed, 4 Jan 2012 13:34:01 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail2.over.net X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham version=3.3.1 Received: from zdravko.siix.org (unknown [192.168.2.183]) by mail2.over.net (Postfix) with ESMTPA id D8128F9AC32; Wed, 4 Jan 2012 13:33:55 +0100 (CET) Message-ID: <4F044733.6020007@siix.com> Date: Wed, 04 Jan 2012 13:33:55 +0100 From: Zdravko Balorda User-Agent: Thunderbird 2.0.0.24 (X11/20110906) MIME-Version: 1.0 To: Samuel Gendler CC: pgsql-sql@postgresql.org Subject: Re: ignore unique violation OR check row exists References: <1325624070446-5117916.post@n5.nabble.com> <20120104090838.GA6039@tux> <4F042291.6040903@siix.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.9 (/) X-Archive-Number: 201201/18 X-Sequence-Number: 36189 Samuel Gendler wrote: > > > On Wed, Jan 4, 2012 at 1:57 AM, Zdravko Balorda > > wrote: > Take it out of transaction. Why is there a transaction in the first > place? > If transaction is needed, ok, but take these inserts out and > everything will > work as it should. Ignoring UNIQUE VIOLATION or any other error > defeats the very > purpose of transaction. That's why you can't ignore it. > > > Unfortunately, bulk inserts are much slower when they don't occur in a > transaction. Try inserting 1 million rows with auto commit enabled vs 1 > million rows in 1 transaction, or even 10 or 100 transactions. The > difference is enormous. The bulk insert into an unconstrained table and > then pulling just the new rows over into the destination table in a > single transaction is definitely the most effective way to do this. > I do a lot of bulk inserts. What helps is dropping indexes before insert and recreating it after. Probably you need to better organize data to avoid having primary keys on a table with a lots of data. Zdravko