手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2015-01-29] 来源:Linux社区  作者:453603647 [字体:大 中 小]

帮同事安装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连接时间不相同的问题  http://www.linuxidc.com/Linux/2012-12/76975.htm

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/112546.htm

linux
相关资讯       Oracle 11g RAC 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款