Two concurrent non-pushdownable INSERT .. SELECT with RETURNING/ON CONFLICT might deadlock on replicated tables
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
See for the details: https://github.com/citusdata/citus/pull/5392#issuecomment-968737732
```SQL
-- create some tables with replication > 1
-- on v10.2 or master
SET citus.shard_replication_factor TO 2;
CREATE TABLE
time_series_events (event_time timestamp, event int, user_id int)
partition by range (event_time);
-- optional: partition management for timeseries workload is supported on
-- both distributed and non-distributed tables. In this example,
-- we use it on distributed tables
SELECT create_distributed_table('time_series_events', 'user_id');
-- first, create monthly partitions for the next 12 months
-- note that you can choose the interval based on your needs
-- we choose monthly partitions in this demo
SELECT create_time_partitions(table_name:='time_series_events',
partition_interval:= '1 month',
end_at:=now() + '12 months',
start_from:=now());
```
/tmp/f.sql
```SQL
insert into time_series_events SELECT '2021-11-01', i, i FROM generate_series(0,100)i RETURNING *;
```
pgbench:
```
pgbench -f /tmp/f3.sql -c4 -j4 -P 1 -T 120 postgres
pgbench: error: client 3 script 0 aborted in command 0 query 0: ERROR: deadlock detected
DETAIL: Process 29020 waits for ExclusiveLock on advisory lock [13236,0,102008,5]; blocked by process 29022.
Process 29022 waits for ExclusiveLock on advisory lock [13236,0,102008,5]; blocked by process 29020.
HINT: See server log for query details.
pgbench: error: client 0 script 0 aborted in command 0 query 0: ERROR: deadlock detected
DETAIL: Process 29021 waits for ExclusiveLock on advisory lock [13236,0,102008,5]; blocked by process 29022.
Process 29022 waits for ExclusiveLock on advisory lock [13236,0,102008,5]; blocked by process 29021.
HINT: See server log for query details.
pgbench: error: client 1 script 0 aborted in command 0 query 0: ERROR: deadlock detected
DETAIL: Process 29023 waits for ExclusiveLock on advisory lock [13236,0,102008,5]; blocked by process 29022.
Process 29022 waits for ExclusiveLock on advisory lock [13236,0,102008,5]; blocked by process 29023.
HINT: See server log for query details.
....
````
Contributor guide
Assessment
This issue has not been assessed yet.