记录一次通过Listener访问RAC显示不正确的sysdate

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxzhaobb/article/details/88827452

RDBMS 11.2.0.4  的RAC

OS redhat 6.9 , 时间设置UTC 。

今天开发说在查询一些表的时候,发现一些时间字段有问题。排查了下,的确发现通过toad /plsql developer等工具查询sysdate的时候,的确显示的北京时间。正常应该显示的是UTC时间。但是,直接在服务器上本地认证查询sysdate的时候,显示的是UTC时间。使用WIndows的CMD窗口来查询还是显示是北京时间(该Windows设置的时间就是UTC时间)。

一共有3套RAC,时间设置都是UTC,其中上个月新安装的那套,查询没有问题。检查OS设置,就是UTC时间。因此这个问题还比较郁闷。

查询出来就是这样的

刚开始,以为是OS的时区设置有问题,检查了没有问题。后将节点1重启,然后直接连接到节点1的VIP地址上,发现查询的时间就是UTC时间,以为找到方法了,于是两个节点都重启了 ,启动后,发现连接到VIP上又变回了北京时间。有点郁闷。

后来在群里咨询,盖国强提示“监听器方式读取时区文件不一样” 。顿时有了思路。

于是,关闭掉其中的一个监听器,再次打开。出现了有意思的事情。注意看监听器显示的时间是UTC时间,显示的启动时间是北京时间。

[grid@oracleabca1 ~]$ lsnrctl

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 26-MAR-2019 07:09:23

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                26-MAR-2019 14:59:40
Uptime                    0 days 0 hr. 9 min. 44 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/oracleabca1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.254.71)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.254.73)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "abc" has 1 instance(s).
  Instance "abc1", status READY, has 1 handler(s) for this service...
Service "abcXDB" has 1 instance(s).
  Instance "abc1", status READY, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL> 


[grid@oracleabca2 ~]$ lsnrctl

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 26-MAR-2019 07:09:52

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                26-MAR-2019 14:59:17
Uptime                    0 days 0 hr. 10 min. 35 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/oracleabca2/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.254.72)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.254.74)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "abc" has 1 instance(s).
  Instance "abc2", status READY, has 1 handler(s) for this service...
Service "abcXDB" has 1 instance(s).
  Instance "abc2", status READY, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL> 

后来又经盖国强提示,MOS上有这方面的说明。于是MOS上查询listener time 。查询出了一篇文章

Incorrect SYSDATE shown when connected via Listener in RAC (文档 ID 1390015.1)

根据这篇文章,进行了设置,在设置之前,现在测试环境中进行了测试 。

MOS上提到的原因:

- Listener might have a different Envs variable setting for Timezone
 
- Listener is started by LSNRCTL instead of SRVCTL or vice versa
 
- PMON only reads the OS environment variables when the database is started. If TZ is changed after the database is started PMON will not pick up the changed value.

When dynamic database service registration is enabled to a listener, PMON both registers the service name and also the environment variables for the database associated with that service name. This means that connections via the dynamically registered service handler will continue to use the old TZ timezone setting.
If the listener is restarted and also has a static service registration, connection via the listener will use the TZ set in the listener until PMON first re-registers the service handler again. When the listener has two service registrations, one static and one dynamic, then the dynamic one will be used.

解决方法

有句话是这样的

For 11.2.0.2 and above the TZ entry in $GRID_HOME/crs/install/s_crsconfig_<nodename>_env.txt sets to correct time zone! This enables resources started under the Grid Infrastructure home (listener, databases) using the timezone set in here and so has no requirement anymore to set TZ for DB and listener via setenv. For more details see: How To Change Timezone for 11gR2 Grid Infrastructure ( Document 1209444.1)

查看这个文件,发现TZ是PRC 

[root@oracleabca1 install]# more s_crsconfig_oracleabca1_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 setting NLS_LANG=JAPANESE_JAPAN.UTF8 
### Do not modify this file except to change NLS_LANG, or under the direction of Oracle Support Services

TZ=PRC
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
TNS_ADMIN=
ORACLE_BASE=
[root@oracleabca1 install]# 

再查看一个测试环境中的,该环境使用的是UTC ,查询时间没有问题。

[grid@oraclemq1 install]$ cat s_crsconfig_oraclemq1_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 setting NLS_LANG=JAPANESE_JAPAN.UTF8 
### Do not modify this file except to change NLS_LANG, or under the direction of Oracle Support Services

TZ=Universal
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
TNS_ADMIN=
ORACLE_BASE=
[grid@oraclemq1 install]$ 

再查看自己的一个测试环境的。安装OS的时候,设置的时区就是HK。装了RAC就是TZ就是Hongkong。

[grid@rac01 install]$ more s_crsconfig_rac01_env.txt 
### This file can be used to modify the NLS_LANG environment variable, which determines the ch
arset to be used for messages.
### For example, a new charset can be configured by setting NLS_LANG=JAPANESE_JAPAN.UTF8 
### Do not modify this file except to change NLS_LANG, or under the direction of Oracle Suppor
t Services

TZ=Hongkong
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
TNS_ADMIN=
ORACLE_BASE=
[grid@rac01 install]$ date
Sun Mar 17 13:50:50 HKT 2019
[grid@rac01 install]$ 

现在来解决问题

1 检查DB和Listener的环境变量

[grid@oracleabca1 ~]$ srvctl getenv database -d abc
abc:
[grid@oracleabca1 ~]$ srvctl getenv nodeapps -n oracleabca1
-n <node_name> option has been deprecated and is ignored.
VIP environment variables:
oracleabca1-vip:
oracleabca2-vip:
GSD environment variables:
gsd:
ONS environment variables:
ons:
[grid@oracleabca1 ~]$ 
[grid@oracleabca1 ~]$ srvctl getenv listener
LISTENER:
ORACLE_BASE=/u01/app/grid
[grid@oracleabca1 ~]$ 

2 进行修复,其实在其中一个节点上执行就可以了

[root@oracleabcb1 grid]# srvctl setenv database -d abc -t 'TZ=Etc/UTC'
[root@oracleabcb1 grid]# srvctl setenv nodeapps -n oracleabcb1 -t 'TZ=Etc/UTC'
-n <node_name> option has been deprecated and is ignored.
[root@oracleabcb1 grid]# srvctl setenv listener -l LISTENER -t 'TZ=Etc/UTC'
[root@oracleabcb1 grid]# 

3 重启CRS 。

4 查看结果,之前这里只显示数据库名称,并没有时区哪一行。

[grid@oracleabca1 ~]$ srvctl getenv database -d abc 
abc:
TZ=Etc/UTC
[grid@oracleabca1 ~]$ 

再次查看sysdate,发现正常了,返回的是UTC时间。

到此,问题解决,最后,感谢盖国强。 

END

猜你喜欢

转载自blog.csdn.net/xxzhaobb/article/details/88827452