Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAF9V-0001A6-St for pgsql-general@arkaria.postgresql.org; Tue, 17 Sep 2019 15:12:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iAF9U-0003QA-Pu for pgsql-general@arkaria.postgresql.org; Tue, 17 Sep 2019 15:12:24 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAF9U-0003Pj-Cx for pgsql-general@lists.postgresql.org; Tue, 17 Sep 2019 15:12:24 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAF9N-0005eG-PY for pgsql-general@lists.postgresql.org; Tue, 17 Sep 2019 15:12:23 +0000 Received: by mail-pf1-x429.google.com with SMTP id b128so2367085pfa.1 for ; Tue, 17 Sep 2019 08:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=9MZzMRyfKbvPt4+WRDap9qNU0T7ZaLJx6gzC6KfR0YU=; b=Aoft1EY82NNpxGyXrBCJv4t89JcZ0yw1SOVLKl5kr9zWuisksvHo/p9zd7tIDJLavV BxqZ1l3BT4LSkZxy8BsI+42Cw1kPbey/6fay6a/8yPb0K4QtVy6LVZ0xF+zXtB9pGlfw tS4tF9k/bXP+Gd5nqqzYZHI64vYploNLkt9lE+HCxMbm6/nC6kgqgSdc7TCtWqinpGJO P5UD6yTAzREjzSgCrmZt57EyJXGhTGfxlvh6xw9gihFSvwM0qawcrTEx/iyr6sFF1E4F hbznKLBgngPSQ6VTJx6Ab+lVEjH1XfHWWr3FDPvBQErghr0CRRfoXr5chLIGrsd8IXE/ 113Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=9MZzMRyfKbvPt4+WRDap9qNU0T7ZaLJx6gzC6KfR0YU=; b=Z4UoPTzivaRaMZ2Byb/AJlYI2S4XvORIJgKxYDy1LWMEPPWtxHJSsqNz5a7S3pPBJP 6vhk+B6WiKJf+C6WIwewnsaUGaDzsnpN5Mdu22kZDstc5veUqrSEzmvCDXQgXqQ+Tjuh CkRKTGaOV5CGIiWJ1Wy7Gm7jPDOa5LVrMOp65QyF49hssKn/NTJYc1ilNVKvMw9nJuuJ 6D0h3whDl0B4Elz9bRhRiUbVVFIOmbxtQzmTZ0jGEZOuf39V4pL71AylXeG00n6Pnqz5 ckcm/7+UeMKnqVc+a8YpJIab3WCJjHk3C+QVO7rZQHG3JWxYjwdvAj4vYGLHFyDF80ZB 42JQ== X-Gm-Message-State: APjAAAXmUHlcxdjqdqHoggSKDzC2m8un3sPJ/DqZ0ikuLvI6AEf2Wm3Y W+2JBSMqTZ4pbeOnzP3FYCDohSul X-Google-Smtp-Source: APXvYqzsTFDWSO710odY33+yX6kAQty6KPVu19mqMNx9J5CC1VDi0MxXHvDQVCaonaGMPYLqPus5Ow== X-Received: by 2002:a62:4d41:: with SMTP id a62mr4778849pfb.155.1568733134226; Tue, 17 Sep 2019 08:12:14 -0700 (PDT) Received: from [10.0.0.102] (c-73-223-6-106.hsd1.ca.comcast.net. [73.223.6.106]) by smtp.gmail.com with ESMTPSA id u11sm3140095pfm.113.2019.09.17.08.12.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Sep 2019 08:12:13 -0700 (PDT) Subject: Re: deadlock on declarative partitioned table (11.3) From: Kevin Wilkinson To: pgsql-general@lists.postgresql.org References: <80032bef-7c43-ae4c-a7cc-abb81e2ccadc@gmail.com> Message-ID: <1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com> Date: Tue, 17 Sep 2019 08:12:11 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <80032bef-7c43-ae4c-a7cc-abb81e2ccadc@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk disregard. problem found. i was locking the wrong table. On 9/16/2019 11:10 AM, Kevin Wilkinson wrote: > on linux, pg11.3, i have a (declarative) partitioned table with a > deadlock that i do not understand. one process does a copy to the > partitioned table. another process is executing a jdbc batch of > commands to "atomically" replace one of the table partitions. it has > the following commands (autocommit is off). > >    lock table foo; >    alter table foo detach partition foo_nn; >    alter table foo_nn rename to foo_nn_old; >    alter table new_foo_nn rename to foo_nn >    alter table foo attach partition foo_nn for values  from (...) to > (...); >    commit; > > the log says the deadlock is on the first alter table command but i > think that is misleading. i suspect what is happening is that the > explicit lock command attempts to lock each partition of foo in turn > rather than locking all partitions immediately. so it acquires some > locks in some unknown order while the copy acquires locks as needed. > so they deadlock. > > or is something else going on? is there a better way to atomically > replace a table partition? the table is partitioned by timestamp but i > don't think that matters. > > thanks, > > kevin > > >