pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: deadlock on declarative partitioned table (11.3)
Date: Tue, 17 Sep 2019 08:12:11 -0700
Message-ID: <1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com> (raw)
In-Reply-To: <80032bef-7c43-ae4c-a7cc-abb81e2ccadc@gmail.com>
References: <80032bef-7c43-ae4c-a7cc-abb81e2ccadc@gmail.com>

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
>
>
>





view thread (2+ messages)

Message-ID: <1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com>
Permalink:  ../1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com/
Also on:    postgresql.org/message-id/1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: w.kevin.wilkinson@gmail.com
  Subject: Re: deadlock on declarative partitioned table (11.3)
  In-Reply-To: <1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com>
  References: <80032bef-7c43-ae4c-a7cc-abb81e2ccadc@gmail.com> <1d9cba89-7a52-1203-acc2-364c011d453c@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox