## 节点一 [root@rocky9-01:/root]# ll /etc/localtime lrwxrwxrwx.1rootroot35Aug1510:17/etc/localtime->../usr/share/zoneinfo/Asia/Shanghai [root@rocky9-01:/root]# timedatectl Local time:Wed2024-08-21 11:56:42 CST Universal time:Wed2024-08-21 03:56:42 UTC RTC time:Wed2024-08-21 03:56:45 Time zone:Asia/Shanghai(CST,+0800) System clock synchronized:no NTP service:active RTC in local TZ:no
## 节点二 [root@rocky9-02:/root]# ll /etc/localtime lrwxrwxrwx.1rootroot35Aug1510:17/etc/localtime->../usr/share/zoneinfo/Asia/Shanghai [root@rocky9-02:/root]# timedatectl Local time:Wed2024-08-21 11:57:40 CST Universal time:Wed2024-08-21 03:57:40 UTC RTC time:Wed2024-08-21 03:57:43 Time zone:Asia/Shanghai(CST,+0800) System clock synchronized:no NTP service:active RTC in local TZ:no
查看数据库时间:
1 2 3 4 5 6 7 8 9 10 11 12 13
-- 使用 TNS 连接数据库查询时间时区为:上海 +0800 SQL> select SYSTIMESTAMP from dual;
SYSTIMESTAMP --------------------------------------------------------------------------- 21-AUG-24 11.59.33.946355 AM +08:00
-- 使用本地连接数据库查询时间:上海 +0800 SQL> select SYSTIMESTAMP from dual;
SYSTIMESTAMP --------------------------------------------------------------------------- 21-AUG-24 11.59.33.946355 AM +08:00
## 节点一 [root@rocky9-01:/root]# timedatectl Local time:Wed2024-08-21 12:10:03 +07 Universal time:Wed2024-08-21 05:10:03 UTC RTC time:Wed2024-08-21 05:10:03 Time zone:Asia/Ho_Chi_Minh(+07,+0700) System clock synchronized:no NTP service:active RTC in local TZ:no
## 节点二 [root@rocky9-02:/root]# timedatectl Local time:Wed2024-08-21 12:10:07 +07 Universal time:Wed2024-08-21 05:10:07 UTC RTC time:Wed2024-08-21 05:10:07 Time zone:Asia/Ho_Chi_Minh(+07,+0700) System clock synchronized:no NTP service:active RTC in local TZ:no
9) Why is my SYSDATE / SYSTIMESTAMP timenot the same as my system clock on Unix? To debug situations in which you have a unexplained difference between the oracle SYSDATE / SYSTIMESTAMP and the systemtime you see on Unix, use the following method:
telnet/ssh to the Unix box connectusing sqlplus in the telnet session:
1) once through the listener using a tnsnames alias $sqlplus user/password @ [tnsnames alias] SQL>select to_char(sysdate,'DD-MON-YY HH24:MI:SS') from dual;
2) once through a "local" ORACLE_SID connection $env | egrep 'ORACLE_SID' $sqlplus user/password SQL>select to_char(sysdate,'DD-MON-YY HH24:MI:SS') from dual;
Check that the timein the banner of sqlplus ( SQL*Plus: Release10.1.0.4.0- Production on Wo Jan 1115:05:462006 ) is reflecting the time based on the current TZ setin the Unix (!) session.
If the results are different this means that the listener is started with a different TZ setting than you currentuser environment. To resolve this simply stop andstart listener with the TZ setting you want to use. Make sure you doublecheck what listener you areusingwhenhaving multiple listeners. For more information about the TZ variable please see your OS documentation.
11)How do I see &set the TZ environment variable in a RAC environment note 1390015.1 Incorrect SYSDATE shown when connected via Listener in RAC
Note: If you stop andstart a RAC database and/or listener "manual" on Unix (=with sqlplus or lsnrctl) then the above setting isNOT used but the TZ setting of the OS user that starts the database/listener, see point 9)
How to use multiple timezones forcurrent_timestamp ( NOTfor sysdate !) please see Note 1531653.1 How to use multiple timezones withone Oracle RAC database .
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-AUG-2024 12:28:52
Copyright (c) 1991, 2013, Oracle. All rights reserved.
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 21-AUG-2024 13:13:32 Uptime 0 days 0 hr. 15 min. 20 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/rocky9-01/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.6.160)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.6.162)(PORT=1521))) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM1", status READY, has 1 handler(s) for this service... Service "lucifer" has 1 instance(s). Instance "lucifer1", status READY, has 1 handler(s) for this service... Service "luciferXDB" has 1 instance(s). Instance "lucifer1", status READY, has 1 handler(s) for this service... The command completed successfully
通过上面的输出可以发现一个很诡异的现象:
1 2 3 4 5
## 查看监听的时间是 12:30,也就是越南时间 LSNRCTL for Linux: Version 11.2.0.4.0 - Production on21-AUG-202412:30:35
## 然而监听启动时间是 13:13,也就是北京时间,明显是错误的 Start Date 21-AUG-202413:13:32
## 系统时间 [grid@rocky9-01:/home/grid]$ date Wed Aug 21 01:07:01 PM +07 2024 ## 监听时间 [grid@rocky9-01:/home/grid]$ lsnrctl stat
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-AUG-2024 13:07:02
Copyright (c) 1991, 2013, Oracle. All rights reserved.
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 21-AUG-2024 13:05:03 Uptime 0 days 0 hr. 1 min. 59 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/rocky9-01/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.6.160)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.6.162)(PORT=1521))) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM1", status READY, has 1 handler(s) for this service... Service "lucifer" has 1 instance(s). Instance "lucifer1", status READY, has 1 handler(s) for this service... Service "luciferXDB" has 1 instance(s). Instance "lucifer1", status READY, has 1 handler(s) for this service... The command completed successfully
可以看到监听时间和系统时间已经保持一致,再次验证数据库时间:
1 2 3 4 5 6 7 8 9 10 11 12 13
-- 使用 TNS 连接数据库查询时间时区为:越南 +0700 SQL> select SYSTIMESTAMP from dual;
sub s_createConfigEnvFile #--------------------------------------------------------------------- # Function: Create s_crsconfig_$HOST_env.txt file for Time Zone # Args : none # Notes : Valid <env_file> format # (Please keep this in sync with has/utl/crswrapexec.pl) # * Empty lines: lines with all white space # * Comments: line starts with #. # * <key>=<value> # * <key> is all non-whitespace characters on the left of the # first "=" character. # * <value> is everything on the right of the first "=" character # (including whitespaces). # * Surrounding double-quote (") won't be stripped. # * Key with blank <value> ('') will be undefined. # (e.g: Hello=, Hello will be undefined) #--------------------------------------------------------------------- { my $env_file = catfile($ORA_CRS_HOME, 'crs', 'install', 's_crsconfig_' . $HOST . '_env.txt');
open (ENVFILE, ">$env_file") or die "Can't create $env_file: $!";
print ENVFILE "### This file can be used to modify the NLS_LANG environment" . " variable, which determines the charset to be used for messages.\n" . "### For example, a new charset can be configured by setting" . " NLS_LANG=JAPANESE_JAPAN.UTF8 \n" . "### Do not modify this file except to change NLS_LANG," . " or under the direction of Oracle Support Services\n\n";
# get TZ if ($CFG->defined_param('TZ')) { my $tz = $CFG->params('TZ'); $tz =~ s/'//g; # remove single quotes print ENVFILE "TZ=" . $tz . "\n"; } ... ... ... }
# pull all parameters defined in crsconfig_params and s_crsconfig_defs (if # it exists) as variables in Perl my $paramfile_default = catfile (dirname ($0), "crsconfig_params");
our $PARAM_FILE_PATH = $paramfile_default;
# Read the config files and set up the configuration data for # subsequent processing my $cfg = crsconfig_lib->new(IS_SIHA => FALSE, paramfile => $PARAM_FILE_PATH, osdfile => $defsfile, addfile => $addparams, crscfg_trace => TRUE, CRSDelete => $g_delete, DEBUG => $DEBUG, HAS_USER => $SUPERUSER, HOST => $HOST, UPGRADE => $UPGRADE, UNLOCK => $g_unlock, unlock_crshome => $unlock_crshome, CRSPatch => $g_patch, DOWNGRADE => $DOWNGRADE, oldcrshome => $oldcrshome, oldcrsver => $oldcrsver, force => $g_force, deinstall => $g_deinstall, keepdg => $g_keepdg, lastnode => $g_lastnode, REMOTENODE => $REMOTENODE, destcrshome => $destcrshome );
## $GRID_HOME/cfgtoollogs/oui/installActions2024-08-15_04-05-22PM.log INFO: The default response file generated with recorded values is /u01/app/11.2.0/grid/inventory/response/oracle.crs_Complete.rsp INFO: -destinationFile option was not provided. Saving the default response file as /u01/app/11.2.0/grid/inventory/response/oracle.crs_Complete.rsp INFO: Recording the installation in file/u01/app/11.2.0/grid/inventory/response/oracle.crs_Complete.rsp.
INFO: Reading global variables fromfile/soft/grid/install/../stage/globalvariables/globalvar.xml
INFO: ---------------------------------------------------------------------------------------------------- INFO: PROPERTY VALUE INFO: ---------------------------------------------------------------------------------------------------- INFO: oracle_install_crs_Timezone Asia/Shanghai INFO: adding the variable oracle_install_crs_Timezone to command line args table INFO: Setting variable 'oracle_install_crs_Timezone' to 'Asia/Shanghai'. Received the value from the command line.
## $GRID_HOME/install/root_rocky9-01_2024-08-15_16-14-17.log Using configuration parameter file: /u01/app/11.2.0/grid/crs/install/crsconfig_params
## $GRID_HOME/cfgtoollogs/crsconfig/rootcrs_rocky9-01.log 2024-08-1516:14:17: The configuration parameter file/u01/app/11.2.0/grid/crs/install/crsconfig_params is valid 2024-08-1516:14:17: ### Printing the configuration values from files: 2024-08-1516:14:17: /u01/app/11.2.0/grid/crs/install/crsconfig_params 2024-08-1516:14:17: paramfile=/u01/app/11.2.0/grid/crs/install/crsconfig_params