Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZDEt5-00016i-S6 for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Jul 2015 16:41:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZDEt4-00013X-AD for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Jul 2015 16:41:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZDE9F-0006KR-V4 for pgsql-bugs@postgresql.org; Thu, 09 Jul 2015 15:54:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZDE9D-0002J6-2X for pgsql-bugs@postgresql.org; Thu, 09 Jul 2015 15:54:05 +0000 MIME-Version: 1.0 Subject: BUG #13496: INSERT WHERE NOT EXISTS error To: pgsql-bugs@postgresql.org From: ilies.ovidiu@googlemail.com Date: Thu, 09 Jul 2015 15:53:04 +0000 Message-ID: <20150709155304.15752.16284@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13496 Logged by: Radu Ovidiu Email address: ilies.ovidiu@googlemail.com PostgreSQL version: 9.4.4 Operating system: Debian Linux 8 / Redhat Linux 6.5 Description: Hi, I run a web server with high loads ~ 700 users / minute. Sometimes (rare) I get an error like duplicate value violation on insert on field "search_term". Table is like: id, primary key search_term, varchar(255), UNIQUE The insert query is like: INSERT INTO "website"."search_terms" SELECT 'someID', 'someSearchTerm' WHERE NOT EXISTS ( SELECT 1 FROM "website"."search_terms" WHERE (("id" = 'someID') OR ("term" = 'someSearchTerm')) LIMIT 1 OFFSET 0 ) It appears this "upsert" is not safe in high concurency mode ~ 20 users / second as I see in Google analytics for that period of time. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs