1、首先确认是否为美国夏令时:
rac1$ echo $TZ
只要不为Asia/Shanghai就需要修改,我们的环境能显示CST6CDT
修改步骤如下:
smitty-> System Environments -> Change / Show Date and Time -> Change Time Zone Using User Inputted Values ->选择china shanghai
2、光改操作系统时区还不够,因为oracle是向aix系统取时间,如果当初时区不正确在安装grid时oracle会默认操作系统的时区,所以grid也需要修改:
修改$GRID_HOME/crs/install/s_crsconfig_
rac1# more s_crsconfig_spdb1_env.txt
### This file can be used to modify the NLS_LANG environment variable,which determines the charset to be used for messages.
### For example, a new charset can be configured by settingNLS_LANG=JAPANESE_JAPAN.UTF8
### Do not modify this file except to change NLS_LANG, or under thedirection of Oracle Support Services
TZ=CST6CDT
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
RT_GRQ=ON
TNS_ADMIN=
ORACLE_BASE=
修改s_crsconfig_spdb1_env.txt的TZ=Asia/Shanghai (别忘记两个节点都需要修改)
最后shutdown -Fr 完成修改。
Oracle dbtimezone与os时区不一致的解决办法
Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0
Connected as sys
//查看数据库时区
SQL> select dbtimezone from dual;
DBTIMEZONE
----------
+00:00
//查看当前时间和时区
SQL> select systimestamp from dual;
SYSTIMESTAMP
--------------------------------------------------------------------------------
12-4月 -11 02.39.49.421000 下午 +08:00
//我明明是在东8区,怎么数据库时区显示为0呢?
SQL> alter database set time_zone='+8:00';
ORA-30079: cannot alter database timezone when database has TIMESTAMP WITH LOCAL TIME ZONE columns
//从错误提示,我们可以看出数据库中一些表的列的数据类型为:TIMESTAMP WITH LOCAL TIME ZONE
//我们得将这些列删除后,才能更改,下面我们来查找这些类。
SQL> select u.name||'.'||o.name||'.'||c.name tsltz_column
2 from sys.obj$ o,sys.col$ c,sys.user$ u
3 where c.type#=231 and
4 o.obj#=c.obj# and
5 u.user#=o.owner#;
TSLTZ_COLUMN
--------------------------------------------------------------------------------
OE.ORDERS.ORDER_DATE
//我们找到了,是oe用户下orders表下的列order_date。
SQL> desc oe.orders;
Name Type Nullable Default Comments
------------ --------------------------------- -------- ------- -----------------------------------------------------------
ORDER_ID NUMBER(12) PRIMARY KEY column.
ORDER_DATE TIMESTAMP(6) WITH LOCAL TIME ZONE TIMESTAMP WITH LOCAL TIME ZONE column, NOT NULL constraint.
ORDER_MODE VARCHAR2(8) Y CHECK constraint.
CUSTOMER_ID NUMBER(6)
ORDER_STATUS NUMBER(2) Y 0: Not fully entered, 1: Entered, 2: Canceled - bad credit,-
3: Canceled - by customer, 4: Shipped - whole order, -
5: Shipped - replacement items, 6: Shipped - backlog on items, -
7: Shipped - special delivery, 8: Shipped - billed, 9: Shipped - payment plan,-
10: Shipped - paid
ORDER_TOTAL NUMBER(8,2) Y CHECK constraint.
SALES_REP_ID NUMBER(6) Y References hr.employees.employee_id.
PROMOTION_ID NUMBER(6) Y Sales promotion ID. Used in SH schema
//将其删除
SQL> alter table oe.orders drop column order_date;
Table altered
//这样我们才可以修改时区
SQL> alter database set time_zone='+8:00';
Database altered
//关闭数据库
//SHUTDOWN is not an SQL command, it is an SQL*Plus command.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
//启动数据库
SQL> startup;
ORACLE instance started.
Total System Global Area 171966464 bytes
Fixed Size 7877988 bytes
Variable Size 145488364 bytes
Database Buffers 25165824 bytes
Redo Buffers 524288 bytes
Database mounted.
Database opened.
//查看时区
SQL> select dbtimezone from dual;
DBTIMEZONE
----------
+08:00
Oracle 11g RAC 远程登录数据库时间和os时间相差16小时解决方案
一个月前帮同事安装11.2.0.4的RAC数据库用于项目压力测试,操作系统为red flag server 3版本。
今天同事突然来电话说数据库时间和os时间相差16个小时,遇到的问题是,2个节点从本地登陆,查看sysdate和os时间一致,但是远程登陆其他节点,数据库时间和os时间相差16个小时,马上怀疑是数据库时区有问题。
经查,数据库时区确实不是东八区,然后停掉应用程序,着手修改数据库时区。
然后重新启动实例,再次查询,数据库时区已经修改,但远程登陆其他节点,数据库时间和os时间依然相差16小时。
然后执行以下SQL:
发现显示的时区为 “-8:00”,为西八区,到这里,问题终于知道出在哪里了。
应该是安装数据库时没有选择好正确的时区,导致数据库时间和os时间相差了16个小时,回想当时安装时选择的是“一般事物用途”,在配置数据库参数的时候没过过多关注数据库时区的问题,才出现这种错误。
那怎么解决呢,多方查找,用以下命令解决:
之后重启数据库实例,再次远程登陆其他节点,数据库时间和os时间已经一致,到此,问题已经解决。同时希望大家不要犯这种类似的错误。
下面摘录网上的一些数据库时区相关的解释,以备参考
Dates & Calendars - Frequently AskedQuestions [ID 227334.1]
Why is my SYSDATE time not the same as my system clock on Unix? Sysdate is just a system call to the OS to get the time (a "gettimeofday" call).
Sysdate does NOT use timezones in the database (select dbtimezone, sessiontimezone from dual . But OS (unix level) TZ settings DO alter the time that the OS will pass on to Oracle.
To debug:
telnet to the unix box and connect using sqlplus in the telnet session:
1) once trought the listener using a tnsnames alias
select to_char(sysdate,'DD-MON-YY HH24:MI:SS') from dual;
2) once trough a "local" ORACLE_SID connection
select to_char(sysdate,'DD-MON-YY HH24:MI:SS') from dual;
if the result is different then it means that the listener is started with a different TZ
then you current user env ->; stop and start listener with the TZ you want .
If you are using RAC then use 'srvctl setenv database -d ; -t TZ=;' to define the correct TZ.
Linux系统,如果修改完/etc/sysconfig/clock和grid配置文件之后,dbtimezone与sessiontimezone、systimestamp时间仍然不一致,可以尝试添加一行oracle用户环境变量vi .bash_profile,如下:
TZ="CST-8"; export TZ
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24162410/viewspace-1809258/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24162410/viewspace-1809258/