Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B6774B5D91F for ; Mon, 12 Sep 2011 14:22:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 18857-02 for ; Mon, 12 Sep 2011 17:22:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (97-64-237-59.client.mchsi.com [97.64.237.59]) by mail.postgresql.org (Postfix) with ESMTP id 70373B5DC07 for ; Mon, 12 Sep 2011 14:22:43 -0300 (ADT) Received: from [192.168.10.84] (unknown [192.168.10.84]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id F3F9646999; Mon, 12 Sep 2011 12:22:41 -0500 (CDT) Message-ID: <4E6E3FE8.5070609@squeakycode.net> Date: Mon, 12 Sep 2011 12:22:48 -0500 From: Andy Colson User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: Robert Klemme CC: pgsql-performance@postgresql.org Subject: Re: Postgres for a "data warehouse", 5-10 TB References: <4E6CC458.4010206@squeakycode.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.918 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201109/148 X-Sequence-Number: 44924 On 9/12/2011 12:15 PM, Robert Klemme wrote: > On 11.09.2011 19:02, Marti Raudsepp wrote: >> On Sun, Sep 11, 2011 at 17:23, Andy Colson wrote: >>> On 09/11/2011 08:59 AM, Igor Chudov wrote: >>>> By the way, does that INSERT UPDATE functionality or something like >>>> this exist in Postgres? >>> You have two options: >>> 1) write a function like: >>> create function doinsert(_id integer, _value text) returns void as >>> 2) use two sql statements: >> >> Unfortunately both of these options have caveats. Depending on your >> I/O speed, you might need to use multiple loader threads to saturate >> the write bandwidth. >> >> However, neither option is safe from race conditions. If you need to >> load data from multiple threads at the same time, they won't see each >> other's inserts (until commit) and thus cause unique violations. If >> you could somehow partition their operation by some key, so threads >> are guaranteed not to conflict each other, then that would be perfect. >> The 2nd option given by Andy is probably faster. >> >> You *could* code a race-condition-safe function, but that would be a >> no-go on a data warehouse, since each call needs a separate >> subtransaction which involves allocating a transaction ID. > > Wouldn't it be sufficient to reverse order for race condition safety? > Pseudo code: > > begin > insert ... > catch > update ... > if not found error > end > > Speed is another matter though... > > Kind regards > > robert > > > No, I dont think so, if you had two loaders, both would start a transaction, then neither could see what the other was doing. There are transaction isolation levels, but they are like playing with fire. (in my opinion). -Andy