Folks,

Per gripes I've been hearing with increasing frequency, please find
attached a patch that implements $Subject. It's microsecond resolution
because at least at the moment, nanosecond resolution doesn't appear
to be helpful in this context.

Best,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
>From 29e620bbae9d458e5789350ed19d63c48b8459ff Mon Sep 17 00:00:00 2001
From: David Fetter <da...@fetter.org>
Date: Tue, 23 Oct 2018 11:35:34 -0700
Subject: [PATCH] log_line_prefix was milliseconds: now microseconds
To: pgsql-hack...@postgresql.org

---
 doc/src/sgml/config.sgml                      |  6 +++---
 src/backend/utils/error/elog.c                | 14 +++++++-------
 src/backend/utils/misc/postgresql.conf.sample |  6 +++---
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 7554cba3f9..8faaa35b86 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5593,17 +5593,17 @@ local0.*    /var/log/postgresql
             </row>
             <row>
              <entry><literal>%t</literal></entry>
-             <entry>Time stamp without milliseconds</entry>
+             <entry>Time stamp without microseconds</entry>
              <entry>no</entry>
             </row>
             <row>
              <entry><literal>%m</literal></entry>
-             <entry>Time stamp with milliseconds</entry>
+             <entry>Time stamp with microseconds</entry>
              <entry>no</entry>
             </row>
             <row>
              <entry><literal>%n</literal></entry>
-             <entry>Time stamp with milliseconds (as a Unix epoch)</entry>
+             <entry>Time stamp with microseconds (as a Unix epoch)</entry>
              <entry>no</entry>
             </row>
             <row>
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index b9c11301ca..70a61fde4c 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -2222,7 +2222,7 @@ static void
 setup_formatted_log_time(void)
 {
 	pg_time_t	stamp_time;
-	char		msbuf[13];
+	char		msbuf[16];
 
 	if (!saved_timeval_set)
 	{
@@ -2238,13 +2238,13 @@ setup_formatted_log_time(void)
 	 * nonempty or CSV mode can be selected.
 	 */
 	pg_strftime(formatted_log_time, FORMATTED_TS_LEN,
-	/* leave room for milliseconds... */
-				"%Y-%m-%d %H:%M:%S     %Z",
+	/* leave room for microseconds... */
+				"%Y-%m-%d %H:%M:%S        %Z",
 				pg_localtime(&stamp_time, log_timezone));
 
-	/* 'paste' milliseconds into place... */
-	sprintf(msbuf, ".%03d", (int) (saved_timeval.tv_usec / 1000));
-	memcpy(formatted_log_time + 19, msbuf, 4);
+	/* 'paste' microseconds into place... */
+	sprintf(msbuf, ".%06d", saved_timeval.tv_usec);
+	memcpy(formatted_log_time + 19, msbuf, 7);
 }
 
 /*
@@ -2665,7 +2665,7 @@ write_csvlog(ErrorData *edata)
 	initStringInfo(&buf);
 
 	/*
-	 * timestamp with milliseconds
+	 * timestamp with microseconds
 	 *
 	 * Check if the timestamp is already calculated for the syslog message,
 	 * and use it if so.  Otherwise, get the current timestamp.  This is done
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 4e61bc6521..dcea840b8f 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -470,9 +470,9 @@
 					#   %r = remote host and port
 					#   %h = remote host
 					#   %p = process ID
-					#   %t = timestamp without milliseconds
-					#   %m = timestamp with milliseconds
-					#   %n = timestamp with milliseconds (as a Unix epoch)
+					#   %t = timestamp without microseconds
+					#   %m = timestamp with microseconds
+					#   %n = timestamp with microseconds (as a Unix epoch)
 					#   %i = command tag
 					#   %e = SQL state
 					#   %c = session ID
-- 
2.17.2

Reply via email to