ORACLE的Scheduler的时区总结

嚴華  金牌会员 | 2023-9-13 04:53:05 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 912|帖子 912|积分 2736

在Oracle数据库中,一般人们可能只会关注数据库的时区或会话的时区,但是很少有人会关注Scheduler的时区设置,因为Scheduler的时区设置一般只会影响作业的scheduler和Windows的运行,很多时候,人们往往没有注意到它。这里简单总结一下这个知识点。
在Oracle 10g/11g中,数据库的scheduler的时区是全局统一的,但是从Oracle 12c开始,多租户架构中,CDB和各个PDB的scheduler的时区设置是分开的。我们一般可以通过下面几种方法查看数据库的scheduler时区信息
方法1:
  1. select dbms_scheduler.stime from dual;
复制代码
方法2:

  1. set linesize 680
  2. col attribute_name for a20
  3. col value for a30
  4. select * from dba_scheduler_global_attribute 
  5. where attribute_name like '%TIMEZONE%';
复制代码
方法3:

get_scheduler_attributes.sql脚本
  1. SET SERVEROUTPUT ON
  2. show con_name;
  3. EXEC DBMS_OUTPUT.put_line(RPAD('-',60,'-'));
  4. DECLARE
  5.   PROCEDURE display(p_param IN VARCHAR2) AS
  6.     l_result VARCHAR2(50);
  7.   BEGIN
  8.     DBMS_SCHEDULER.get_scheduler_attribute(
  9.       attribute => p_param,
  10.       value     => l_result);
  11.     DBMS_OUTPUT.put_line(RPAD(p_param, 30, ' ') || ' : ' || l_result);
  12.   END;
  13. BEGIN
  14.   display('current_open_window');
  15.   display('default_timezone');
  16.   display('email_sender');
  17.   display('email_server');
  18.   display('event_expiry_time');
  19.   display('log_history');
  20.   display('max_job_slave_processes');
  21. END;
  22. /
复制代码
如下所示,我们在CDB容器下,查看数据库的Scheduler时区信息,如下所示,第一个SQL可以判断为东八区设置,其它两个SQL的值为null,表示使用systimestamp的时区。而当前systimestamp的时区为东八区
  1. SQL> select dbms_scheduler.stime from dual;
  2. STIME
  3. ---------------------------------------------------------------------------
  4. 11-SEP-23 10.04.37.395374000 PM +08:00
  5. SQL> set linesize 680
  6. SQL> col attribute_name for a20
  7. SQL> col value for a30
  8. SQL> select * from dba_scheduler_global_attribute 
  9.   2  where attribute_name like '%TIMEZONE%';
  10. ATTRIBUTE_NAME       VALUE
  11. -------------------- ------------------------------
  12. DEFAULT_TIMEZONE
  13. SQL> @get_scheduler_attributes.sql
  14. CON_NAME
  15. ------------------------------
  16. CDB$ROOT
  17. ------------------------------------------------------------
  18. PL/SQL procedure successfully completed.
  19. current_open_window            : MONDAY_WINDOW
  20. default_timezone               :
  21. email_sender                   :
  22. email_server                   :
  23. event_expiry_time              :
  24. log_history                    : 30
  25. max_job_slave_processes        :
  26. PL/SQL procedure successfully completed.
  27. SQL> 
复制代码
官方文档[1]中的介绍如下
  1. When start_date is NULL, the Scheduler determines the time zone for the repeat interval as follows:

  2. It checks whether or not the session time zone is a region name. The session time zone can be set by either:

  3. Issuing an ALTER SESSION statement, for example:

  4. SQL> ALTER SESSION SET time_zone = 'Asia/Shanghai';



  5. Setting the ORA_SDTZ environment variable.

  6. If the session time zone is an absolute offset instead of a region name, the Scheduler uses the value of the DEFAULT_TIMEZONE Scheduler attribute. For more information, see the SET_SCHEDULER_ATTRIBUTE Procedure.

  7. If the DEFAULT_TIMEZONE attribute is NULL, the Scheduler uses the time zone of systimestamp when the job or window is enabled.
复制代码
在Oracle 19c中,一般用DBCA创建的PDB数据库,它的scheduler时区默认为PST8PDT, 如下所示,PST8PDT其实是美国的太平洋标准时间,是美国西部城市的主要计时制度。就和我们的北京时间类似。中国是统一使用北京时间,但是美国东西部使用不同的时间制度。美国东部有西5区,西6区等,PST8PDT就是西8区的时间。
关于这个问题,其实官方文档Default Scheduler Timezone Value In PDB$SEED Different Than CDB (Doc ID 2702230.1)[2]有阐述这个现象。
  1. On 12C, 18c and 19c, using DBCA General mode create DB, the default timezone of scheduler of PDB is different with CDB$ROOT.
  2. The default timezone of the scheduler of PDB is PST8PDT on 19c and Etc/UTC on 12C & 18c no matter what the timezone of the scheduler is in CDB$ROOT.
  3. But using create database command or using DBCA customize mode, the default timezone of the scheduler of PDB is same with CDB$ROOT.
  4. It is expected behavior. 
  5. Please refer to the below bug raised an enhancement request.
  6.   Unpublished Bug 30076391 : DIFFERENT TIMEZONES OF SCHEDULER IN CDB$ROOT AND PDB USING DBCA GENERAL MODE CREATE DB
复制代码
这个现象,如果你没有注意到,可能Scheduler的运行时间跟你所预期的不一样。例如,数据库采集、更新统计信息的时间,这个影响说大其实影响也蛮大的。可能导致在白天业务高峰期,数据库正在收集统计信息。所以,一般你在创建对应的PDB数据库时,就必须检查/设置Scheduler的时区。
设置scheduler的时区
  1. exec dbms_scheduler.set_scheduler_attribute('default_timezone', 'Asia/Shanghai');
复制代码
参考资料

[1] 1: https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_SCHEDULER.html#GUID-2D8930DD-1042-4FA9-A0C0-2E4C7A7BFE9B
[2] 2: https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=122259819987503&id=2702230.1&_afrWindowMode=0&_adf.ctrl-state=bngoz01qg_129
扫描上面二维码关注我如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

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

本版积分规则

嚴華

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表