From azajac@ang.com.pl Mon Oct 7 21:00:08 2019 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 1iHa75-0006Ea-5v for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2019 21:00:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHa73-0000hj-Rd for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2019 21:00:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHa73-0000ha-HI for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2019 21:00:13 +0000 Received: from cloudserver124499.home.pl ([188.128.182.39]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHa70-0002Xy-BR for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2019 21:00:13 +0000 Received: from host-188.117.168.42.static.3s.pl (188.117.168.42) (HELO DESKTOP5IS4FKS) by serwer1372326.home.pl (188.128.182.39) with SMTP (IdeaSmtpServer 0.83.292) id 41aac367032189a4; Mon, 7 Oct 2019 23:00:08 +0200 From: =?iso-8859-2?Q?Artur_Zaj=B1c?= To: Subject: Table locking during backup Date: Mon, 7 Oct 2019 23:00:08 +0200 Message-ID: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0220_01D57D62.F721EB80" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdV9S3OLAUGEer5eSPS3mvtwv+CcxA== Content-Language: pl List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multipart message in MIME format. ------=_NextPart_000_0220_01D57D62.F721EB80 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Hi, =20 I cannot reproduce some scenario I found in my PostgreSQL logs. =20 I have two connections/processes: =20 Process 24755 is standard pg_backup connection with: =20 . BEGIN; SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY . LOCK TABLE gm.tableabc; . COPY FROM gm.tableabc =20 Process 5969 is normal connection where I have: =20 LOG: proces 5969 still waiting for AccessExclusiveLock on relations 562888531 of database 16429 after 1000.066 ms DETAILT: Process holding the lock: 24755. Wait queue: 5969 =20 Query that is waiting (from proces 5969) is: =20 CREATE TEMP TABLE IF NOT EXISTS tableabc=20 ( Id BIGINT DEFAULT gm.top() ) INHERITS (gm.tableabc); =20 I cannot reproduce what pg_dump is doing that causes waiting on proces = 5969 (which lock is acquired and why). When pg_dump ends lock is released and proces 5969 continues. =20 I know that doing in two parallel connections: =20 BEGIN; =20 CREATE TEMP TABLE IF NOT EXISTS tableabc=20 ( Id BIGINT DEFAULT gm.top() ) INHERITS (gm.tableabc); =20 causes waiting state on second connection until the first finished, but pg_dump connection is read only.=20 =20 Could you suggest me which part of pg_dump (which query) might cause = that behaviour. =20 Artur Zaj=B1c ------=_NextPart_000_0220_01D57D62.F721EB80 Content-Type: text/html; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable

Hi,

 

I cannot = reproduce some scenario =A0I found in my PostgreSQL = logs.

 

I have two connections/processes:

 

Process = 24755 is standard pg_backup connection with:

 

…

BEGIN;
SET TRANSACTION ISOLATION LEVEL REPEATABLE = READ, READ ONLY

…

LOCK TABLE = gm.tableabc;

…

COPY FROM gm.tableabc

 

Process 5969 = is normal connection where I have:

 

LOG: proces = 5969 still waiting for AccessExclusiveLock on relations 562888531 of = database 16429 after 1000.066 ms

DETAILT: Process holding the lock: 24755. Wait queue: = 5969

 

Query that is waiting (from proces 5969) = is:

 

CREATE TEMP TABLE IF NOT EXISTS tableabc =

(

Id BIGINT DEFAULT gm.top()

) INHERITS (gm.tableabc);

 

I cannot = reproduce what pg_dump is doing that causes waiting on proces 5969 = (which lock is acquired and why). When pg_dump ends lock is released and = proces 5969 continues.

 

I know that = doing in two parallel connections:

 

BEGIN;

 

CREATE TEMP = TABLE IF NOT EXISTS tableabc

(

Id BIGINT DEFAULT = gm.top()

) INHERITS = (gm.tableabc);

 

causes = =A0waiting state on second connection until the first finished, but = pg_dump connection is read only…

 

Could you = suggest me which part of pg_dump (which query) =A0might cause that = behaviour.

 

Artur Zaj=B1c

------=_NextPart_000_0220_01D57D62.F721EB80-- From tomas.vondra@2ndquadrant.com Mon Oct 7 21:19:30 2019 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 1iHaPv-0006uc-Jd for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2019 21:19:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHaPt-0008Mv-Mn for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2019 21:19:41 +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 1iHaPt-0008Mc-9r for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2019 21:19:41 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iHaPp-0000H8-U9 for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2019 21:19:39 +0000 Received: by mail-wm1-x344.google.com with SMTP id a6so912683wma.5 for ; Mon, 07 Oct 2019 14:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=l+br1ufweB37Jza+/C6pk8J8yMdGnqiF8zOTPGPHeR0=; b=E5lT6t3CQ8l0uchZw5yv/J/Am/2EZCSA5417prHhZbJbtOf6Nih/LENDUSLMrLkEEn Nz8FG3FIQ79tywkc/MJfRavXWu433mJuJCcsbkzQl84i90GHZEvAlhwtkbju0YOjs1sr At3VlMmGQKE5HPvhCDqJkrPVCEOSontu3nJzqfYHVwItwcGa9Yu/HVk28c1vyKClYTwt wtQzD4P2XHANfvMTcfii6bwxz1PGUeqcNhJitfUP+azC4/vNeRbZ7BrT3CiZPF/BEYd/ hiazFKBNyqiuXZs/8iN3cD3KOZ8uM8id7H3PCeLnYhz4zANgWacOCjyhWNtQe0ewtzGx tIEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=l+br1ufweB37Jza+/C6pk8J8yMdGnqiF8zOTPGPHeR0=; b=QKZRTUB8kfjA1dR+QtD2Upp3JJyhLEkQt5grclo/UYu7PeJOUGLWv74W7TiXDNpap6 DN4xShZL8xf3bQfJRo9b6rNGgwjy0mktpl4sMQCfcbvHUzRdIWE9n8RH9KNJKc1W3iJu Xg/9tUY4HPeNJf8O/z+5vybBPDWWRpFJAKAENXAARM/oZadkVlwV3/sNRljr1qvWh6oD Ug056jN9iKhUcz2ouHj0/pP81oqEcKJLiuHLtOB4mBdOjuOlLwTLIvEN/LdkKvwru0D/ GUcZRCnkKmPKHM+vCB/mo/LxDmoqSQ+1hwm5xdIjNxARjqGD9wtcamY2u6OuOaMzz1Cm tvHw== X-Gm-Message-State: APjAAAWaSK7M2Fe3D5bkucTaSyfEyDo1nhUKqoBZcj0ZtrdLUU0w09yh byTKv1GsmrtHmxwhihfptzUlMhVuxJM= X-Google-Smtp-Source: APXvYqwXlALMc+I6Y5xfntLKk5bM1yo5465MmvA89hvECjYrPs+9sVJ4UuR6cAPf1F8Xo6S4ydCOEw== X-Received: by 2002:a7b:cc91:: with SMTP id p17mr969205wma.81.1570483176434; Mon, 07 Oct 2019 14:19:36 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id r2sm15114455wrm.3.2019.10.07.14.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 14:19:31 -0700 (PDT) Date: Mon, 7 Oct 2019 23:19:30 +0200 From: Tomas Vondra To: Artur =?utf-8?B?WmFqxIVj?= Cc: pgsql-general@lists.postgresql.org Subject: Re: Table locking during backup Message-ID: <20191007211930.r53ockkfjkx3gbzt@development> References: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Oct 07, 2019 at 11:00:08PM +0200, Artur ZajÄ…c wrote: >Hi, > > > >I cannot reproduce some scenario I found in my PostgreSQL logs. > > > >I have two connections/processes: > > > >Process 24755 is standard pg_backup connection with: > > > >. > >BEGIN; >SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY > >. > >LOCK TABLE gm.tableabc; > >. > >COPY FROM gm.tableabc > > > >Process 5969 is normal connection where I have: > > > >LOG: proces 5969 still waiting for AccessExclusiveLock on relations >562888531 of database 16429 after 1000.066 ms > >DETAILT: Process holding the lock: 24755. Wait queue: 5969 > > > >Query that is waiting (from proces 5969) is: > > > >CREATE TEMP TABLE IF NOT EXISTS tableabc > >( > >Id BIGINT DEFAULT gm.top() > >) INHERITS (gm.tableabc); > > > >I cannot reproduce what pg_dump is doing that causes waiting on proces 5969 >(which lock is acquired and why). When pg_dump ends lock is released and >proces 5969 continues. > > > >I know that doing in two parallel connections: > > > >BEGIN; > > > >CREATE TEMP TABLE IF NOT EXISTS tableabc > >( > >Id BIGINT DEFAULT gm.top() > >) INHERITS (gm.tableabc); > > > >causes waiting state on second connection until the first finished, but >pg_dump connection is read only. > Not sure why would it matter that the pg_dump connection is read-only, this is about locking because pg_dump needs to ensure the schema does not change while it's running. pg_dump does not do LOCK TABLE gm.tableabc; but LOCK TABLE gm.tableabc IN ACCESS SHARE MODE; Which should be visible in pg_locks system view. And it does conflict with the ACCESS EXCLUSIVE mode, used by the second query. > > >Could you suggest me which part of pg_dump (which query) might cause that >behaviour. > It's this line: https://github.com/postgres/postgres/blob/master/src/bin/pg_dump/pg_dump.c#L6676 regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services From azajac@ang.com.pl Tue Oct 8 06:40:58 2019 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 1iHjBA-00047Y-7Z for pgsql-general@arkaria.postgresql.org; Tue, 08 Oct 2019 06:41:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHjB8-00008x-Tz for pgsql-general@arkaria.postgresql.org; Tue, 08 Oct 2019 06:41:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHjB8-00008S-K9 for pgsql-general@lists.postgresql.org; Tue, 08 Oct 2019 06:41:02 +0000 Received: from cloudserver124499.home.pl ([188.128.182.39]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHjB6-0000j2-FS for pgsql-general@lists.postgresql.org; Tue, 08 Oct 2019 06:41:02 +0000 Received: from host-188.117.168.42.static.3s.pl (188.117.168.42) (HELO DESKTOP5IS4FKS) by serwer1372326.home.pl (188.128.182.39) with SMTP (IdeaSmtpServer 0.83.292) id 7669b71b202a8aa0; Tue, 8 Oct 2019 08:40:58 +0200 From: =?utf-8?Q?Artur_Zaj=C4=85c?= To: References: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl> <20191007211930.r53ockkfjkx3gbzt@development> In-Reply-To: <20191007211930.r53ockkfjkx3gbzt@development> Subject: RE: Table locking during backup Date: Tue, 8 Oct 2019 08:40:58 +0200 Message-ID: <02b701d57da3$57bea1f0$073be5d0$@ang.com.pl> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQE+0JW5D9Rpi2eYBc1OsvvrSBIzPQKFmNfHqGl1b6A= Content-Language: pl List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > Not sure why would it matter that the pg_dump connection is read-only, = this is about locking because=20 > pg_dump needs to ensure the schema does not change while it's running. > pg_dump does not do > > LOCK TABLE gm.tableabc; > > but > > LOCK TABLE gm.tableabc IN ACCESS SHARE MODE; > > Which should be visible in pg_locks system view. And it does conflict = with the ACCESS EXCLUSIVE mode, > used by the second query. My mistake. I cited the log incorrectly - of course should be (and there = was) LOCK TABLE gm.tableabc IN ACCESS SHARE MODE.=20 After all, your answer does not explain everything. I tried to reproduce = the minimum commands: First session: BEGIN;=20 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()) = INHERITS (gm.tableabc); "CREATE TEMP TABLE" does not wait for anything. Waiting state is only = when I start third session with the same queries as in second. Maybe "LOCK TABLE ... IN ACCESS SHARE MODE" is the answer, but with = correlation with some other query or setting setted by pg_backup. Table gm.tableabc is created with "create table gm.tableabc (x int = default random());" AZ From tgl@sss.pgh.pa.us Tue Oct 8 15:02:31 2019 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