创建表分区时,PostgreSQL检测到死锁错误

时间:2018-04-07 19:57:17

标签: postgresql deadlock

我正在使用PostgreSQL 10新的分区表功能。我有一个分区的父表看起来像这样

CREATE TABLE names (
    id integer,
    name varchar(64)
) PARTITION BY RANGE (id)

在将数据加载到数据库中时,我有许多节点并行创建分区表

CREATE TABLE names__139__119230558__120050888 PARTITION OF names
FOR VALUES FROM ('119230558') TO ('120050888')

然后不知何故,deadlock detected错误会像这样提出

ERROR:  deadlock detected
DETAIL:  Process 7802 waits for AccessExclusiveLock on relation 16401 of database 16390; blocked by process 7803.
    Process 7803 waits for AccessExclusiveLock on relation 16401 of database 16390; blocked by process 7802.
    Process 7802: 
          CREATE TABLE names__139__119230558__120050888 PARTITION OF names
          FOR VALUES FROM ('119230558') TO ('120050888')
    Process 7803: 
          CREATE TABLE names__94__80601867__81503664 PARTITION OF names
          FOR VALUES FROM ('80601867') TO ('81503664')

这是奇怪的部分,这并不奇怪,死锁意味着两个进程等待资源在其他进程保持彼此所需的资源时由其他进程释放,但是,看看死锁错误是否正确

Process 7802 waits for AccessExclusiveLock on relation 16401 of database 16390; blocked by process 7803.
Process 7803 waits for AccessExclusiveLock on relation 16401 of database 16390; blocked by process 7802.

它实际上正在等待相同的资源relation 16401 of database 16390,在这种情况下是names父分区表。所以问题是,当两个进程实际获取相同的资源时,如何检测到死锁?我认为第二个过程应该等待第一个过程完成。

0 个答案:

没有答案