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 1i9vSP-0001I4-7u for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 18:10:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9vSM-0001Oa-VD for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 18:10:34 +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 1i9vSM-0001OP-JN for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 18:10:34 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9vSG-0002jH-F0 for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 18:10:34 +0000 Received: by mail-pg1-x534.google.com with SMTP id z12so436068pgp.9 for ; Mon, 16 Sep 2019 11:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=CDRr5nCLwuU1Fkkgddm/LDKffYkKmduEja0Q3XEqWso=; b=Xq1ozlIjaP/BRB/DuSbFUhYhRstGMn3Y21iIBAbDIlm37hPuPqBKnBNW03S8rsb7jL Irq6TOEJd2cSuwKQiS99DCIhOkQ18bmsMLrdUsGdob1Xv3dAqgSwksBOu+qGN1BlhBtD NVr47gI2re1/ag1jqjUqd7V/j8oLIBWVIaw4elh+v0Rml7/q4tz3iOl3ZwEYVuq8VCzz e36AuCvSgzcqqg+nPN0Dx8J2mGZ3WAgeh5MyCxyEds1GNTdJU/VzM/hjt6/r9dJYfqOb lgCBl7DzU7yHn1yIGTPkxG8c0Ln+6sz5cDB5VxVxHJ7vXHn4ZIEfvOzX5kkH97ZZRWSh kM8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=CDRr5nCLwuU1Fkkgddm/LDKffYkKmduEja0Q3XEqWso=; b=ZSRn7zC6wYTRHMy8FQtGL6UMysPq9YKVGr94DHyUvw/p4IXPuwQJB6Riy2mnxLEPoB cLylxXNHUznt/lw+/8sgJRZF819C8omTBc1QYLvvuP1wKodMdtqSqOihpkU6S9Gn7jfV aVvgtNcJuLeMzHZ4pq2zAIFM5zy576IA4/hWaWqAH2tVzOPG+PSXtACvorVhrvz2YhQX I5gbDOBwiwKOTMn8FshDBsgjcMHCUrkwk1GX/c9Rn02iiNPnmqjjclSDZdEwQ0J8N0Eq bZUkl+K4ccJGi5UGRCqSrNVtCbyW1V7dMFCPkVPmzcd0WfRdJ+Uh6ywCtkxctC7288Ay 75tw== X-Gm-Message-State: APjAAAVA4f0rf3JMQiGD5ni9bcpwErknvaoSEfx2UQNOrJrKXDIuDqyi dw7BlaeITh88wUFkJh7jIOi7sYsd X-Google-Smtp-Source: APXvYqzgYNu8bMqJ/z5Qe/8B5/7rBo2gzMAoKgsM4gf3yoPlSvLIh+s5kq/nQCzGvHCNbRGUHBM0PQ== X-Received: by 2002:a62:7710:: with SMTP id s16mr602245pfc.139.1568657425387; Mon, 16 Sep 2019 11:10:25 -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 c11sm71410958pfj.114.2019.09.16.11.10.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Sep 2019 11:10:24 -0700 (PDT) To: pgsql-general@lists.postgresql.org From: Kevin Wilkinson Subject: deadlock on declarative partitioned table (11.3) Message-ID: <80032bef-7c43-ae4c-a7cc-abb81e2ccadc@gmail.com> Date: Mon, 16 Sep 2019 11:10:22 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 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 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