X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D5984528E0 for ; Mon, 13 Jun 2005 12:55:39 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56870-05 for ; Mon, 13 Jun 2005 15:55:36 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 30F28528BB for ; Mon, 13 Jun 2005 12:55:32 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 87D9F414181; Mon, 13 Jun 2005 16:55:19 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id D494315EE4; Mon, 13 Jun 2005 16:52:24 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01182-09; Mon, 13 Jun 2005 16:52:20 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 4ECDE15ED5; Mon, 13 Jun 2005 16:49:16 +0100 (BST) Message-ID: <42ADAAFB.30404@archonet.com> Date: Mon, 13 Jun 2005 16:49:15 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Csaba Nagy Cc: "ON.KG" , Postgres general mailing list Subject: Re: duplicate key violates unique constraint References: <42A95936.3060002@archonet.com> <20050610095655.0215752956@svr1.postgresql.org> <10813889593.20050613202239@on.kg> <42AD9B9D.6080902@archonet.com> <1118676122.2720.24.camel@coppola.muc.ecircle.de> In-Reply-To: <1118676122.2720.24.camel@coppola.muc.ecircle.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.054 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/627 X-Sequence-Number: 79335 Csaba Nagy wrote: > [snip] > >>If you have more than one client, this can always happen. You have two >>choices: >> 1. Use a lock to stop two clients interacting like this > > > This won't work unless you make all the clients serialized, or you have > all the ip's already inserted in the data base... you can't lock on an > unknown key, otherwise the locking will also need to insert, and you're > back to the same race condition ;-) You can, however, have something more finely-grained than whole-table locking (assuming one IP updated/inserted at a time) by filling a dummy table with e.g. integers 0..255 and locking a row there based on (e.g.) the last octet of your target IP. -- Richard Huxton Archonet Ltd