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 1u1UIo-003EnN-AR for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Apr 2025 18:01:02 +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 1u1UIm-0008U5-P6 for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Apr 2025 18:01:01 +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 1u1UIm-0008Mz-6V for pgsql-hackers@lists.postgresql.org; Sun, 06 Apr 2025 18:01:00 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u1UIk-003KCY-1m for pgsql-hackers@postgresql.org; Sun, 06 Apr 2025 18:00:59 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2ff784dc055so3030501a91.1 for ; Sun, 06 Apr 2025 11:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1743962457; x=1744567257; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=oWPgTv3wPl/3g2YmPwf3GhIRKUDbmZScD5i8LDPQyoo=; b=USMCbohNe8IQMO6sCFfrSSyUQmMBORgE7ZlUL8BL+7S9U+wxHsGG3wKixyUqht87NA R45cLzFCz04hvS0wX05p3JcvQCoXX4pDTYXuvEV1ELk4WjaQLJkPzt3ndH/RI7TKL1M/ 0mHaiWVcRx1kOHtUoCJxbK/Cs0wH2AsShfPhc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743962457; x=1744567257; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oWPgTv3wPl/3g2YmPwf3GhIRKUDbmZScD5i8LDPQyoo=; b=mxeMNfzWedBS/iI8OgNRyJvKNk+ck5D1QfRrozbmNEymbODukf9lcL7Z/eV9xdEdGo +FhhMtM6YK+tLDmViiq6fV3QzaDDIe/lh6dL0iYXAHdOxbkeraiomUDKNgA9RylsiS60 gpvj5SEaxHXolFaF1s925xlc9QkaUSaWTcK1Vodk8Ls9WnEEv3w4uM7YdjlfWSMBOBUx Ckw+TzBX2SpuxlE+dz1y1LMYkMobdtKT44Ng7+d0BzDefK8gzhi2x8wC4E5idgWw3rZe kIYdMAg3BqKtFoqI+9ThVggN/AiE7DzFRoyShhmItcfgmOfi8W63jl3Jiw0f2bGoNSu2 joYg== X-Gm-Message-State: AOJu0YxhXODW/P19j30tRt15m8YTPw2XGi4LYPqfoK9xQ8ltbneWav1l hnI+zsiqqZiPlvFxkATJADZRHopVL/JgjAMZfERawFXEUE90QQ1KdZMN3m0jdm1HbGOOBBgfkso = X-Gm-Gg: ASbGncsXgFk7ST+IAn5829Z3gBH8qFSd8lysvOLeD4XFwnoy+T0X4gUHj3/YzOxRzah 9x7Q2fGl7WdxdcFRkFEz96QH0pHl8Gf2rjeupjqAgXtliXw+gHNYbgS9ZujyYieBNWdmhQkhFkL H0GO8Tsy0Q+DC9b25odwV+0EY2FVnaFtp69/HTzaW2/r14XCSpiSTXs4K7yQYNqyD4YZ+AsN7YC pPB63uBhxSdsHv0ATcViMQ5eStf4/K0Ntd2YRbZ4PZa/WZcS6hSjU/x/chZlPBq1sfa7WyjjIuT hTZ4xf8ZHiqYD1QuZjdDHjotXmhL2BVOrLhVdQ5KGpYWUZDwpMfA X-Google-Smtp-Source: AGHT+IEiC7h4hWEAXpj8vvx+mlrgSICWmRn8v+7GWEb+7G3cYRYloOT+znUn9Gyp4UHZu0wru01B2A== X-Received: by 2002:a17:90b:1cc8:b0:2ff:6e72:b8e2 with SMTP id 98e67ed59e1d1-306af7b22c8mr7014811a91.31.1743962457228; Sun, 06 Apr 2025 11:00:57 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af9bc2cfbb2sm5984101a12.14.2025.04.06.11.00.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Apr 2025 11:00:56 -0700 (PDT) Date: Sun, 6 Apr 2025 11:00:54 -0700 From: Noah Misch To: pgsql-hackers@postgresql.org Subject: Re: datfrozenxid > relfrozenxid w/ crash before XLOG_HEAP_INPLACE Message-ID: <20250406180054.26.nmisch@google.com> References: <20240620012908.92.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240620012908.92.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 Wed, Jun 19, 2024 at 06:29:08PM -0700, Noah Misch wrote: > https://postgr.es/m/20240512232923.aa.nmisch@google.com wrote: > > Separable, nontrivial things not fixed in the attached patch stack: > > > - Trouble is possible, I bet, if the system crashes between the inplace-update > > memcpy() and XLogInsert(). See the new XXX comment below the memcpy(). > > That comment: > > /*---------- > * XXX A crash here can allow datfrozenxid() to get ahead of relfrozenxid: > * > * ["D" is a VACUUM (ONLY_DATABASE_STATS)] > * ["R" is a VACUUM tbl] > * D: vac_update_datfrozenid() -> systable_beginscan(pg_class) > * D: systable_getnext() returns pg_class tuple of tbl > * R: memcpy() into pg_class tuple of tbl > * D: raise pg_database.datfrozenxid, XLogInsert(), finish > * [crash] > * [recovery restores datfrozenxid w/o relfrozenxid] > */ > > > Might solve this by inplace update setting DELAY_CHKPT, writing WAL, and > > finally issuing memcpy() into the buffer. > > That fix worked. I pushed that as commit 8e7e672 (2024-10-25). I now think DELAY_CHKPT_START is superfluous here, per this proc.h comment: * (In the * extremely common case where the data being modified is in shared buffers * and we acquire an exclusive content lock on the relevant buffers before * writing WAL, this mechanism is not needed, because phase 2 will block * until we release the content lock and then flush the modified data to * disk.) heap_inplace_update_and_unlock() meets those conditions. Its closest precedent is XLogSaveBufferForHint(), which does need DELAY_CHKPT_START due to having only BUFFER_LOCK_SHARED. heap_inplace_update_and_unlock() has BUFFER_LOCK_EXCLUSIVE, so it doesn't need DELAY_CHKPT_START. I'm considering two options: 1. Stop using DELAY_CHKPT_START in heap_inplace_update_and_unlock(). 2. Add a comment. BUFFER_LOCK_EXCLUSIVE entitles heap_inplace_update_and_unlock() to omit DELAY_CHKPT_START. Instead, the function elects to keep itself aligned with XLogSaveBufferForHint(), to make analysis simpler. I'm leaning toward (2), since inplace update isn't frequent enough that it needs to pursue small optimizations. Would anyone strongly prefer (1)?