1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +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

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.276 2007/08/01 22:45:08 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.277 2007/08/04 01:26:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -437,7 +437,7 @@ static void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
uint32 endLogId, uint32 endLogSeg);
static void WriteControlFile(void);
static void ReadControlFile(void);
static char *str_time(time_t tnow);
static char *str_time(pg_time_t tnow);
static void issue_xlog_fsync(void);
#ifdef WAL_DEBUG
@ -4266,13 +4266,13 @@ BootStrapXLOG(void)
}
static char *
str_time(time_t tnow)
str_time(pg_time_t tnow)
{
static char buf[128];
strftime(buf, sizeof(buf),
"%Y-%m-%d %H:%M:%S %Z",
localtime(&tnow));
pg_strftime(buf, sizeof(buf),
"%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&tnow, log_timezone));
return buf;
}
@ -6290,7 +6290,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
char *backupidstr;
XLogRecPtr checkpointloc;
XLogRecPtr startpoint;
time_t stamp_time;
pg_time_t stamp_time;
char strfbuf[128];
char xlogfilename[MAXFNAMELEN];
uint32 _logId;
@ -6368,16 +6368,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
XLByteToSeg(startpoint, _logId, _logSeg);
XLogFileName(xlogfilename, ThisTimeLineID, _logId, _logSeg);
/*
* We deliberately use strftime/localtime not the src/timezone
* functions, so that backup labels will consistently be recorded in
* the same timezone regardless of TimeZone setting. This matches
* elog.c's practice.
*/
stamp_time = time(NULL);
strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
localtime(&stamp_time));
/* Use the log timezone here, not the session timezone */
stamp_time = (pg_time_t) time(NULL);
pg_strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&stamp_time, log_timezone));
/*
* Check for existing backup label --- implies a backup is already
@ -6455,7 +6450,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
text *result;
XLogRecPtr startpoint;
XLogRecPtr stoppoint;
time_t stamp_time;
pg_time_t stamp_time;
char strfbuf[128];
char histfilepath[MAXPGPATH];
char startxlogfilename[MAXFNAMELEN];
@ -6489,16 +6484,11 @@ pg_stop_backup(PG_FUNCTION_ARGS)
XLByteToSeg(stoppoint, _logId, _logSeg);
XLogFileName(stopxlogfilename, ThisTimeLineID, _logId, _logSeg);
/*
* We deliberately use strftime/localtime not the src/timezone functions,
* so that backup labels will consistently be recorded in the same
* timezone regardless of TimeZone setting. This matches elog.c's
* practice.
*/
stamp_time = time(NULL);
strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
localtime(&stamp_time));
/* Use the log timezone here, not the session timezone */
stamp_time = (pg_time_t) time(NULL);
pg_strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&stamp_time, log_timezone));
/*
* Open the existing label file