1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Switch over to using the src/timezone functions for formatting timestamps

displayed in the postmaster log.  This avoids Windows-specific problems with
localized time zone names that are in the wrong encoding, and generally seems
like a good idea to forestall other potential platform-dependent issues.
To preserve the existing behavior that all backends will log in the same time
zone, create a new GUC variable log_timezone that can only be changed on a
system-wide basis, and reference log-related calculations to that zone instead
of the TimeZone variable.

This fixes the issue reported by Hiroshi Saito that timestamps printed by
xlog.c startup could be improperly localized on Windows.  We still need a
simpler patch for that problem in the back branches, however.
This commit is contained in:
Tom Lane
2007-08-04 01:26:54 +00:00
parent 73852bd520
commit bdd6b62245
16 changed files with 275 additions and 148 deletions

View File

@ -42,7 +42,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.191 2007/08/02 23:39:44 adunstan Exp $
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.192 2007/08/04 01:26:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1495,33 +1495,18 @@ log_line_prefix(StringInfo buf)
break;
case 'm':
{
/*
* Note: for %m, %t, and %s we deliberately use the C
* library's strftime/localtime, and not the equivalent
* functions from src/timezone. This ensures that all
* backends will report log entries in the same timezone,
* namely whatever C-library setting they inherit from the
* postmaster. If we used src/timezone then local
* settings of the TimeZone GUC variable would confuse the
* log.
*/
time_t stamp_time;
struct timeval tv;
pg_time_t stamp_time;
char strfbuf[128],
msbuf[8];
struct timeval tv;
gettimeofday(&tv, NULL);
stamp_time = tv.tv_sec;
stamp_time = (pg_time_t) tv.tv_sec;
strftime(strfbuf, sizeof(strfbuf),
/* leave room for milliseconds... */
/* Win32 timezone names are too long so don't print them */
#ifndef WIN32
"%Y-%m-%d %H:%M:%S %Z",
#else
"%Y-%m-%d %H:%M:%S ",
#endif
localtime(&stamp_time));
pg_strftime(strfbuf, sizeof(strfbuf),
/* leave room for milliseconds... */
"%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&stamp_time, log_timezone));
/* 'paste' milliseconds into place... */
sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
@ -1532,32 +1517,23 @@ log_line_prefix(StringInfo buf)
break;
case 't':
{
time_t stamp_time = time(NULL);
pg_time_t stamp_time = (pg_time_t) time(NULL);
char strfbuf[128];
strftime(strfbuf, sizeof(strfbuf),
/* Win32 timezone names are too long so don't print them */
#ifndef WIN32
"%Y-%m-%d %H:%M:%S %Z",
#else
"%Y-%m-%d %H:%M:%S",
#endif
localtime(&stamp_time));
pg_strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&stamp_time, log_timezone));
appendStringInfoString(buf, strfbuf);
}
break;
case 's':
{
pg_time_t stamp_time = (pg_time_t) MyStartTime;
char strfbuf[128];
strftime(strfbuf, sizeof(strfbuf),
/* Win32 timezone names are too long so don't print them */
#ifndef WIN32
"%Y-%m-%d %H:%M:%S %Z",
#else
"%Y-%m-%d %H:%M:%S",
#endif
localtime(&MyStartTime));
pg_strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&stamp_time, log_timezone));
appendStringInfoString(buf, strfbuf);
}
break;