博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle中sysdate的时区偏差
阅读量:4028 次
发布时间:2019-05-24

本文共 1708 字,大约阅读时间需要 5 分钟。

转自: www.fengbin.com/2011/10/oracle-sysdate-timezone.html
国庆前有个应用上线,让DBA装了一个双机的Oracle RAC,装好后发现数据的sysdate不太对头,和机器时间差了16小时。这个问题后来解决了,也不复杂,只是这个过程异常曲折。
网上有很多帖子说到了这个问题,操作系统本身的时间是正确的,Oracle里的current_date、current_timestamp都是正常的,就是sysdate有问题。提供的解决方法都是类似的一条命令:
srvctl setenv database -d <dbname> -t TZ=EAT-8
看起来容易理解,差了16小时,可能是时区不对,于是把时区改成东八区(EAT-8),可DBA试了几次,都不见效果。其间也请教过其他人,也怀疑过是不是操作系统装的有问题,打算重装系统。直到在网上看到另外一段资料,才明白了其中的奥秘。
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.
这段文字说sysdate是调用操作系统里的gettimeofday函数,不依赖oracle数据库里设置的时区,用的是操作系统的时区。而对linux来说,就是环境变量里设置的时区。按照这个解释,运行之前命令是正确的,问题就出在TZ的值上。
运行命令
cat /etc/sysconfig/clock
看到的时区是Asia/Beijing,而不是EAT-8,再到系统目录/usr/share/zoneinfo下查询,发现没有EAT-8。于是修改以前的命令,把TZ设成Asia/Beijing,问题解决。
在此之前,已经有人有过这方面的提示,只是当时不是很清楚数据库里面的机制,误打误撞,总是设不对,明白原理之后,也就有的放矢了。
改Oracle的时区设置。
如ALTER DATABASE SET TIME_ZONE='+8.00';
修改之后,重新启动Oracle数据库。

转载地址:http://immbi.baihongyu.com/

你可能感兴趣的文章
Vue-子组件改变父级组件的信息
查看>>
Python自动化之pytest常用插件
查看>>
Python自动化之pytest框架使用详解
查看>>
【正则表达式】以个人的理解帮助大家认识正则表达式
查看>>
性能调优之iostat命令详解
查看>>
性能调优之iftop命令详解
查看>>
非关系型数据库(nosql)介绍
查看>>
移动端自动化测试-Windows-Android-Appium环境搭建
查看>>
Xpath使用方法
查看>>
移动端自动化测试-Mac-IOS-Appium环境搭建
查看>>
Selenium之前世今生
查看>>
Selenium-WebDriverApi接口详解
查看>>
Selenium-ActionChains Api接口详解
查看>>
Selenium-Switch与SelectApi接口详解
查看>>
Selenium-Css Selector使用方法
查看>>
Linux常用统计命令之wc
查看>>
测试必会之 Linux 三剑客之 sed
查看>>
Socket请求XML客户端程序
查看>>
Java中数字转大写货币(支持到千亿)
查看>>
Java.nio
查看>>