Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmJ7B-00044T-E5 for pgsql-admin@arkaria.postgresql.org; Thu, 27 May 2021 16:44:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lmJ7A-00073w-8N for pgsql-admin@arkaria.postgresql.org; Thu, 27 May 2021 16:44:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmJ79-00073o-WC for pgsql-admin@lists.postgresql.org; Thu, 27 May 2021 16:44:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmJ73-0003tJ-RF for pgsql-admin@postgresql.org; Thu, 27 May 2021 16:44:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14RGhuRK1785726; Thu, 27 May 2021 12:43:56 -0400 From: Tom Lane To: Holger Jakobs cc: pgsql-admin Subject: Re: now() and statement_timestamp() In-reply-to: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com> References: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com> Comments: In-reply-to Holger Jakobs message dated "Thu, 27 May 2021 18:26:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1785724.1622133836.1@sss.pgh.pa.us> Date: Thu, 27 May 2021 12:43:56 -0400 Message-ID: <1785725.1622133836@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Holger Jakobs writes: > So in psql now() and statement_timestamp() are identical when not in a > transaction, while in the others the two values vary a little bit, > roughly 100 microseconds. > How come the same statements aren't behaving identical. I'm using a > current PostgreSQL server on a Linux machine. I'd try turning on log_statement = all to see what's actually happening. What seems somewhat likely is that the non-psql cases are wrapping the command you gave in BEGIN/COMMIT, or something along that line. [ thinks for a bit ] It could also be down to the wire protocol used. psql is just sending a simple Query message, but the other two might well be sending Parse/Bind/Execute. IIRC the transaction must be started by Bind, but we may consider the statement timestamp to be the start of processing Execute. regards, tom lane