数据库时间灵异事件

[复制链接]
查看11 | 回复6 | 2012-12-21 12:39:59 | 显示全部楼层 |阅读模式
本帖最后由 yongzhi2008 于 2013-3-19 08:31 编辑
本来要添加一个job 定时执行一个任务, 添加之后发现next_date 时间不对, 困惑中却发现以下灵异事件:
1、select sysdate from dual 查询出来的时间是正常的, 而job中的时间确快了一个小时。 系统的时间也是正确的, 跟select sysdate from dual 查询的时间一致。
2、在客户端用sqlplus连接数据库, 查询系统时间确实快一个小时, 在服务器本地查询却是正常的。
下面是演示:
在数据库服务器上:
[oracle@ora02 ~]$ sqlplus ZHAOPIN_USER/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 18 23:22:55 2013
Copyright (c) 1982, 2011, Oracle.All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select job, log_user, last_date,next_date, interval, what from user_jobs;
no rows selected
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:11:57
SQL> begin
2dbms_job.submit(:jobno,'begin proc_test; end;', sysdate + 10/1440, 'sysdate+2/24');
3end;
4/
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:12:26
SQL> select job, log_user, last_date,next_date, interval, what from user_jobs;
JOB LOG_USER
LAST_DATE NEXT_DATE INTERVAL
WHAT
---------- ------------------------------ ------------------- ------------------- ------------------------------ ------------------------------
90 ZHAOPIN_USER
2013-03-19 00:12:21 2013-03-19 02:12:21 sysdate+2/24
begin proc_test; end;
--刚刚添加, last_date 就有值了, 说明已经执行了, 执行时间为添加时的时间, 但是next_date 却是正常的。 再次确认时间:
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:13:01
SQL> ! date
Mon Mar 18 23:15:01 GMT+08:00 2013
SQL> /
SYSDATE
-------------------
2013-03-18 23:15:37
SQL> begin
2dbms_job.submit(:jobno,'begin proc_test; end;', sysdate + 10/1440, 'sysdate+2/24');
3commit;
4end;
5/
PL/SQL procedure successfully completed.
SQL> select job, log_user, last_date,next_date, interval, what from user_jobs;
JOB LOG_USER
LAST_DATE NEXT_DATE INTERVAL
WHAT
---------- ------------------------------ ------------------- ------------------- ------------------------------ ------------------------------
91 ZHAOPIN_USER
2013-03-19 00:16:01 2013-03-19 02:16:01 sysdate+2/24
begin proc_test; end;
90 ZHAOPIN_USER
2013-03-19 00:12:21 2013-03-19 02:12:21 sysdate+2/24
begin proc_test; end;
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:16:16
--从客户端连接,发现时间提前了一个小时
[oracle@oracle admin]$ sqlplus zhaopin_user/oracle@ncssdb2;
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 3月 18 23:19:25 2013
Copyright (c) 1982, 2005, Oracle.All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ncssdb2>select sysdate from dual;
SYSDATE
-------------------
2013-03-19 00:19:30
--tnsnames.ora 文件中对ncssdb2 的配置
ncssdb2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.15.102)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ncssdb)
)
)
[oracle@ora02 ~]$ ping ora02
PING ora02: (192.168.15.102): 56 data bytes
64 bytes from 192.168.15.102: icmp_seq=0 ttl=255 time=0 ms
64 bytes from 192.168.15.102: icmp_seq=1 ttl=255 time=0 ms
[oracle@ora02 ~]$ lsnrctl status
LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 18-MAR-2013 23:50:36
Copyright (c) 1991, 2011, Oracle.All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias
LISTENER
Version
TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
Start Date
08-MAR-2013 14:53:40
Uptime
10 days 8 hr. 56 min. 55 sec
Trace Level
off
Security
ON: Local OS Authentication
SNMP
ON
Listener Parameter File /u01/oracle/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/oracle/app/grid/diag/tnslsnr/ora02/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.15.102)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.15.202)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "ncssdb" has 1 instance(s).
Instance "ncssdb2", status READY, has 1 handler(s) for this service...
Service "ncssdbXDB" has 1 instance(s).
Instance "ncssdb2", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@ora02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 18 23:21:53 2013
Copyright (c) 1982, 2011, Oracle.All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:21:57
系统为RAC, 前几天一个节点因为夏令时的原因出现过时间提前一个小时的情况。 当时直接把那节点停掉了一个多小时, 服务器时间同步后, 再将节点重启就解决了时间不同步的问题。
本以为没有问题了, 谁想另一个节点的时间居然又快了一个小时, 而且用select sysdate from dual 还不容易查询出来。
真是乱套了!后将数据库重启, 遂解决了此问题。
--数据库重启之后:
[oracle@ora02 ~]$ sqlplus zhaopin_user/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 18 23:34:26 2013
Copyright (c) 1982, 2011, Oracle.All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:34:53
SQL> var jobno number;
SQL> begin
2dbms_job.submit(:jobno,'begin proc_test; end;', sysdate + 10/1440, 'sysdate+2/24');
3end;
4/
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> print jobno;
JOBNO
----------
94
SQL> set line 180;
SQL> col what for a30;
SQL> col log_user for a15;
SQL> col interval for a40;
SQL> /
Commit complete.
SQL> select job, log_user, last_date,next_date, interval, what from user_jobs;
JOB LOG_USERLAST_DATE NEXT_DATE INTERVAL
WHAT
---------- --------------- ------------------- ------------------- ---------------------------------------- ------------------------------
91 ZHAOPIN_USER2013-03-19 00:16:01 2013-03-19 02:16:01 sysdate+2/24
begin proc_test; end;
90 ZHAOPIN_USER2013-03-19 00:12:21 2013-03-19 02:12:21 sysdate+2/24
begin proc_test; end;
92 ZHAOPIN_USER2013-03-19 00:25:57 2013-03-19 02:25:57 sysdate+2/24
begin proc_test; end;
93 ZHAOPIN_USER2013-03-19 00:27:27 2013-03-19 02:27:27 sysdate+2/24
begin proc_test; end;
94 ZHAOPIN_USER
2013-03-18 23:45:09 sysdate+2/24
begin proc_test; end;
SQL> select sysdate from dual;
SYSDATE
-------------------
2013-03-18 23:36:26

