pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
deadlock on declarative partitioned table (11.3)
2+ messages / 1 participants
[nested] [flat]

* deadlock on declarative partitioned table (11.3)
@ 2019-09-16 18:10 Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  2019-09-17 15:12 ` Re: deadlock on declarative partitioned table (11.3) Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Kevin Wilkinson @ 2019-09-16 18:10 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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








^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: deadlock on declarative partitioned table (11.3)
  2019-09-16 18:10 deadlock on declarative partitioned table (11.3) Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
@ 2019-09-17 15:12 ` Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Kevin Wilkinson @ 2019-09-17 15:12 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-09-17 15:12 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16 18:10 deadlock on declarative partitioned table (11.3) Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
2019-09-17 15:12 ` Kevin Wilkinson <w.kevin.wilkinson@gmail.com>

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