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 1rlr9U-004Zom-PH for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Mar 2024 14:06: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 1rlr9T-00B2o1-8q for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Mar 2024 14:06: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 1rlr9S-00B2nt-Rm for pgsql-hackers@lists.postgresql.org; Sun, 17 Mar 2024 14:06:15 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rlr9O-004zI2-UZ for pgsql-hackers@postgresql.org; Sun, 17 Mar 2024 14:06:14 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2d475b6609eso45436251fa.2 for ; Sun, 17 Mar 2024 07:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710684370; x=1711289170; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QsDOMwHfRLhn5IfsyA/e3zTpyIfCuc+LH1J2HaYMIVY=; b=UD4ZrrK3+0wK9ySwsHPMWwnBvQNhEWaGhtW5VIx253P0w+kq+8mMeRHymp4LDlcDZX 50kYAMpxxUid3xpwBRMPABXEl45LMY4kBPn1Mpp8/sdDpNsoa+8ZNGNgksjIlrQ9njqD VGS9gB2dyrJXe8EKayk67OV3dfg2BCw30NOxZrE7ekZ4xNHkgfpurvdTCXRSqEmgU6IU XMg8tf05PUUSTuns1JzpmMnU03UuV56tnFdTy+0cc349rUVDk4il1gvwJEBPx+ZmZjgz KzJBFhbMiLUKo9y5uyPIZsPQZ2B2QswyyMgKOGNxtwVbOtQXzkAeEjCGJm5xQt833QBv wLRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710684370; x=1711289170; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QsDOMwHfRLhn5IfsyA/e3zTpyIfCuc+LH1J2HaYMIVY=; b=Q+dusYZsqA0bSi6z/bfkk3A6txGrBzXrg4tdrududRkTYUxeb5RSzITxt2hbe8QGcf KACb+r3ayopHMWUqS1vXCl1uxZWEr2SZj8RDPP0nCZdD/Q3fRKT4c7ceLd/PWPJuMykG tMC1Nmholu3kvofhZhVXQ+jrY66Q285CMldHDTCLlvTlqOGF41kjSI7KOUa7fjJ25WuV ltlB304x7vQ4PA75l4R6KffcYS8rtdIGUgzgZVCGEXPpGnxxeP+PDnUttLyrdxVtlVti mJOzTRcs5zUypjrSful8csPMI5AM5y48T9amssN/L71vkYR9iNTWGmVxC9kQYBWSJNwF ZgtA== X-Gm-Message-State: AOJu0Yztsz0pVANZz4NiLnwUaC9Hole45F3+odLMBysFSr+h0MwvPQfP 6mdgiUo9YQgqRlD3N3GKdwAVGT74sniMYN/4Sn2Uwh4riR6++DFznTllq46AR2ytbK+WA7M9IQG dX71Rduq1y8Br4qMm86PDVM/nv2UKLIjN X-Google-Smtp-Source: AGHT+IGgh3ehf/x0AzEy+jNc+NfpmVNd2ziI9+9OGpChk+nVS9irFLWVA+UjAOWbbejsj60pQY8G8qzmg11duaWdIwE= X-Received: by 2002:a05:651c:820:b0:2d4:7363:a45a with SMTP id r32-20020a05651c082000b002d47363a45amr4989171ljb.53.1710684369512; Sun, 17 Mar 2024 07:06:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Kambam Vinay Date: Sun, 17 Mar 2024 19:35:57 +0530 Message-ID: Subject: Re: Fix for timestamp lag issue from emit_log_hook when GUC log_line_prefix has '%m' To: Michael Paquier Cc: pgsql-hackers@postgresql.org Content-Type: multipart/mixed; boundary="0000000000002b3eaf0613dbbe6b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002b3eaf0613dbbe6b Content-Type: multipart/alternative; boundary="0000000000002b3ead0613dbbe69" --0000000000002b3ead0613dbbe69 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks Michael for the review. Agree with your comment on the patch. updated the patch with recommended change. Thanks, Vinay On Mon, Mar 11, 2024 at 1:13=E2=80=AFPM Michael Paquier wrote: > 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_hook > > hook implementation when the log_line_prefix GUC has '%m'. > > > > 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 th= e > > next call to send_message_to_server_log(). Due to this, saved_timeval_s= et > > will be true during the execution of hook emit_log_hook() which prefixe= s > > the saved timestamp 'saved_timeval' from the previous log line (our hoo= k > > implementation calls log_line_prefix()). > > > > 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 > --0000000000002b3ead0613dbbe69 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks=C2=A0Michael for the review. Agree with your c= omment on the patch. updated the patch with recommended change.=C2=A0
=

Thanks,
Vinay

On Mon, Mar 11, 2024 at 1:13=E2= =80=AFPM Michael Paquier <michael= @paquier.xyz> wrote:
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= _hook
> hook implementation when the log_line_prefix GUC has '%m'.
>
> Upon debugging, we found that the saved_timeval_set variable is set to=
> 'true' in get_formatted_log_time() but is not reset to 'fa= lse' 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 prefix= es
> the saved timestamp 'saved_timeval' from the previous log line= (our hook
> implementation calls log_line_prefix()).
>
> Attached patch sets the saved_timeval_set to false before executing th= e
> emit_log_hook()

Indeed.=C2=A0 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.=C2=A0 Shouldn't we remove the forced reset of formatted_log_time f= or
the 'm' case in log_status_format() and remove the reset done at th= e
beginning of send_message_to_server_log()?=C2=A0 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?=C2=A0 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
--0000000000002b3ead0613dbbe69-- --0000000000002b3eaf0613dbbe6b Content-Type: application/octet-stream; name="0001-set-saved_timeval_set-to-false-before-executing-emit.patch" Content-Disposition: attachment; filename="0001-set-saved_timeval_set-to-false-before-executing-emit.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ltvk8cf70 RnJvbSBkYjIyMWQwNjI3ODdiYjUxYjU2YmQ5MjEzM2M5NjMzYmYwYz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