另外, 重新从客户端用sqlplus连接, 查询时间正常了。

这里粗略介绍一下, 大家有何高见, 欢迎回帖呀, 谢谢,呵呵。



回复

使用道具 举报

千问 | 2012-12-21 12:39:59 | 显示全部楼层
本帖最后由 uranusxt 于 2013-3-19 02:47 编辑
there is a bug when connecting remotely database is not showing the timestamp reflecting the correct timezone.
workaround is to set the timezone in srvctl, and use srvctl to start the database.
double check your timezone settings.
回复

使用道具 举报

千问 | 2012-12-21 12:39:59 | 显示全部楼层
重启之后用你的10G的客户端连接一下,时间也没有问题了?
回复

使用道具 举报

千问 | 2012-12-21 12:39:59 | 显示全部楼层
vage 发表于 2013-3-19 06:59
重启之后用你的10G的客户端连接一下,时间也没有问题了?

没有问题了。
回复

使用道具 举报

千问 | 2012-12-21 12:39:59 | 显示全部楼层
是否是时区设置问题?
看一下job中的环境设置
回复

使用道具 举报

千问 | 2012-12-21 12:39:59 | 显示全部楼层
bedba 发表于 2013-3-19 08:28
是否是时区设置问题?
看一下job中的环境设置

数据库重启前后, 时区没有改变过。
客户端时区:
[oracle@oracle ~]$ date -R
Tue, 19 Mar 2013 08:43:00 +0800
[oracle@oracle ~]$ date
Tue Mar 19 08:43:34 CST 2013

服务器时区:
SQL> ! date
Tue Mar 19 08:40:43 GMT+08:00 2013
job 环境变量如下, 第一个是客户端连接数据库添加的, 第二个是直接在服务器上添加的。
SQL> select nls_env from user_jobs;
NLS_ENV
--------------------------------------------------------------------------------
NLS_LANGUAGE='SIMPLIFIED CHINESE' NLS_TERRITORY='CHINA' NLS_CURRENCY='¥' NLS_IS
O_CURRENCY='CHINA' NLS_NUMERIC_CHARACTERS='.,' NLS_DATE_FORMAT='YYYY-MM-DD HH24:
MI:SS' NLS_DATE_LANGUAGE='SIMPLIFIED CHINESE' NLS_SORT='BINARY'
NLS_LANGUAGE='AMERICAN' NLS_TERRITORY='AMERICA' NLS_CURRENCY='$' NLS_ISO_CURRENC
Y='AMERICA' NLS_NUMERIC_CHARACTERS='.,' NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
NLS_DATE_LANGUAGE='AMERICAN' NLS_SORT='BINARY'



回复

使用道具 举报

千问 | 2012-12-21 12:39:59 | 显示全部楼层
[oracle@ora02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 19 09:56:04 2013
Copyright (c) 1982, 2011, Oracle.All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select dbtimezone from dual;
DBTIME
------
+00:00
SQL> select sessiontimezone from dual;
SESSIONTIMEZONE
---------------------------------------------------------------------------
+08:00
SQL> SELECT TZ_OFFSET(SESSIONTIMEZONE), TZ_OFFSET(DBTIMEZONE) FROM DUAL;
TZ_OFFS TZ_OFFS
------- -------
+08:00+00:00
SQL> ! date
Tue Mar 19 10:30:21 GMT+08:00 2013
数据库时区是不是存在问题, 需要将数据库时区也修改成+08:00吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行