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 1iHr0a-0007oN-0w for pgsql-general@arkaria.postgresql.org; Tue, 08 Oct 2019 15:02:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHr0Y-0007Ok-OJ for pgsql-general@arkaria.postgresql.org; Tue, 08 Oct 2019 15:02:38 +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 1iHr0Y-0007OP-BP for pgsql-general@lists.postgresql.org; Tue, 08 Oct 2019 15:02:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iHr0W-0001cp-6J for pgsql-general@lists.postgresql.org; Tue, 08 Oct 2019 15:02:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x98F2Vqb020846; Tue, 8 Oct 2019 11:02:31 -0400 From: Tom Lane To: =?utf-8?Q?Artur_Zaj=C4=85c?= cc: pgsql-general@lists.postgresql.org Subject: Re: Table locking during backup In-reply-to: <02b701d57da3$57bea1f0$073be5d0$@ang.com.pl> References: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl> <20191007211930.r53ockkfjkx3gbzt@development> <02b701d57da3$57bea1f0$073be5d0$@ang.com.pl> Comments: In-reply-to =?utf-8?Q?Artur_Zaj=C4=85c?= message dated "Tue, 08 Oct 2019 08:40:58 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20844.1570546950.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 08 Oct 2019 11:02:31 -0400 Message-ID: <20845.1570546951@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?Q?Artur_Zaj=3DC4=3D85c?=3D writes: > First session: > BEGIN; = > set transaction isolation level repeatable read, read only; > lock TABLE gm.tableabc IN access share mode; > Second session: > BEGIN; > CREATE TEMP TABLE IF NOT EXISTS tableabc (Id BIGINT DEFAULT random()) IN= HERITS (gm.tableabc); > "CREATE TEMP TABLE" does not wait for anything. Waiting state is only wh= en I start third session with the same queries as in second. A bit of looking into pg_locks will show you that CREATE TABLE ... INHERITS takes ShareUpdateExclusiveLock on the table being inherited from. Per the manual, SHARE UPDATE EXCLUSIVE Conflicts with the SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This mode protects a table against concurrent schema changes and VACUUM runs. So that doesn't conflict with pg_dump, but would conflict with another session trying to INHERIT from the same table. AFAICS, pg_dump's lock isn't involved in that conflict at all. If you only notice blocking when pg_dump is running, it's likely not due to this lock in isolation, but the fact that pg_dump takes access-share locks on everything in sight. That can block sessions that are trying to do DDL, causing other things to queue up behind them, depending on what other locks those session(s) already hold. There's really no substitute for looking into pg_locks to see what's going on in cases like this ... regards, tom lane