Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa8bdab

Browse files
committed
Attached patch gets rid of the global timezone in the following steps:
* Changes the APIs to the timezone functions to take a pg_tz pointer asan argument, representing the timezone to use for the selectedoperation.* Adds a global_timezone variable that represents the current timezonein the backend as set by SET TIMEZONE (or guc, or env, etc).* Implements a hash-table cache of loaded tables, so we don't have toread and parse the TZ file everytime we change a timezone. While notnecesasry now (we don't change timezones very often), I beleive thiswill be necessary (or at least good) when "multiple timezones in thesame query" is eventually implemented. And code-wise, this was the timeto do it.There are no user-visible changes at this time. Implementing the"multiple zones in one query" is a later step...This also gets rid of some of the cruft needed to "back out a timezonechange", since we previously couldn't check a timezone unless it wasactivated first.Passes regression tests on win32, linux (slackware 10) and solaris x86.Magnus Hagander
1 parentdd39dd2 commitaa8bdab

File tree

11 files changed

+233
-191
lines changed

11 files changed

+233
-191
lines changed

‎src/backend/commands/variable.c

Lines changed: 27 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.105 2004/12/31 21:59:42 pgsql Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.106 2005/04/19 03:13:58 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -315,104 +315,50 @@ assign_timezone(const char *value, bool doit, GucSource source)
315315
* UNKNOWN as the canonical spelling.
316316
*
317317
* During GUC initialization, since the timezone library isn't
318-
* set up yet,pg_get_current_timezone will return NULL and we
318+
* set up yet,pg_get_timezone_name will return NULL and we
319319
* will leave the setting as UNKNOWN. If this isn't
320320
* overridden from the config file then
321321
* pg_timezone_initialize() will eventually select a default
322322
* value from the environment.
323323
*/
324-
constchar*curzone=pg_get_current_timezone();
324+
constchar*curzone=pg_get_timezone_name(global_timezone);
325325

326326
if (curzone)
327327
value=curzone;
328328
}
329329
else
330330
{
331331
/*
332-
* Otherwise assume it is a timezone name.
333-
*
334-
* We have to actually apply the change before we can have any
335-
* hope of checking it. So, save the old value in case we
336-
* have to back out. We have to copy since
337-
* pg_get_current_timezone returns a pointer to its static
338-
* state.
339-
*
340-
* This would all get a lot simpler if the TZ library had a
341-
* better API that would let us look up and test a timezone
342-
* name without making it the default.
332+
* Otherwise assume it is a timezone name, and try to load it.
343333
*/
344-
constchar*cur_tz;
345-
char*save_tz;
346-
boolknown,
347-
acceptable;
334+
pg_tz*new_tz;
348335

349-
cur_tz=pg_get_current_timezone();
350-
if (cur_tz)
351-
save_tz=pstrdup(cur_tz);
352-
else
353-
save_tz=NULL;
336+
new_tz=pg_tzset(value);
354337

355-
known=pg_tzset(value);
356-
acceptable=known ?tz_acceptable() : false;
338+
if (!new_tz)
339+
{
340+
ereport((source >=PGC_S_INTERACTIVE) ?ERROR :LOG,
341+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
342+
errmsg("unrecognized time zone name: \"%s\"",
343+
value)));
344+
returnNULL;
345+
}
357346

358-
if (doit&&known&&acceptable)
347+
if (!tz_acceptable(new_tz))
359348
{
360-
/* Keep the changed TZ */
361-
HasCTZSet= false;
349+
ereport((source >=PGC_S_INTERACTIVE) ?ERROR :LOG,
350+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
351+
errmsg("time zone \"%s\" appears to use leap seconds",
352+
value),
353+
errdetail("PostgreSQL does not support leap seconds.")));
354+
returnNULL;
362355
}
363-
else
356+
357+
if (doit)
364358
{
365-
/*
366-
* Revert to prior TZ setting; note we haven't changed
367-
* HasCTZSet in this path, so if we were previously using
368-
* a fixed offset, we still are.
369-
*/
370-
if (save_tz)
371-
pg_tzset(save_tz);
372-
else
373-
{
374-
/*
375-
* TZ library wasn't initialized yet. Annoyingly, we
376-
* will come here during startup because guc-file.l
377-
* checks the value with doit = false before actually
378-
* applying. The best approach seems to be as follows:
379-
*
380-
* 1. known && acceptable: leave the setting in place,
381-
* since we'll apply it soon anyway. This is mainly
382-
* so that any log messages printed during this
383-
* interval are timestamped with the user's requested
384-
* timezone.
385-
*
386-
* 2. known && !acceptable: revert to GMT for lack of any
387-
* better idea. (select_default_timezone() may get
388-
* called later to undo this.)
389-
*
390-
* 3. !known: no need to do anything since TZ library did
391-
* not change its state.
392-
*
393-
* Again, this should all go away sometime soon.
394-
*/
395-
if (known&& !acceptable)
396-
pg_tzset("GMT");
397-
}
398-
/* Complain if it was bad */
399-
if (!known)
400-
{
401-
ereport((source >=PGC_S_INTERACTIVE) ?ERROR :LOG,
402-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
403-
errmsg("unrecognized time zone name: \"%s\"",
404-
value)));
405-
returnNULL;
406-
}
407-
if (!acceptable)
408-
{
409-
ereport((source >=PGC_S_INTERACTIVE) ?ERROR :LOG,
410-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
411-
errmsg("time zone \"%s\" appears to use leap seconds",
412-
value),
413-
errdetail("PostgreSQL does not support leap seconds.")));
414-
returnNULL;
415-
}
359+
/* Save the changed TZ */
360+
global_timezone=new_tz;
361+
HasCTZSet= false;
416362
}
417363
}
418364
}
@@ -459,7 +405,7 @@ show_timezone(void)
459405
IntervalPGetDatum(&interval)));
460406
}
461407
else
462-
tzn=pg_get_current_timezone();
408+
tzn=pg_get_timezone_name(global_timezone);
463409

