Race condition while creating a new partition

From: Andrei Zhidenkov <andrei(dot)zhidenkov(at)n26(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Race condition while creating a new partition
Date: 2019-11-15 10:49:50
Message-ID: FDFDBCC0-3AC5-44A7-A69F-D607CBA5A662@n26.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

We use this code in order to automatically create new partitions for a partitioned table (Postgres 10.6):

begin
insert into <partitioned_table>;
exception when undefined_table then
begin
<create_unexistent_partition>
-- A concurrent txn has created the new partition
exception when others then end;
-- Insert data into the new partition
insert into <partitioned_table>;
end;
end;

As far as I understand we should always have a new partition created either in current or in concurrent transaction but today we faced the problem when we failed to insert data due to a partition nonexistence for a small period of time. Have I missed something?

Thank you.

With best regards, Andrei Zhidenkov.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message PegoraroF10 2019-11-15 14:31:09 naming triggers for execution
Previous Message Arup Rakshit 2019-11-15 10:01:26 Create array of data from JSONB in PG 9.5