Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOomz-00011J-Ax for pgsql-novice@arkaria.postgresql.org; Tue, 23 Mar 2021 21:42:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOomy-0004Rc-3S for pgsql-novice@arkaria.postgresql.org; Tue, 23 Mar 2021 21:42:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOomx-0004RV-PU for pgsql-novice@lists.postgresql.org; Tue, 23 Mar 2021 21:42:11 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lOomr-0006qH-1g for pgsql-novice@lists.postgresql.org; Tue, 23 Mar 2021 21:42:10 +0000 Received: by mail-ej1-x636.google.com with SMTP id u9so29520142ejj.7 for ; Tue, 23 Mar 2021 14:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=k62/1r0GdF8pgeb6z5uSaK9++DXNHqhkgnH/zXaX56U=; b=PC7OWME3wt99UzebXnKLKy5OtzE/12jauQBWlRtRz9X9ltU5jT/5JTwGZyMUcuE93s yaDkZla67WbjynQ0S/a1ztreb5g6EwUbh3z9Fo0mPKjKpdocoEV+R33SosqJVsUK148i cmTwDN65eFXJsVRO/+qnh+WRoB6uVpxzfNOTgQRBACDb7LTuROAZbGhwTUrJfeAi/gbN k9QXmih9KYysSu4vGkZv2QfkJ6Fk0jloxhAj/nTJvtI/865hQLLWRruuSj6NfTYtGC2Q g1QLJJc6NybuTjCAG+0cul4Q84JOOSsczbMyzG1fg0xS7ivgi3U6TmFEAvTkdUYQ0O6/ fBSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=k62/1r0GdF8pgeb6z5uSaK9++DXNHqhkgnH/zXaX56U=; b=PfRHgs0T0AaVzremeVK6xPHqPzz4ipKW0+lXF3FosOO6vx7ttjrlm2b4m+NX0ahr8P OMVs1OGcDtGQeUiQFhSx/37Re5J1o6QcpeRgySowdC3YuADg6myT95Vq5eX7F1Kw0ue8 /wTVnFMpsrYPEhajhz+ixxAOVTi0qzQUlGPPHb/HUnEjSliSa/nFuXy5TWMqCHW136PR 5QylZUpXcM/px84lmCoQj7MkIfQdSGK/zsMeL0XCuY35fddsKLYiV/OckXBi6Bh2VGYH Mt94nQVzrHIycObFCFDYLV5sjyw+TONKocVrfUV1Hb3LUWoNM7RL+/vqIp/B972M5BAY chGQ== X-Gm-Message-State: AOAM5313B1BaGJ1W5jdGEExx4CGGn/4NdOwCwrMLvpY0wG5ln6QJ6f/A I/YdtKH8NwOodeoi77gKnm//Wg== X-Google-Smtp-Source: ABdhPJy/G3G2R+pR4JV5ehqyqcImARACkaEspcQXYpNvK3jOaUbFS6eoxg7FVA3yOPdKL7D6cwG7lw== X-Received: by 2002:a17:907:ea3:: with SMTP id ho35mr237986ejc.219.1616535723089; Tue, 23 Mar 2021 14:42:03 -0700 (PDT) Received: from localhost.localdomain ([86.56.204.198]) by smtp.gmail.com with ESMTPSA id o20sm112609eds.65.2021.03.23.14.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 14:42:02 -0700 (PDT) Message-ID: <45d321c969ccd8d0b41f23efc2bcf6e41dde0e52.camel@cybertec.at> Subject: Re: Understanding recovery conflict due to bufferpin From: Laurenz Albe To: vinay kumar Cc: pgsql-novice@lists.postgresql.org Date: Tue, 23 Mar 2021 22:42:01 +0100 In-Reply-To: References: <4ac7f69b5881b8fe67c15f4f62f979839dd886f6.camel@cybertec.at> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2021-03-23 at 22:48 +0530, vinay kumar wrote: > My query is does the buffer pin pins block present in shared buffers(assuming the > block is already read into memory previously) or it's pinned to the block at the OS level? > > Also have another query: > > Do we have any queue mechanism to attain buffer pins on a block? > > To provide an example: > > Let's say, I need to read tuples present in a block by multiple backends. > Shouldn't the backends wait in FIFO order to hold pins on the block? > > To give you an example, if I have the few backends requesting access to a block > in the following order: > > -> backend 1: reads the tuples from block > -> backend 2: reads the tuples from block > -> backend 3: reads the tuples from block > -> WAL replay: waiting to modify block either due to replaying change or Vacuum operation. > > Will the order of requests to access blocks be maintained in a cache or any other memory area? > > If possible to implement lazy cache invalidation (invalidating blocks in buffer cache > when no conflicts query is run), it would be great and helpful to lots of users who query > data from standby to avoid recovery conflict and don't have to re-run the entire query once > again consuming resources. A pin is not a lock, it just protects a page from being swapped out of cache. Several backends can pin the same page simultaneously. The buffer pin is an internal PostgreSLQ concept and has nothing to do with the operating system. I recommend that you start by reading the appropriate README: https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/storage/buffer/README That explains the concepts better than I could. The key sentence when it comes to replication conflicts is this: To physically remove a tuple or compact free space on a page, one must hold a pin and an exclusive lock, *and* observe while holding the exclusive lock that the buffer's shared reference count is one (ie, no other backend holds a pin). Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com