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 1tAs8q-000Z6n-38 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 14:45:15 +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 1tAs8n-0077gS-K4 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 14:45:14 +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 1tAs8n-0077aD-6j for pgsql-hackers@lists.postgresql.org; Tue, 12 Nov 2024 14:45:13 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAs8k-001YL4-Bk for pgsql-hackers@postgresql.org; Tue, 12 Nov 2024 14:45:13 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5ee461f5dedso3241427eaf.0 for ; Tue, 12 Nov 2024 06:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wi3ck-info.20230601.gappssmtp.com; s=20230601; t=1731422709; x=1732027509; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=NNFxgTE/yfsw1Jhw5IcTHXumeyRffxdizwZ/P+mnio8=; b=oij2lFgRQsNkEq/LU92YOjHrAScXeVzohuKKUKK/MA2Exq9uh75cuhB2Kj8dOBgMD7 EUV77KdoQPyNPSDPD5Bg94onh8HcDUzwLhvrFr1f9lp2MLQDxcjyjKCyROA8lNhPRGud +ZslCBQGAbtpdQpSTgq/yhnJusgy9+PMHCdbvb/vTPFz+ygNsQ6wYzh/YyLByIvAOj2q +3wmIeTqO7OiF2JxN3mL0DzUccXclCSByGnpVOV9SnbeWP0lgPmiEAm54+qk9NsSkVyJ U/7TCe7+ezPXdn7K3iZHBZP1GyveLFsAZiGNOz7hcEbDckd3pjU4v8yDyAVpirn9MnYR h0HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731422709; x=1732027509; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NNFxgTE/yfsw1Jhw5IcTHXumeyRffxdizwZ/P+mnio8=; b=lrf00I8U2sbvg+u7fAgDjTj4wLHWgK40hpFcbuxWLMKLc3afZDIHdqBdtGAtEx1Coq k2LxqH1pHEsEoRF8HWw/2M3GuVXMfVof+J9bICdnGY5hv8dnLm6pQbvhuB/GiOVTf2NV grO/ebJWIHOCA4DDalj3r1HSLiMPxTqzjiQVguSqbtm+9HOsRVYiEXd2apYCZs48DXJo lLOjC9OcGJAfpecVoK6w56aNDX1d+1LGmv0EC5zc3DzaZ/9YszbO7prKeTKouggkTyYH 1QX76ZboU2qavnEsj23B1OPrPB8wQnXkxAVZjYHswhaJstS+WfKjRWq2VfxcHW1d+aLs zQbg== X-Forwarded-Encrypted: i=1; AJvYcCWDff/opLtCaMYrdmpjHfAREvHYPVwipJhhdpVU7SHIabMJhI1L0eCz1mHyFrfyXsBGxNO8K0VyFs7Egto2@postgresql.org X-Gm-Message-State: AOJu0YzC0fU7irIonUZNGUyt9FXv8HG6Xj24TesbIzDDD7S5lJjBi9Qk eGTAX5d/hqjJ5+7msZYxdd2ks0INWRYX6l1R4Lx9wfsi8xTefhFL9gzUnuvdJEc= X-Google-Smtp-Source: AGHT+IGpbQrYxaMucpkAIRLxmv8kkaoTfhyn3xQuU3CL4RsznJBMm96cV8DC2+5F9U+8ar8jg/7U2g== X-Received: by 2002:a05:6358:850e:b0:1c3:7358:3d1c with SMTP id e5c5f4694b2df-1c641f3cf89mr654271155d.19.1731422709429; Tue, 12 Nov 2024 06:45:09 -0800 (PST) Received: from [172.21.0.10] (pool-108-16-53-81.phlapa.fios.verizon.net. [108.16.53.81]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff3df53fsm75625381cf.8.2024.11.12.06.45.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Nov 2024 06:45:08 -0800 (PST) Message-ID: <3dd6f01e-918b-4bea-97dd-65cee886b9b8@wi3ck.info> Date: Tue, 12 Nov 2024 09:45:07 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Commit Timestamp and LSN Inversion issue To: Amit Kapila , Tomas Vondra Cc: Andres Freund , "Zhijie Hou (Fujitsu)" , Aleksander Alekseev , pgsql-hackers , shveta malik References: <9f7f4def-7ea8-4ad3-83e7-a8cc9d18c58a@wi3ck.info> <11ee3489-40ba-45d6-ba6a-7c3def725e84@vondra.me> Content-Language: en-US From: Jan Wieck In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/11/24 23:22, Amit Kapila wrote: > On Mon, Nov 11, 2024 at 9:05 PM Tomas Vondra wrote: >> >> 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. > I had originally experimented with adjusting the timestamps sent to the subscriber in the output plugin. This works for the most part but has two major flaws: 1) In case the system is restarted in a situation where it has some forward clock skew and the restart LSN is right in the middle of it, the output plugin has no knowledge of that and again emits backwards running timestamps. 2) The origin and the subscriber now have a different timestamp associated with the same transaction. That can lead to different behavior in conflict resolution when a third node gets involved. Best Regards, Jan