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 1nnoyz-0004SZ-11 for pgsql-hackers@arkaria.postgresql.org; Sun, 08 May 2022 22:02:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nnoyx-0005Ii-R1 for pgsql-hackers@arkaria.postgresql.org; Sun, 08 May 2022 22:02:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nnoyx-0005H9-6y for pgsql-hackers@lists.postgresql.org; Sun, 08 May 2022 22:02:27 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nnoyv-0004jk-5q for pgsql-hackers@postgresql.org; Sun, 08 May 2022 22:02:26 +0000 Received: by fetter.org (Postfix, from userid 1001) id 3B2BB418AF; Mon, 9 May 2022 00:02:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fetter.org; s=default; t=1652047343; bh=zkK4A3RyeOzGP7kdcJ5Mplc33CU2SF8Mp+SO2wv+gDY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=5WAvyeIrIm3stDXKFEJW+CxApcejcHwtnkQ0DXGVQMUumI13mWXn9eUyQ5D2UHTzr Iw9CJlye+2csCYkL685/hxbgg52Uc1jv3W9VJk48ltmvFOx0gd2f2ReEr1car2Ijf4 CnO5WWy0c+WBK+B2+iooy3wbhrwk70QdrqVxfsCsp1Hm1PcNuMEWT5ypWa/aDsbTuZ Rvzq85a9aKblYB/U5Wy0g62pzQ8i6wfJLyiqusSh1WESUqLHqi4gKn6fS8TDnaVMXj 8+jAt5spzy60rVDxi/Xix44Sla1eqRTRVOQtIeEXNl0J7ykivvBzFSG5h079e9ZErR 1sYHd9yBf9TjA== Date: Sun, 8 May 2022 22:02:22 +0000 From: David Fetter To: Justin Pryzby Cc: pgsql-hackers@postgresql.org Subject: Re: Finer grain log timestamps Message-ID: <20220508220222.GD11333@fetter.org> References: <20220508204451.GC11333@fetter.org> <20220508211227.GP28830@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="oC1+HKm2/end4ao3" Content-Disposition: inline In-Reply-To: <20220508211227.GP28830@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --oC1+HKm2/end4ao3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, May 08, 2022 at 04:12:27PM -0500, Justin Pryzby wrote: > On Sun, May 08, 2022 at 08:44:51PM +0000, David Fetter wrote: > > CREATE TABLE postgres_log > > ( > > - log_time timestamp(3) with time zone, > > + log_time timestamp(6) with time zone, > > Please also update the corresponding thing in doc/src/sgml/file-fdw.sgml Thanks for looking this over, and please find attached the next version. Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate --oC1+HKm2/end4ao3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Change-log-timestamps-from-milli-to-microseconds.patch" From f6772fc0378879fd5c7fbf8cb320ee68f66341d2 Mon Sep 17 00:00:00 2001 From: David Fetter Date: Sun, 8 May 2022 13:24:33 -0700 Subject: [PATCH v2] Change log timestamps from milli- to microseconds --- doc/src/sgml/config.sgml | 12 ++++++------ doc/src/sgml/file-fdw.sgml | 2 +- src/backend/utils/error/elog.c | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git doc/src/sgml/config.sgml doc/src/sgml/config.sgml index 03986946a8..f00db09547 100644 --- doc/src/sgml/config.sgml +++ doc/src/sgml/config.sgml @@ -7174,17 +7174,17 @@ local0.* /var/log/postgresql %t - Time stamp without milliseconds + Time stamp at second resolution no %m - Time stamp with milliseconds + Time stamp with microseconds no %n - Time stamp with milliseconds (as a Unix epoch) + Time stamp with microseconds (as a Unix epoch) no @@ -7526,7 +7526,7 @@ log_line_prefix = '%m [%p] %q%u@%d/%a ' This option emits log lines in comma-separated-values (CSV) format, with these columns: - time stamp with milliseconds, + time stamp with microseconds, user name, database name, process ID, @@ -7557,7 +7557,7 @@ log_line_prefix = '%m [%p] %q%u@%d/%a ' CREATE TABLE postgres_log ( - log_time timestamp(3) with time zone, + log_time timestamp(6) with time zone, user_name text, database_name text, process_id integer, @@ -7682,7 +7682,7 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; timestamp string - Time stamp with milliseconds + Time stamp with microseconds user diff --git doc/src/sgml/file-fdw.sgml doc/src/sgml/file-fdw.sgml index 5b98782064..c3efcbd679 100644 --- doc/src/sgml/file-fdw.sgml +++ doc/src/sgml/file-fdw.sgml @@ -242,7 +242,7 @@ CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw; CREATE FOREIGN TABLE pglog ( - log_time timestamp(3) with time zone, + log_time timestamp(6) with time zone, user_name text, database_name text, process_id integer, diff --git src/backend/utils/error/elog.c src/backend/utils/error/elog.c index 55ee5423af..4698e32ab7 100644 --- src/backend/utils/error/elog.c +++ src/backend/utils/error/elog.c @@ -2295,7 +2295,7 @@ char * get_formatted_log_time(void) { pg_time_t stamp_time; - char msbuf[13]; + char msbuf[16]; /* leave if already computed */ if (formatted_log_time[0] != '\0') @@ -2315,13 +2315,13 @@ get_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); + sprintf(msbuf, ".%06d", saved_timeval.tv_usec ); + memcpy(formatted_log_time + 19, msbuf, 7); return formatted_log_time; } @@ -2652,9 +2652,9 @@ log_line_prefix(StringInfo buf, ErrorData *edata) saved_timeval_set = true; } - snprintf(strfbuf, sizeof(strfbuf), "%ld.%03d", + snprintf(strfbuf, sizeof(strfbuf), "%ld.%06d", (long) saved_timeval.tv_sec, - (int) (saved_timeval.tv_usec / 1000)); + saved_timeval.tv_usec); if (padding != 0) appendStringInfo(buf, "%*s", padding, strfbuf); -- 2.35.1 --oC1+HKm2/end4ao3--