Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSiAE-0004b5-Tm for pgsql-general@arkaria.postgresql.org; Sat, 23 Dec 2017 11:40:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSiAE-0001hh-62 for pgsql-general@arkaria.postgresql.org; Sat, 23 Dec 2017 11:40: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_2) (envelope-from ) id 1eSiAD-0001hX-UR for pgsql-general@lists.postgresql.org; Sat, 23 Dec 2017 11:40:25 +0000 Received: from mail-qt0-x232.google.com ([2607:f8b0:400d:c0d::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eSiAB-0008D5-3p for pgsql-general@postgresql.org; Sat, 23 Dec 2017 11:40:25 +0000 Received: by mail-qt0-x232.google.com with SMTP id m59so38961984qte.11 for ; Sat, 23 Dec 2017 03:40:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=u1m3VQ5IwoXkEUasGjI9l255y7wDTev6VV/M31VALUA=; b=HdtHaDVQaQxdne6AdFgTg76I8TZNn1abBzVnVm8J0cMRRUubqyTiftOMETNQ/dLQwJ boaR7ZGhqgJqEcj45gz1Nmf6SPJ39o3NICixJO+LYXcxIU5UtrCN4vynvqqDfT6cReT7 mKa+Zu3Qp7aTwSVh3vVPnVj8VuGNdW5pW+ylQHaJSZXQiswbCqbyn5NMbYVj+IFbNGKH N8oL2hHpXKUNc+JBbt+pjLHxdvxKf4UX3C67t1bEGwzekY+x7neH7zwAVXOyoOMwp1dn LeyhP7WWh9EkNG4DK9rJQi/jrWHtBg1nhlNeVP1Xq2LlQ1hlAJtPuulHp4vl0GtAcFNw BmEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=u1m3VQ5IwoXkEUasGjI9l255y7wDTev6VV/M31VALUA=; b=JlcnA+U6L4K5Hc3W51hJdvtktWO9fbs3LSKilXCiXe+fi00sLv9IssHKekirKJTkzk vm0nGqc3AP/Pj0WJ0x3M+W+SjErB+RoThkxEyAaxzomv7eRqj0qurgPFYHcUsvgMW+lR 4GHnX3k4liLpzPCoQMgAL7XgnWaRjEMgP+N157kl61rVCti/3J+2DxGPAGAUR2jmDYSU EqJjvLpktU8OVxHz044vc3ATssNwSBYHdhfY0EQutdTxv5ECliUURhdynNn0K3h4v+6v ZZgk/OXyXVdAhAptCC7oPOrUJaTABQahlzfnye4iZQeLuFB7O8/vOibSyOCfTowkFC4S yneA== X-Gm-Message-State: AKGB3mK8B0rtmxhhx6yhtLE/uW3l6WHZ8L7dYRVijjSJNaRaVD5TgkrQ FY3/LcqgmKxeYjq5fDHaVAE+JNzIlHtyo+5gjz0a5boX0uWcKwwg4JJYfUXSfUOB8nPtXuZdP5s coSiy9vu/p3RNfnWFN0T+6W42uDc6C4bZWo39yGv/RqI87tuOdzgQcrXsfGobBCWPvVOiStu61y m+sD87X4E17xJoWQ== X-Google-Smtp-Source: ACJfBosc9dScSyfWmydcbU7s2pW0glG+yWPMojo2pHzwYzLF9az3T74/E+H8MABkv80OU1eVOAkkpA== X-Received: by 10.200.43.16 with SMTP id 16mr24699757qtu.44.1514029220545; Sat, 23 Dec 2017 03:40:20 -0800 (PST) Received: from alderaan.marques ([200.82.53.14]) by smtp.googlemail.com with ESMTPSA id e197sm12430187qka.50.2017.12.23.03.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Dec 2017 03:40:20 -0800 (PST) Subject: Re: Deadlock between concurrent index builds on different tables To: Jeremy Finzel , Postgres General References: From: Martin Marques Message-ID: Date: Sat, 23 Dec 2017 08:40:18 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk El 22/12/17 a las 18:53, Jeremy Finzel escribió: > I am attempting to build several indexes in parallel, guaranteeing that > I never build one on the same table twice.  I understand I can't build > two on the same table at once or I will get a deadlock.  However, I am > also getting a deadlock when doing several in parallel on different tables. On the same table you wouldn't get a dead lock as CREATE INDEX CONCURRENTLY takes a "share update exclusive lock" which is incompatible with vacuum and schema changes (and stronger locks), and a second CREATE INDEX CONCURRENTLY would be another schema change. So the first one would lock the second, which will have to wait until completion of the locking statement. > Here is an example of the error I am getting: > > 2017-12-22 15:48:07.669 CST,"CREATE INDEX",2017-12-22 15:48:02 > CST,8/32,0,ERROR,40P01,"deadlock detected","Process 4470 waits for > ShareLock on virtual transaction 4/262; blocked by process 4466. > Process 4466 waits for ShareLock on virtual transaction 8/32; blocked by > process 4470. > Process 4470: CREATE INDEX CONCURRENTLY index_foo_on_created_at ON foo > USING btree (created_at); > Process 4466: CREATE INDEX CONCURRENTLY index_bar_on_id ON bar USING > btree (id);","See server log for query details.",,,,"CREATE INDEX > CONCURRENTLY index_foo_on_created_at ON foo USING btree (created_at);",,,"" The only thing I can think of is that there's a foreign key from foo to bar(id), but the create index on bar shouldn't prevent a share lock on foo, even if such a restriction exists. -- Martín Marqués http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services