在Linux操作系统上,Oracle数据库的时区和以下几个因素有关:
1. /etc/localtime
这个文件记录的是系统的时区,缺省的数据库由此获得时区信息
这个文件是二进制文件,修改该文件的方法是拷贝/usr/share/zoneinfo下的相应时区文件覆盖 localtime 文件。
/etc/sysconfig/clock 与 localtime 配置,定义的是时区名称区域信息等。
2./usr/share/zoneinfo/
该目录存储所有合法的时区信息,如果会话设置的时区和系统时区不一致,则由此读取时区信息。
3.$ORACLE_HOME/oracore/zoneinfo
这里存储的文件记录数据库的合法时区,和操作系统提供的信息会进行对比。
-rw-rw-r--. 1 oracle oinstall 1407 Jun 1 2009 readme.txt
-rw-rw-r--. 1 oracle oinstall 408315 Apr 14 2010 timezlrg.dat
-rw-rw-r--. 1 oracle oinstall 160733 Apr 14 2010 timezone.dat4.Linux上的时区信息可以通过 tzselect 命令查看,使用 timeconfig 进行配置修改
5.会话级别的时区设置可以如下进行
TZ='Asia/Shanghai';export TZ
6.hwclock -w
保存时区设置使之重启系统后仍生效
关于Oracle的时区选项与时区关系,可以通过strace跟踪进程,清晰的获得整个流程:
分析整个过程中的文件读取:
open("/etc/ld.so.preload", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/tls/x86_64/libsqlplus.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/u01/app/oracle/product/10.2.0/db_1/lib/tls/libsqlplus.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/u01/app/oracle/product/10.2.0/db_1/lib/x86_64/libsqlplus.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/u01/app/oracle/product/10.2.0/db_1/lib/libsqlplus.so", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libnnz10.so", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
open("/lib64/libdl.so.2", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libm.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libm.so.6", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libpthread.so.0", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libnsl.so.1", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libc.so.6", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/lib/libsqlplusic.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/u01/app/oracle/product/10.2.0/db_1/lib/libociicus.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/u01/app/oracle/product/10.2.0/db_1/lib/libociei.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx1boot.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx00001.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx20354.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx10001.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx40011.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx20001.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/nls/data/lx40001.nlb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/sqlplus/mesg/sp1us.msb", O_RDONLY) = 3
open("/u01/app/oracle/product/10.2.0/db_1/sqlplus/mesg/sp2us.msb", O_RDONLY) = 4
open("/u01/app/oracle/product/10.2.0/db_1/sqlplus/mesg/cpyus.msb", O_RDONLY) = 5
open("/usr/share/zoneinfo/Asia/Shanghai", O_RDONLY) = 6
open("/u01/app/oracle/product/10.2.0/db_1/oracore/zoneinfo/timezlrg.dat", O_RDONLY) = 6
open("/u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/ocius.msb", O_RDONLY) = 6可以看到Oracle读取的操作系统时区文件:
/usr/share/zoneinfo/Asia/Shanghai
这是跟进环境变量的设置读取的,数据库的时区文件则是:
/u01/app/oracle/product/10.2.0/db_1/oracore/zoneinfo/timezlrg.dat
这整个验证过程和Oracle的字符集完全相同,很有意思。