Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ignfo-0007aQ-SA for pgsql-general@arkaria.postgresql.org; Mon, 16 Dec 2019 10:32:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ignfn-0004Ar-Et for pgsql-general@arkaria.postgresql.org; Mon, 16 Dec 2019 10:32:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ignfn-0004Aj-1G for pgsql-general@lists.postgresql.org; Mon, 16 Dec 2019 10:32:19 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ignfk-0000M3-LF for pgsql-general@lists.postgresql.org; Mon, 16 Dec 2019 10:32:17 +0000 Received: by mail-wr1-x433.google.com with SMTP id c14so6591175wrn.7 for ; Mon, 16 Dec 2019 02:32:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=n26.com; s=google; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=w9t6RulQZFpM4lhPTJV1mFEzaL8H1Z1vyYKCeJYn6gE=; b=IlGka0QO5ViZVU9TDA4AaaNl2lPHoabhF0euEOknX8w7Et0+gpcAuwIgUWwBQVsMkB zbXaSHGz1Tsh2Tks6WZy+b+KcEDJK3Vt2idX5oWzJGjCtfDfu/N1+zo1+11f96JK+yiQ c2sCw2iQ8VojaspJJ/ZFuW2R0B7tihZrcJzTcyW2LPptkbJ7j9yU1UNKXziYW4p0IZPd WB34OYEr0clxy2KXPXPICNz4hlDc/t6GEt3oQwwtCrVBGCKFp0i8CKdMuWhAe+fHhART SZzKT1Z25NLpQyJsolFTplDUPUGjA/KaGsMsWG5xX2dGXTjgkwxLAsqOOvy2YNAxOuaB QYMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=w9t6RulQZFpM4lhPTJV1mFEzaL8H1Z1vyYKCeJYn6gE=; b=ShcKPjHJFDkpn/I4tKQNmwu3stFktr1yVxMUWtPv9cDj6MimcDXLnvrHsGVYKWi0Yv ziI3sBd7HvTZwpqQzUpqMwJVAWilXyvDxhM/u97C07NzDLTh19jPT0V5ji8DjIo8UwjM oQHf92Ih6K6j8vfP9TbXzGUHrMRQG2s8ZM5zAzedIhYFwH7mSBEHFwytOUzhTi7DxvHP bshpT6U44tK8hMup+YkJFZE3S46OBFFArWNZQXADA49ssAiXPLAbSO5QiP1m2pSZ18k5 49KlOeVPB9RZ63Q52deO/pQzGY0hY67Wc00zyoiRhFWSbeYwnsiRSiAyosCioQ6HhkFL 5ByA== X-Gm-Message-State: APjAAAXN5DELprc8NKnCJyLzX+jGOcR2hy6M6uCvsd8lSlLBEykEGRa5 6qJaMdFmjp3F3/6kdvFp+bGlaoSbx2YD+Nv7m7KSX0BrHlXrTJ267cGtgfowu8bg2hQiHaxdUVm CTlKuUIjjjOXZMFjT8AUaaBU+XeUlI/uOIaMDalo+g+zv13UWVcwVJXAS+jEMfj6AxjsHf743mi XLlzfZkTFbtUT3e7EU X-Google-Smtp-Source: APXvYqx9HovGCMhUSxKFJcAa2gLB0E2ssAK9Xm35e8qmlzyRWPdpge2SGIt7IqFTdwkbap7vrtNOtA== X-Received: by 2002:a5d:52c4:: with SMTP id r4mr27711995wrv.368.1576492334172; Mon, 16 Dec 2019 02:32:14 -0800 (PST) Received: from [10.4.23.129] ([62.96.137.138]) by smtp.gmail.com with ESMTPSA id v3sm20795222wru.32.2019.12.16.02.32.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 02:32:13 -0800 (PST) From: Andrei Zhidenkov Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3601.0.10\)) Subject: Re: Race condition while creating a new partition Date: Mon, 16 Dec 2019 11:32:11 +0100 References: To: pgsql-general@lists.postgresql.org In-Reply-To: Message-Id: <728B91DD-5A10-4F46-89BF-B14DED93A7FD@n26.com> X-Mailer: Apple Mail (2.3601.0.10) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I think that I=E2=80=99ve got a deadlock (which is handled by `exception = when others` statements). But the problem is it occurs too fast. Is it = possible to get a deadlock faster than deadlock_timeout? It=E2=80=99s = set to 1s (default value) but it looks like I get it immidiately. Error = message I=E2=80=99m getting after removing the second exception handling = is the following: psycopg2.errors.DeadlockDetected: deadlock detected DETAIL: Process 33 waits for AccessExclusiveLock on relation 16453 of = database 16384; blocked by process 37. Process 37 waits for AccessExclusiveLock on relation 16453 of database = 16384; blocked by process 33. HINT: See server log for query details. CONTEXT: SQL statement " CREATE TABLE IF NOT EXISTS = prov_level_1.log_*__2019_12_16_10_25_46 PARTITION OF prov_level_1.log_* FOR VALUES FROM ('2019-12-16 10:25:46+00') TO = ('2019-12-16 10:25:47+00'); " > On 15. Nov 2019, at 11:49, Andrei Zhidenkov = wrote: >=20 > We use this code in order to automatically create new partitions for a = partitioned table (Postgres 10.6): >=20 > begin > insert into ; > exception when undefined_table then > begin > > -- A concurrent txn has created the new partition > exception when others then end; > -- Insert data into the new partition > insert into ; > end; > end; >=20 > 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? >=20 > Thank you. >=20 > =E2=80=94 >=20 > With best regards, Andrei Zhidenkov.