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 1rVgU5-000jJD-0a for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Feb 2024 23:28:41 +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 1rVgU1-008Sc1-9q for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Feb 2024 23:28:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rVgU0-008Sbt-QP for pgsql-bugs@lists.postgresql.org; Thu, 01 Feb 2024 23:28:37 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rVgTv-004bUt-VO for pgsql-bugs@postgresql.org; Thu, 01 Feb 2024 23:28:35 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-214410e969cso1231377fac.0 for ; Thu, 01 Feb 2024 15:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1706830111; x=1707434911; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=JRndSVN1VadoTudNtnMjqRnZDpgGWwJY0j3H9RJoY94=; b=Km+AGYtgHRtWwx56t81JrPC24CEabxIWgt47RF+quFD+jbpvXavIpO0XbBJ6H8VrMf Y3XVt3BadDR+unP0oVtIVomNWxYME4hRND38PABjP71XJBAxQSLIH/Mi3gYiKiSSWNkp OSCbm9dGPtkoS3RdIVmz/cyV6ZzAAqRgg95pc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706830111; x=1707434911; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JRndSVN1VadoTudNtnMjqRnZDpgGWwJY0j3H9RJoY94=; b=FdigIeXJNiW+M6gRJeTNZ4kOdplGZeOQlg/uOuzkCW4bpp39KYggSo55w7YXJDujqT QDrQqVqI7PXGHlmhdG5ft3prG+6onAJavUUz3RL9rtwxCLN6IcvZCIhFwvn8A3K934m9 G+EdiLGdfueRlO0vrSGcXoBScvocrIvUmFjTSwhinNEmOBu1G7p3m9GMQgANrTEliTwM znX9Zu+3RpwegMsNRMLQ119Hgb1DwyMXYC+rm3V46055YMSN4JPeyjr9A+pwXJ5eDfJ5 WfPg4dCvKsGyORY7Yas6y44+vI21zuXOVBlxFD4g8lYkZXEah2MbnHKbSJPKTGQry0nw VFaA== X-Gm-Message-State: AOJu0YwJJ51Mbj5VGAq+njJwoETXa030xXhAfCshIi8k7XGqgR87wW8l GPCieTEVVlb8J+foiJbDBzRiqyt2NLHxogLnIfDcYxSpX7/tQGXslSPVeliUTBj9xlsfFcUBMoY = X-Google-Smtp-Source: AGHT+IGIv/kZrJF2GunBjsCQXMAn4HEJTZ5mVsuU7MDgQojC/U94J+4oS2R2dA1KhJOMdfpwppypXQ== X-Received: by 2002:a05:6870:a551:b0:214:c0ff:2d5d with SMTP id p17-20020a056870a55100b00214c0ff2d5dmr212163oal.23.1706830110917; Thu, 01 Feb 2024 15:28:30 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVK5AfP1RQth+peKSY4x0CyPTkOZqNq7NzZY3RvRcKkBR0sRXaySFQI3bBq5GzSQV4gYURLvOWMjywLZgaTLO9w2FrNzEI= Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id zd31-20020a056871279f00b00218496d80b7sm190793oab.29.2024.02.01.15.28.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Feb 2024 15:28:30 -0800 (PST) Date: Thu, 1 Feb 2024 15:28:28 -0800 From: Noah Misch To: pgsql-bugs@postgresql.org, dilipbalaut@gmail.com Cc: robertmhaas@gmail.com Subject: Re: STRATEGY=WAL_LOG missing checkpoint interlocks and sync Message-ID: <20240201232828.b1.nmisch@google.com> References: <20240130195003.0a.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240130195003.0a.nmisch@google.com> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jan 30, 2024 at 11:50:03AM -0800, Noah Misch wrote: > (1) CreateDirAndVersionFile() uses a code sequence: XLogInsert(), XLogFlush(), > write(PG_VERSION). This is missing the interlock with checkpoints, which > pd_lsn usually secures. This breaks when one takes a base backup between the > XLogInsert() and the write(). The transam/README "action first and then write > a WAL entry" strategy works well. createdb_failure_callback() will remove the > whole directory on failure. > > (2) RelationMapCopy() reasons that it doesn't need RelationMappingLock. > CheckPointRelationMap() relies on RelationMappingLock to avoid completing a > checkpoint between the WAL and the sync. A base backup taken in the middle of > write_relmap_file() has no relmap after recovery. > > (3) CreateDirAndVersionFile() populates the PG_VERSION file without syncing > it. An OS crash after the next checkpoint may leave PG_VERSION empty or > missing. Let's fsync the file immediately. I used LazyFS to confirm the > defect and fix. Though I was skeptical about adding a wait event in back > branches, I plan to do so anyway. Commit 368ffde got away with it, and we do > have this pattern of the sync event being separate from the write event. Pushed at commit 0b6517a.