Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qjLjg-00AY33-3a for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Sep 2023 15:37:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qjLjd-00D7uK-O0 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Sep 2023 15:36:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qjLjd-00D7u3-DG for pgsql-hackers@lists.postgresql.org; Thu, 21 Sep 2023 15:36:57 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qjLja-006Y9C-8W for pgsql-hackers@postgresql.org; Thu, 21 Sep 2023 15:36:56 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-50305abe5f0so1853023e87.2 for ; Thu, 21 Sep 2023 08:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695310613; x=1695915413; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gjyf7XX0zK93oUdcFZhXs+XGn2gzG3zZr8kgjVPDuqk=; b=akqpZ3fcXl2GJwkazurcKZuH9B5WJlXHRYOMqi6SUOAZlLlOtuoxl+yEghsHQli8E0 dwJ98wh6Ce1Vly42e/0tpEcqutvbthk8ncL9Rmuh/kfo2wZbTSCsP7s32zgaJqR55etv YtQ3u0cSyhV71qf39ks5t+6Erh+2mWK6FIGLzmAhXGM/3btIxXxhw10rezvXkB63rCDA KZvv768GlawZrWbWYXDkxYPOvlQIhgn3hje4ecuN7eSVhaTuBkSoxSqCuTh3wXaCkjJY qu2W/No/5s5Z40T6+UR+0cT3rWF3F6GIm6+nhQmwmNBFrMN8d4th7CyGxf8jYdDR9s1h LJ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695310613; x=1695915413; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gjyf7XX0zK93oUdcFZhXs+XGn2gzG3zZr8kgjVPDuqk=; b=sEil7388/mRt2WXTScQO5SgW2unSnsoS1BItUPNskdzj93Wilhh0R9ptgIl+cxhyMn HLEiPmlR2muk5LDx8GVAfl+dcEYANp+9Vg3w/4o/CmMuyhItprcxFHQnGXazggybgtKf cfbca5lYSHJJa7bFLzn3he/3b92MmBStQdMAnux4dzr4KIECDBwaH2kpZ5qWjFzYaV9U kbK3t2tF5ynNtfUBdvXcZhTCFjBNTn5V9jQ5rnTrSNhsUq0ixCHc2/djjULQsb3Wwgt6 De5xl/KRvfgjvYjWMU26W0rdbE8/Deg/Vfuh4O+JBYodHUTToBuM/fQuzUr01mnsSVeg GBvg== X-Gm-Message-State: AOJu0YyhFYfNi8XgXN6ygsRC1NQjKz8aOvJMROfd6F/D2FNxCKOQQfzs QCiExqmsZrutqC9TfupzQj9iNykr4a+p/XTVNOo= X-Google-Smtp-Source: AGHT+IEom6zHIccCDndP9m+BS5K/dEVWRntQcczBX5T814lOpqPfT083/Cjfrha2G9mdCfQk/VjTpNOgGqx0fkuoU3o= X-Received: by 2002:ac2:58cc:0:b0:503:34b8:20b with SMTP id u12-20020ac258cc000000b0050334b8020bmr4880058lfo.65.1695310612703; Thu, 21 Sep 2023 08:36:52 -0700 (PDT) MIME-Version: 1.0 References: <20230714151626.rhgae7taigk2xrq7@awork3.anarazel.de> In-Reply-To: From: Robert Haas Date: Thu, 21 Sep 2023 11:36:41 -0400 Message-ID: Subject: Re: New WAL record to detect the checkpoint redo location To: Amit Kapila Cc: Andres Freund , Dilip Kumar , Heikki Linnakangas , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Sep 21, 2023 at 4:22=E2=80=AFAM Amit Kapila wrote: > After the 0003 patch, do we need acquire exclusive lock via > WALInsertLockAcquireExclusive() for non-shutdown checkpoints. Even the > comment "We must block concurrent insertions while examining insert > state to determine the checkpoint REDO pointer." seems to indicate > that it is not required. If it is required then we may want to change > the comments and also acquiring the locks twice will have more cost > than acquiring it once and write the new WAL record under that lock. I think the comment needs updating. I don't think we can do curInsert =3D XLogBytePosToRecPtr(Insert->CurrBytePos) without taking the locks. Same for Insert->fullPageWrites. I agree that it looks a little wasteful to release the lock and then reacquire it, but I suppose checkpoints don't happen often enough for it to matter. You're not going to notice an extra set of insertion lock acquisitions once every 5 minutes, or every half hour, or even every 1 minute if your checkpoints are super-frequent. Also notice that the current code is also quite inefficient in this way. GetLastImportantRecPtr() acquires and releases each lock one at a time, and then we immediately turn around and do WALInsertLockAcquireExclusive(). If the overhead that you're concerned about here were big enough to matter, we could reclaim what we're losing by having a version of GetLastImportantRecPtr() that expects to be called with all locks already held. But when I asked Andres, he thought that it didn't matter, and I bet he's right. > One minor comment: > + else if (XLOG_CHECKPOINT_REDO) > + class =3D WALINSERT_SPECIAL_CHECKPOINT; > + } > > Isn't the check needs to compare the record type with info? Yeah wow. That's a big mistake. > Your v6-0001* patch looks like an improvement to me even without the > other two patches. Good to know, thanks. > BTW, I would like to mention that there is a slight interaction of > this work with the patch to upgrade/migrate slots [1]. Basically in > [1], to allow slots migration from lower to higher version, we need to > ensure that all the WAL has been consumed by the slots before clean > shutdown. However, during upgrade we can generate few records like > checkpoint which we will ignore for the slot consistency checking as > such records doesn't matter for data consistency after upgrade. We > probably need to add this record to that list. I'll keep an eye on > both the patches so that we don't miss that interaction but mentioned > it here to make others also aware of the same. If your approach requires a code change every time someone adds a new WAL record that doesn't modify table data, you might want to rethink the approach a bit. --=20 Robert Haas EDB: http://www.enterprisedb.com