Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZK7kc-00005w-Md for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jul 2015 16:29:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZK7kc-00088R-31 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jul 2015 16:29:10 +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 1ZK7kb-000880-9j for pgsql-bugs@postgresql.org; Tue, 28 Jul 2015 16:29:09 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZK7kW-0007dW-5L for pgsql-bugs@postgresql.org; Tue, 28 Jul 2015 16:29:07 +0000 MIME-Version: 1.0 Subject: BUG #13523: Unexplained deadlocks (possible race condition) To: pgsql-bugs@postgresql.org From: jack@douglastechnology.co.uk Date: Tue, 28 Jul 2015 16:28:23 +0000 Message-ID: <20150728162823.25043.27625@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" 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: 13523 Logged by: Jack Douglas Email address: jack@douglastechnology.co.uk PostgreSQL version: 9.4.3 Operating system: Debian Jessie Description: Hi I'm getting intermittent (but easily reproducible) deadlocks showing in my error log, for example: 2015-07-28 16:46:19 BST ERROR: deadlock detected 2015-07-28 16:46:19 BST DETAIL: Process 9394 waits for ExclusiveLock on relation 65605 of database 12141; blocked by process 9393. Process 9393 waits for ExclusiveLock on relation 65605 of database 12141; blocked by process 9394. Process 9394: select f_test('blah') Process 9393: select f_test('blah') 2015-07-28 16:46:19 BST HINT: See server log for query details. 2015-07-28 16:46:19 BST CONTEXT: SQL function "f_test" statement 1 2015-07-28 16:46:19 BST STATEMENT: select f_test('blah') The above is from a minimal test case I've attempted to create rather than my production code. The test case is as follows: create table test( id serial primary key, val text ); create function f_test(v text) returns integer language sql security definer set search_path = postgres,pg_temp as $$ lock test in exclusive mode; insert into test(val) select v where not exists(select * from test where val=v); select id from test where val=v; $$; then from two bash sessions simultaneously: for i in {1..1000}; do psql postgres postgres -c "select f_test('blah')"; done This produces a handful of deadlocks on my server, however using a VM on a laptop another postgres user said he got far more. More detail is on the question I posted at DBA.SE (and it's probably easier to read the code there: http://dba.stackexchange.com/q/108290/1396 Kind regards Jack -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs