Oracle 11g RAC 远程登录数据库时间和OS时间相差16小时解决方案


帮同事安装Oracle 11.2.0.4的RAC数据库用于项目压力测试,操作系统为red flag server 3版本。

今天同事突然来电话说数据库时间和os时间相差16个小时,遇到的问题是,2个节点从本地登陆,查看sysdate和os时间一致,但是远程登陆其他节点,数据库时间和os时间相差16个小时,马上怀疑是数据库时区有问题。

经查,数据库时区确实不是东八区,然后停掉应用程序,着手修改数据库时区。

alter database set time_zone='+8:00';

然后重新启动实例,再次查询,数据库时区已经修改,但远程登陆其他节点,数据库时间和os时间依然相差16小时。

然后执行以下SQL:

select systimezone from dual;

发现显示的时区为  “-8:00”,为西八区,到这里,问题终于知道出在哪里了。

应该是安装数据库时没有选择好正确的时区,导致数据库时间和os时间相差了16个小时,回想当时安装时选择的是“一般事物用途”,在配置数据库参数的时候没过过多关注数据库时区的问题,才出现这种错误。

那怎么解决呢,多方查找,用以下命令解决:

srvctl setenv database -d <dbname> -t TZ=EAT-8

之后重启数据库实例,再次远程登陆其他节点,数据库时间和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 <dbname>; -t TZ=<the TZ you want>;' to define the correct TZ.

Oracle 11g RAC 本地时间和通过listener连接时间不相同的问题 

相关内容