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 1tAiQl-00HMh9-K9 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 04:23:06 +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 1tAiQj-002rOn-3P for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 04:23:05 +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 1tAiQi-002rOf-QB for pgsql-hackers@lists.postgresql.org; Tue, 12 Nov 2024 04:23:05 +0000 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAiQg-001QFS-SS for pgsql-hackers@postgresql.org; Tue, 12 Nov 2024 04:23:04 +0000 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3e606cba08eso3127955b6e.0 for ; Mon, 11 Nov 2024 20:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731385382; x=1731990182; 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=0zHdhH5fFHqxwRidO7rS2MQJDYpDFpXLQ9V6oHlpIjs=; b=W8/uMUtg2Ltiph4IPRLxfx7v3z6QT50Nhlul1wtvwpcytVDtsVULs+QDpy78OQhAzw 8sOIGRE9Qx8hZycez8+EmD2RxdTbXmwYOaIL9G8vCS9dodXfY4WNdk2Lhl/Q6VTvJ3h/ vi3Z/JMrT3zK1uWLDBDxYHGUIHIFxqjcSu4qwDsv6fqYXoH53d3YwYfVC4wl4Htd1gk2 9x8pAeC6xczyG7P175HR2hJkp+u6FFFzxh8lwGa4jozcmHbxjKad+xgryWQ+MlKJjSHq 9t8CyN+k7T9/CSs30WecalBfkx61vFUNm2+VHUt79BOUhXLG/+2vVqIgWrLVokgreTlZ MKUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731385382; x=1731990182; 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=0zHdhH5fFHqxwRidO7rS2MQJDYpDFpXLQ9V6oHlpIjs=; b=b7jyPkDoxnXaMD6HrfSFIzvkOI5nCiN6vevutN5GqwGEzny2RMEIOpP8owmHifFu86 BcU/Pw7AB4k8y/aAliW2MzTy8HPsbqc0OZk+syM+vkvLL4u///0+7Tr/z3aBEqOjlJ/m X0M8vQRIY/kFjPR2OcNSWTDHawpvH6suIlfeA1E2jun4ynpIcz+WNywm17gE0OOzEdR1 kFbTJEK/JeABuA1+oAsIFc8eLYbDDTbLVpEOpJ20ne4bHdVhylkPAIWytYXtFw5cQQXl AVob5kVVQ9kdDRylud5TlBmrvzmvJD/stPfH608gNkCwdU7CqyVk1OfOC5Dmvy6+XBfT Rktw== X-Forwarded-Encrypted: i=1; AJvYcCWN/46YNyLvGrLsUhMF29+ttcTtEPZWToJNwbrN11+JAqqfsDWUlR6iU7qqbiFn7AxkLAuhjvQBXTCj9Xv9@postgresql.org X-Gm-Message-State: AOJu0YxTSg3Mok45IysiLOlFLSzwjU52yNSv0xv8aw2/QK3pg/TM5qIV V3/0niJaDtTWjvO4g9wdpwAwT1BhRI72ldTrNy0bjWxqQPtqLL5oWbBFB6Za74PZSPTITVRE53T nxearYCgDte8VjA5MoC7GUPVymNs= X-Google-Smtp-Source: AGHT+IEkKkSP+EvAroDaht/cISuGGiRr+a4OMXWFdZFhDfWDgTkpiwd14sBOis39oKFmYsdcxbewzUVJVDBfmFrS96Q= X-Received: by 2002:a05:6808:d47:b0:3e6:1473:19d6 with SMTP id 5614622812f47-3e7aadfb190mr973977b6e.29.1731385382119; Mon, 11 Nov 2024 20:23:02 -0800 (PST) MIME-Version: 1.0 References: <9f7f4def-7ea8-4ad3-83e7-a8cc9d18c58a@wi3ck.info> <11ee3489-40ba-45d6-ba6a-7c3def725e84@vondra.me> In-Reply-To: <11ee3489-40ba-45d6-ba6a-7c3def725e84@vondra.me> From: Amit Kapila Date: Tue, 12 Nov 2024 09:52:50 +0530 Message-ID: Subject: Re: Commit Timestamp and LSN Inversion issue To: Tomas Vondra Cc: Andres Freund , "Zhijie Hou (Fujitsu)" , Aleksander Alekseev , pgsql-hackers , shveta malik , Jan Wieck 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 Mon, Nov 11, 2024 at 9:05=E2=80=AFPM Tomas Vondra wrot= e: > > Alternatively, we could simply stop relying on the timestamps recorded > in the commit, and instead derive "monotonic" commit timestamps after > the fact. For example, we could track timestamps for some subset of > commits, and then approximate the rest using LSN. > > AFAIK the inversion can happen only for concurrent commits, and there's > can't be that many of those. So if we record the (LSN, timestamp) for > every 1MB of WAL, we approximate timestamps for commits in that 1MB by > linear approximation. > > Of course, there's a lot of questions and details to solve - e.g. how > often would it need to happen, when exactly would it happen, etc. And > also how would that integrate with the logical decoding - it's easy to > just get the timestamp from the WAL record, this would require more work > to actually calculate it. It's only a very rough idea. > I think for logical decoding it would be probably easy because it reads all the WAL. So, it can remember the commit time of the previous commit, and if any future commit has a commit timestamp lower than that it can fix it by incrementing it. But outside logical decoding, it would be tricky because we may need a separate process to fix up commit timestamps by using linear approximation. IIUC, the bigger challenge is that such a solution would require us to read the WAL on a continuous basis and keep fixing commit timestamps or we need to read the extra WAL before using or relying on commit timestamp. This sounds to be a somewhat complex and costlier solution though the cost is outside the hot-code path but still, it matters as it leads to extra read I/O. --=20 With Regards, Amit Kapila.