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 1rjaJh-006VDp-JB for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Mar 2024 07:43:26 +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 1rjaJf-00A8Q4-KC for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Mar 2024 07:43:24 +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 1rjaJf-00A8Pw-AY for pgsql-hackers@lists.postgresql.org; Mon, 11 Mar 2024 07:43:23 +0000 Received: from fout1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjaJc-003uiT-8y for pgsql-hackers@postgresql.org; Mon, 11 Mar 2024 07:43:22 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 4C2AC13800A5; Mon, 11 Mar 2024 03:43:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 11 Mar 2024 03:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc: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=1710143000; x=1710229400; bh=+XEX9hde5V bzD5LOCW5Nhkm5sXfg634TLmZUKwxB3Xk=; b=lagBougDBgnwwcysiZO7ZyLY+e FZ52NFVgZku/zal3aL3MNLJvywGsoZa/5L4lkYaQi3LMZNm9cNoKYZaW6FYW51dj wfvh27fvJcMSujuX/fA4HcT+VOgKr9R/LQHZ3yizCsPEHmLWhU1XdyzzmxD0/AOF 3MFtTCXMfrgNB6ht4ByqLmcnDrusBpPGrP+ywNu+CSYqKYDyDc8jxYXKL8TJQlBe 023RysC09+1ZI63MkrZ2UV6SPz3lpzOG9xwp6S+Dv2DxWFstWaBch4Nn++UPk1UE JrSXCDi59s0t3M9HiVDWHDV07xCbGxQWp1sxk2PhnhIxIWuAlgcxjalU7Vmw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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= fm1; t=1710143000; x=1710229400; bh=+XEX9hde5VbzD5LOCW5Nhkm5sXfg 634TLmZUKwxB3Xk=; b=jBR1eIkskMZNcEauXy+sNfrzwpoDP4g1JLov9HE0oDF2 0sK2mJMJakfxEScnYipS+YkuPvJoqVv7mbnJmb0e+CNe9vVrYx+p3YqdPiIUquQ/ UeVeNv+KaAdq13Jpje+I/NlXdVjm8qlLyYn2hoa+91Qh/FqYt3LRMSfc7g23DslC cGCy++u1CP8fw+4TROAm1evCMEW0VQfGdzZB2FwlzPtINGwnT/DYO8qfkvoDw/Xt AXovKYjl827OZMGxfjnteb1G4LAQqOz3syb63oJG1zPM00TnqGFloo8X6vxtewMb u97XurIexeu2Et+rI2wkWA/+814A8edzG0FSJ4ahbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjedtgdduuddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 Mar 2024 03:43:18 -0400 (EDT) Date: Mon, 11 Mar 2024 16:43:06 +0900 From: Michael Paquier To: Kambam Vinay Cc: pgsql-hackers@postgresql.org Subject: Re: Fix for timestamp lag issue from emit_log_hook when GUC log_line_prefix has '%m' Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="xVVuDcVp6c6zilfh" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --xVVuDcVp6c6zilfh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 09, 2024 at 09:09:39PM +0530, Kambam Vinay wrote: > We observed a slight lag in timestamp for a few logs from the emit_log_ho= ok > hook implementation when the log_line_prefix GUC has '%m'. >=20 > Upon debugging, we found that the saved_timeval_set variable is set to > 'true' in get_formatted_log_time() but is not reset to 'false' until the > next call to send_message_to_server_log(). Due to this, saved_timeval_set > will be true during the execution of hook emit_log_hook() which prefixes > the saved timestamp 'saved_timeval' from the previous log line (our hook > implementation calls log_line_prefix()). >=20 > Attached patch sets the saved_timeval_set to false before executing the > emit_log_hook() Indeed. If you rely on log_line_prefix() in your hook before the server side elog, the saved timestamp would not match with what could be computed in the follow-up send_message_to_server_log or send_message_to_frontend. Hmm. Shouldn't we remove the forced reset of formatted_log_time for the 'm' case in log_status_format() and remove the reset done at the beginning of send_message_to_server_log()? One problem with your patch is that we would still finish with a different saved_timeval in the hook and in send_message_to_server_log(), but we should do things so as the timestamps are the same for the whole duration of EmitErrorReport(), no? It seems to me that a more correct solution would be to reset saved_timeval_set and formatted_log_time[0] once before the hook, at the beginning of EmitErrorReport(). -- Michael --xVVuDcVp6c6zilfh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmXutgoACgkQnvQgOdby QH3I9RAAqkX47mNCSyhl3RYYJFjq9Gr/qAJP22X6YMQFmF5hQNDyarmiIIeSsH7x Fu+e18cJoeyMPbux666HudbTa2ibdQAtT3uhnSV+wK8OmKz+HFcxDGB+vwe6I1Nf tifmUQFE6tTuF/A7B+OvIz01S4z2KAa+w+pclNq4pEllEcL00vZ1oYVMioknyKyJ dDdK40meu0nwIvxHlS1+h88/oqo5EEczjXZTzslcWQLa9URLdhrGLQDRK3GQilUV IixuxOigFmMwcmp9HqmCDXK3c58J2nv4b0vYYg8Y74lPf5HnvVfPlNkWK/DC/u7I Fk7KrhsDiXaBWfsXt6TGi2hkQIG8Lmk8I3bcNgfRgFgrysjZKt8FJPbng7vo0w2Z WsNeMxRlR2zME+Eq1q8t2TK/okroNaaiCkrjNUKY1PShV3/0KEZXG6KGvzXIqGcB Kso2jxCNnc51IYR/QNwGIhhtxzrCB9Uy2AD74PESv9SNAbMKuQv8K2D4sctJtogn UAG/7iqK8ehr1wo7xQvXtVs9Qco5EQRw1qoAYV8xW3sYtSQgNA5gjusQNJKi6Uar /EPGo15oJGuZrtmi0FQY3PHPe4OqNSmNgVbQPuZUZGXJ7lfAtgRI67jvJeKt6kOz EQ8rOCGHvQ7Zn3wKybh3XkoB0EbQCEntlSFqcOhgHv6rANTkdv4= =myVd -----END PGP SIGNATURE----- --xVVuDcVp6c6zilfh--