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 1sxDRh-008f5B-8t for pgsql-general@arkaria.postgresql.org; Sat, 05 Oct 2024 22:40:17 +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 1sxDRf-006E5k-5D for pgsql-general@arkaria.postgresql.org; Sat, 05 Oct 2024 22:40:15 +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 1sxDRd-006E5b-Gp for pgsql-general@lists.postgresql.org; Sat, 05 Oct 2024 22:40:14 +0000 Received: from fhigh-a2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sxDRZ-002hcG-FN for pgsql-general@lists.postgresql.org; Sat, 05 Oct 2024 22:40:11 +0000 Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0946C114010B for ; Sat, 5 Oct 2024 18:40:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Sat, 05 Oct 2024 18:40:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1728168008; x=1728254408; bh=dlJMxfXmOM5kypOgMMfFOQD8wZwnSMyHxTruvyijgJ8=; b= a/88EeCiW29ir3J2z6veO++3Q5edI0zPr1+vk6PXRCZtmW4VgQ72U26HRys/k/J6 nC56pfPqPCjlQbfjSrD7x8KE89V2KfyAfGS9YXs/ROPhKAt8AnUkAezEvlfsZzD8 CykwbYu6XCozWF7GsArAmm5RVkF1pvZZ8bzlPyhBEADfsiI0g60L5z7LCX36qp0+ YIPi/jiWBRgvkYmiepbqNQvmozKYHyTn0QbSadvlSjq9AoGC+2YLXWiSWbttzxvI x/E9wZP3F+LLqzRDVsMmJk9Zq1mx7e50KbvEwKIdgVB0lAVIYVohLnWeY/CnIltX g+PySZ9GdxV2ickjlrFqhg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1728168008; x= 1728254408; bh=dlJMxfXmOM5kypOgMMfFOQD8wZwnSMyHxTruvyijgJ8=; b=L OlLEVvt8ZGyq24QPD78ZmDD0OgTg+qaebAXPxlvdGTtUJrgjBJipaOBqfWxDvD8r fRidOBLuhlC4JtAA2cVMLowgfFd+Occrbew+lHLxMjCWyAB4VwZod1+O6zhPvgj0 8KC7h2+6UyrfpqL1DM874BeVRm4HvU4hs/CK2nrnpJevqojrjg5l/KC0qBV1oDLI 3Y5BX3XEpucF6E38ABIS0wAJbrObsy+QhZxKTmgEwYuf38ZoGDGR53GLCrP+lkW4 01fAIZbsJoGVfmfxrKJVpwCBiVFMEohX6oTBYxwRA2Z/wcKoqWRv/T6ujMkz6x4e uViuTLi9w/KZlY5VAFl0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddviedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfg fuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghr uceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrth htvghrnhepleegveekkeekueeigfdtveeileeuhfefudefteekjeffkeejueejheegheeg kedtnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghr segrkhhlrghvvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehlihhsthhsrdhpohhsthhg rhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 5 Oct 2024 18:40:07 -0400 (EDT) Message-ID: <19575239-9d4d-4876-b9b2-df2e7059e698@aklaver.com> Date: Sat, 5 Oct 2024 15:40:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Repeatable Read Isolation Level "transaction start time" To: pgsql-general@lists.postgresql.org References: <20240925215554.gfg24h5sp5aqesxv@hjp.at> <152525.1727302184@sss.pgh.pa.us> <20241005091424.34il2ss4noazgegx@hjp.at> <368259fb-fd2e-4a05-89e9-a733fae6d964@aklaver.com> <20241005203327.nb52nfuopdsjilvd@hjp.at> <1166698.1728162188@sss.pgh.pa.us> <20241005222555.wm53cmxnwfam4vtz@hjp.at> Content-Language: en-US From: Adrian Klaver In-Reply-To: <20241005222555.wm53cmxnwfam4vtz@hjp.at> 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 10/5/24 15:25, Peter J. Holzer wrote: > On 2024-10-05 17:03:08 -0400, Tom Lane wrote: >> "Peter J. Holzer" writes: >>> Again, I'm not arguing for such a change, but I'm wondering if recording >>> transaction_timestamp just after the snapshot might be a safe change or >>> whether that might break some assumption that programmers can currently >>> make. >> >> As I mentioned upthread, we currently promise that xact_start matches >> the query_start of the transaction's first statement. (I'm not sure >> how well that's documented, but the code goes out of its way to make >> it so, so somebody thought it was important.) > > It's mentioned in > https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT > > | statement_timestamp() and transaction_timestamp() return the same value during the first command of a transaction > > But that seems to be wrong in practice. The first statement of a > transaction is BEGIN. So whatever command calls statement_timestamp() is > already the second command, so statement_timestamp() is later than > transaction_timestamp(). This is even true if the BEGIN and SELECT are > on the same line: > > hjp=> begin; select transaction_timestamp(), statement_timestamp(), clock_timestamp(); rollback; > BEGIN > Time: 0.406 ms > ╔═[ RECORD 1 ]══════════╤═══════════════════════════════╗ > ║ transaction_timestamp │ 2024-10-05 23:55:47.356582+02 ║ > ║ statement_timestamp │ 2024-10-05 23:55:47.357106+02 ║ > ║ clock_timestamp │ 2024-10-05 23:55:47.357397+02 ║ > ╚═══════════════════════╧═══════════════════════════════╝ > > Time: 0.570 ms > ROLLBACK > Time: 0.285 ms > > The difference are only 0.5 ms, but it's not zero. > > I think the only case where transaction_timestamp() = statement_timestamp() > is outside of a transaction. > AFAIK that is still a transaction: https://www.postgresql.org/docs/current/sql-begin.html By default (without BEGIN), PostgreSQL executes transactions in “autocommit” mode, that is, each statement is executed in its own transaction and a commit is implicitly performed at the end of the statement (if execution was successful, otherwise a rollback is done). -- Adrian Klaver adrian.klaver@aklaver.com