464410
if (tzn!=NULL)
465411
returntzn;

‎src/backend/postmaster/syslogger.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.14 2005/03/12 01:54:44 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.15 2005/04/19 03:13:59 momjian Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -833,7 +833,7 @@ logfile_getname(pg_time_t timestamp)
833833
if (strchr(Log_filename,'%'))
834834
{
835835
/* treat it as a strftime pattern */
836-
tm=pg_localtime(&timestamp);
836+
tm=pg_localtime(&timestamp,global_timezone);
837837
pg_strftime(filename+len,MAXPGPATH-len,Log_filename,tm);
838838
}
839839
else
@@ -868,7 +868,7 @@ set_next_rotation_time(void)
868868
*/
869869
rotinterval=Log_RotationAge*60;/* convert to seconds */
870870
now=time(NULL);
871-
tm=pg_localtime(&now);
871+
tm=pg_localtime(&now,global_timezone);
872872
now+=tm->tm_gmtoff;
873873
now-=now %rotinterval;
874874
now+=rotinterval;

‎src/backend/utils/adt/datetime.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.137 2005/01/11 18:33:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.138 2005/04/19 03:13:59 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1634,7 +1634,8 @@ DetermineLocalTimeZone(struct pg_tm * tm)
16341634
res=pg_next_dst_boundary(&prevtime,
16351635
&before_gmtoff,&before_isdst,
16361636
&boundary,
1637-
&after_gmtoff,&after_isdst);
1637+
&after_gmtoff,&after_isdst,
1638+
global_timezone);
16381639
if (res<0)
16391640
gotooverflow;/* failure? */
16401641

‎src/backend/utils/adt/nabstime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.127 2004/12/31 22:01:22 pgsql Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.128 2005/04/19 03:13:59 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -192,7 +192,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
192192
time-=CTimeZone;
193193

194194
if ((!HasCTZSet)&& (tzp!=NULL))
195-
tx=pg_localtime(&time);
195+
tx=pg_localtime(&time,global_timezone);
196196
else
197197
tx=pg_gmtime(&time);
198198

@@ -1677,7 +1677,7 @@ timeofday(PG_FUNCTION_ARGS)
16771677
gettimeofday(&tp,&tpz);
16781678
tt= (pg_time_t)tp.tv_sec;
16791679
pg_strftime(templ,sizeof(templ),"%a %b %d %H:%M:%S.%%06d %Y %Z",
1680-
pg_localtime(&tt));
1680+
pg_localtime(&tt,global_timezone));
16811681
snprintf(buf,sizeof(buf),templ,tp.tv_usec);
16821682

16831683
len=VARHDRSZ+strlen(buf);

‎src/backend/utils/adt/timestamp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.118 2005/04/01 14:25:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.119 2005/04/19 03:13:59 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1078,7 +1078,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
10781078
utime= (pg_time_t)dt;
10791079
if ((Timestamp)utime==dt)
10801080
{
1081-
structpg_tm*tx=pg_localtime(&utime);
1081+
structpg_tm*tx=pg_localtime(&utime,global_timezone);
10821082

10831083
tm->tm_year=tx->tm_year+1900;
10841084
tm->tm_mon=tx->tm_mon+1;

‎src/include/pgtime.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/include/pgtime.h,v 1.6 2004/12/31 22:03:19 pgsql Exp $
9+
* $PostgreSQL: pgsql/src/include/pgtime.h,v 1.7 2005/04/1903:13:59 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -37,21 +37,24 @@ struct pg_tm
3737
constchar*tm_zone;
3838
};
3939

40-
externstructpg_tm*pg_localtime(constpg_time_t*timep);
40+
typedefstructpg_tzpg_tz;
41+
42+
externstructpg_tm*pg_localtime(constpg_time_t*timep,constpg_tz*tz);
4143
externstructpg_tm*pg_gmtime(constpg_time_t*timep);
4244
externintpg_next_dst_boundary(constpg_time_t*timep,
4345
longint*before_gmtoff,
4446
int*before_isdst,
4547
pg_time_t*boundary,
4648
longint*after_gmtoff,
47-
int*after_isdst);
49+
int*after_isdst,
50+
constpg_tz*tz);
4851
externsize_tpg_strftime(char*s,size_tmax,constchar*format,
4952
conststructpg_tm*tm);
5053

5154
externvoidpg_timezone_initialize(void);
52-
externboolpg_tzset(constchar*tzname);
53-
externbooltz_acceptable(void);
54-
externconstchar*select_default_timezone(void);
55-
externconstchar*pg_get_current_timezone(void);
55+
externpg_tz*pg_tzset(constchar*tzname);
56+
externbooltz_acceptable(pg_tz*tz);
57+
externconstchar*pg_get_timezone_name(pg_tz*tz);
5658

59+
externpg_tz*global_timezone;
5760
#endif/* _PGTIME_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp