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