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 1lmaTE-0007Ya-GC for pgsql-admin@arkaria.postgresql.org; Fri, 28 May 2021 11:16:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lmaTC-0001lc-NR for pgsql-admin@arkaria.postgresql.org; Fri, 28 May 2021 11:16:02 +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 1lmaTC-0001lU-EV for pgsql-admin@lists.postgresql.org; Fri, 28 May 2021 11:16:02 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmaT7-00044r-Mm for pgsql-admin@lists.postgresql.org; Fri, 28 May 2021 11:16:01 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 10869380449; Fri, 28 May 2021 13:15:55 +0200 (CEST) Received: from rs.plausibolo.de ([IPv6:::1]) by localhost (h2367442.stratoserver.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id yA4WLJLQSyzw; Fri, 28 May 2021 13:15:54 +0200 (CEST) Received: from tuxedo.local.de (p5b248469.dip0.t-ipconnect.de [91.36.132.105]) by rs.plausibolo.de (Postfix) with ESMTPSA id C5589380405; Fri, 28 May 2021 13:15:54 +0200 (CEST) To: pgsql-admin@lists.postgresql.org References: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com> <1785725.1622133836@sss.pgh.pa.us> From: Holger Jakobs Subject: Re: now() and statement_timestamp() Message-ID: Date: Fri, 28 May 2021 13:15:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <1785725.1622133836@sss.pgh.pa.us> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KmGyokB7Lb6vpyz4jUgU12YlrIzGx3Lnw" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --KmGyokB7Lb6vpyz4jUgU12YlrIzGx3Lnw Content-Type: multipart/mixed; boundary="RRahnLEMWXXhkhMS5bObepnvHuzo6gRGT"; protected-headers="v1" From: Holger Jakobs To: pgsql-admin@lists.postgresql.org Message-ID: Subject: Re: now() and statement_timestamp() References: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com> <1785725.1622133836@sss.pgh.pa.us> In-Reply-To: <1785725.1622133836@sss.pgh.pa.us> --RRahnLEMWXXhkhMS5bObepnvHuzo6gRGT Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: de-DE Am 27.05.21 um 18:43 schrieb Tom Lane: > 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 =3D 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 I turned on logging of statements, and found out that psql uses a simple = query, while the others us an extended query. According to the documentation a simple query and a series of parse,=20 bind, execute are approximately equivalent (Note right above "Function=20 Call" in=20 https://www.postgresql.org/docs/13/protocol-flow.html#id-1.10.5.7.6) So actually the "approximately equivalent" is the point here. The series = of parse, bind, execute doesn't call the two funtions now() and=20 statement_timestamp() at the same stage, so the timestamps vary. I wasn't aware of this effect. Now it's clear that one can only use a=20 simple query in order to find out whether a session is within a=20 transaction or in autocommit mode. Maybe the Note in the documentation=20 should mention this clearly. --=20 Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012 --RRahnLEMWXXhkhMS5bObepnvHuzo6gRGT-- --KmGyokB7Lb6vpyz4jUgU12YlrIzGx3Lnw Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQScuJCxWJK1p5BOebGKV5yTsxlhugUCYLDQ6gUDAAAAAAAKCRCKV5yTsxlhumds AJ96V5RUsYZW9gVH2yl/3dknmlBjwgCgwYHS74JwW93YE48kTOjVCeXSeWQ= =987m -----END PGP SIGNATURE----- --KmGyokB7Lb6vpyz4jUgU12YlrIzGx3Lnw--