Bo's Oracle Station

查看: 1543|回复: 0

远程外部作业(甚至是Windows)课程第48次(2017-10-26星期四)

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-10-24 21:32:51 | 显示全部楼层 |阅读模式
1Z0-053第17章
1Z0-05219章(上完13章),1Z0-05321章(上完15章)和1Z0-063多租户部分共9章(上完0章)
总共上完全部49章中的28
服务器端要做:

  1. [root@station26 ~]# su - oracle
  2. [oracle@station26 ~]$ lsnrctl services

  3. LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 24-OCT-2017 21:20:13

  4. Copyright (c) 1991, 2014, Oracle.  All rights reserved.

  5. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
  6. Services Summary...
  7. Service "+ASM" has 1 instance(s).
  8.   Instance "+ASM", status READY, has 1 handler(s) for this service...
  9.     Handler(s):
  10.       "DEDICATED" established:5505 refused:0 state:ready
  11.          LOCAL SERVER
  12. Service "cdb1" has 1 instance(s).
  13.   Instance "cdb1", status READY, has 1 handler(s) for this service...
  14.     Handler(s):
  15.       "DEDICATED" established:8037 refused:0 state:ready
  16.          LOCAL SERVER
  17. Service "cdb1XDB" has 1 instance(s).
  18.   Instance "cdb1", status READY, has 1 handler(s) for this service...
  19.     Handler(s):
  20.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  21.          DISPATCHER <machine: station26.example.com, pid: 10924>
  22.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=46517))
  23. Service "orcl" has 1 instance(s).
  24.   Instance "orcl", status READY, has 1 handler(s) for this service...
  25.     Handler(s):
  26.       "DEDICATED" established:19901 refused:0 state:ready
  27.          LOCAL SERVER
  28. Service "orcl2" has 1 instance(s).
  29.   Instance "orcl2", status READY, has 1 handler(s) for this service...
  30.     Handler(s):
  31.       "DEDICATED" established:20960 refused:0 state:ready
  32.          LOCAL SERVER
  33. Service "orcl2XDB" has 1 instance(s).
  34.   Instance "orcl2", status READY, has 1 handler(s) for this service...
  35.     Handler(s):
  36.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  37.          DISPATCHER <machine: station26.example.com, pid: 13973>
  38.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=19539))
  39. Service "orclXDB" has 1 instance(s).
  40.   Instance "orcl", status READY, has 1 handler(s) for this service...
  41.     Handler(s):
  42.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  43.          DISPATCHER <machine: station26.example.com, pid: 13328>
  44.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=27200))
  45. Service "pdb1_1" has 1 instance(s).
  46.   Instance "cdb1", status READY, has 1 handler(s) for this service...
  47.     Handler(s):
  48.       "DEDICATED" established:8037 refused:0 state:ready
  49.          LOCAL SERVER
  50. The command completed successfully
  51. [oracle@station26 ~]$ sqlplus /nolog

  52. SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 24 21:20:20 2017

  53. Copyright (c) 1982, 2014, Oracle.  All rights reserved.

  54. SQL> conn / as sysdba
  55. Connected.
  56. SQL> show parameter dispa

  57. NAME                                     TYPE         VALUE
  58. ------------------------------------ ----------- ------------------------------
  59. dispatchers                             string         (PROTOCOL=TCP) (SERVICE=orclXD
  60.                                                  B)
  61. max_dispatchers                      integer
  62. SQL> alter system set dispatchers='(PROTOCOL=TCP) (dispatchers=3)';  

  63. System altered.

  64. SQL> show parameter shared_ser

  65. NAME                                     TYPE         VALUE
  66. ------------------------------------ ----------- ------------------------------
  67. max_shared_servers                     integer
  68. shared_server_sessions                     integer
  69. shared_servers                             integer         1
  70. SQL> alter system set shared_servers=3 ;

  71. System altered.

  72. SQL> exit
  73. Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
  74. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
  75. [oracle@station26 ~]$ lsnrctl services

  76. LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 24-OCT-2017 21:21:24

  77. Copyright (c) 1991, 2014, Oracle.  All rights reserved.

  78. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
  79. Services Summary...
  80. Service "+ASM" has 1 instance(s).
  81.   Instance "+ASM", status READY, has 1 handler(s) for this service...
  82.     Handler(s):
  83.       "DEDICATED" established:5505 refused:0 state:ready
  84.          LOCAL SERVER
  85. Service "cdb1" has 1 instance(s).
  86.   Instance "cdb1", status READY, has 1 handler(s) for this service...
  87.     Handler(s):
  88.       "DEDICATED" established:8038 refused:0 state:ready
  89.          LOCAL SERVER
  90. Service "cdb1XDB" has 1 instance(s).
  91.   Instance "cdb1", status READY, has 1 handler(s) for this service...
  92.     Handler(s):
  93.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  94.          DISPATCHER <machine: station26.example.com, pid: 10924>
  95.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=46517))
  96. Service "orcl" has 1 instance(s).
  97.   Instance "orcl", status READY, has 4 handler(s) for this service...
  98.     Handler(s):
  99.       "DEDICATED" established:19902 refused:0 state:ready
  100.          LOCAL SERVER
  101.       "D001" established:0 refused:0 current:0 max:1022 state:ready
  102.          DISPATCHER <machine: station26.example.com, pid: 10545>
  103.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=52095))
  104.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  105.          DISPATCHER <machine: station26.example.com, pid: 13328>
  106.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=27200))
  107.       "D002" established:0 refused:0 current:0 max:1022 state:ready
  108.          DISPATCHER <machine: station26.example.com, pid: 10547>
  109.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=49550))
  110. Service "orcl2" has 1 instance(s).
  111.   Instance "orcl2", status READY, has 1 handler(s) for this service...
  112.     Handler(s):
  113.       "DEDICATED" established:20963 refused:0 state:ready
  114.          LOCAL SERVER
  115. Service "orcl2XDB" has 1 instance(s).
  116.   Instance "orcl2", status READY, has 1 handler(s) for this service...
  117.     Handler(s):
  118.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  119.          DISPATCHER <machine: station26.example.com, pid: 13973>
  120.          (ADDRESS=(PROTOCOL=tcp)(HOST=station26.example.com)(PORT=19539))
  121. Service "orclXDB" has 1 instance(s).
  122.   Instance "orcl", status READY, has 0 handler(s) for this service...
  123. Service "pdb1_1" has 1 instance(s).
  124.   Instance "cdb1", status READY, has 1 handler(s) for this service...
  125.     Handler(s):
  126.       "DEDICATED" established:8038 refused:0 state:ready
  127.          LOCAL SERVER
  128. The command completed successfully
  129. [oracle@station26 ~]$
复制代码

Screenshot.png

  1. [oracle@station26 ~]$ netstat -lntp | grep :8888
  2. (Not all processes could be identified, non-owned process info
  3. will not be shown, you would have to be root to see it all.)
  4. [oracle@station26 ~]$ sqlplus /nolog

  5. SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 24 21:27:55 2017

  6. Copyright (c) 1982, 2014, Oracle.  All rights reserved.

  7. SQL> conn / as sysdba
  8. Connected.
  9. SQL> exec DBMS_XDB.SETHTTPPORT(8888);

  10. PL/SQL procedure successfully completed.

  11. SQL> exit
  12. Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
  13. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
  14. [oracle@station26 ~]$ netstat -lntp | grep :8888
  15. (Not all processes could be identified, non-owned process info
  16. will not be shown, you would have to be root to see it all.)
  17. tcp        0      0 :::8888                     :::*                        LISTEN      13005/tnslsnr      
复制代码
  1. BEGIN
  2. DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('mypassword');
  3. END;

  4. SELECT DBMS_XDB.GETHTTPPORT() FROM DUAL;
复制代码

客户端要做:
Screenshot.png

Screenshot.png

Screenshot-1.png

  1. DECLARE
  2. versionnum VARCHAR2(30);
  3. BEGIN
  4. versionnum := DBMS_SCHEDULER.GET_AGENT_VERSION('192.168.0.199');
  5. DBMS_OUTPUT.PUT_LINE(versionnum);
  6. END;

  7. DECLARE
  8. versionnum VARCHAR2(30);
  9. BEGIN
  10. versionnum := DBMS_SCHEDULER.GET_AGENT_VERSION('192.168.0.39');
  11. DBMS_OUTPUT.PUT_LINE(versionnum);
  12. END;
复制代码
  1. grant all on station199 to hr;

  2. grant all on station39 to hr;
复制代码
Windows版本(有bug,一直running)
  1. BEGIN
  2. sys.dbms_scheduler.create_job(
  3. job_name => '"HR"."JOB11"',
  4. job_type => 'EXECUTABLE',
  5. job_action => 'c:\Users\oracle\c1.bat',
  6. start_date => systimestamp at time zone 'Asia/Shanghai',
  7. job_class => '"DEFAULT_JOB_CLASS"',
  8. comments => 'job11',
  9. auto_drop => FALSE,
  10. enabled => FALSE);
  11. DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB11"', attribute => 'destination', value => 'station199' );
  12. DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB11"', attribute => 'credential_name', value => '"SYS"."CRED1"' );
  13. sys.dbms_scheduler.enable( '"HR"."JOB11"' );
  14. END;
复制代码
Linux版本没问题:
  1.         
  2.                         
  3. BEGIN
  4. sys.dbms_scheduler.create_job(
  5. job_name => '"HR"."JOB111"',
  6. job_type => 'EXECUTABLE',
  7. job_action => '/home/oracle/c1.sh',
  8. repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
  9. start_date => systimestamp at time zone 'Asia/Shanghai',
  10. end_date => to_timestamp_tz('2017-10-26 19:55:00 Asia/Shanghai', 'YYYY-MM-DD HH24:MI:SS TZR'),
  11. job_class => '"DEFAULT_JOB_CLASS"',
  12. comments => 'job111',
  13. auto_drop => FALSE,
  14. enabled => FALSE);
  15. DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB111"', attribute => 'destination', value => 'station39' );
  16. DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB111"', attribute => 'credential_name', value => '"SYS"."CRED1"' );
  17. sys.dbms_scheduler.enable( '"HR"."JOB111"' );
  18. END;
复制代码

远程外部作业(文件的时间属性是格林威志时间):

  1. --SYS:
  2. 创建远程credential
  3. begin
  4.   dbms_scheduler.create_credential(
  5.         credential_name => 'credential2',
  6.         username => 'oracle',
  7.         password => 'oracle');
  8. end;

  9. grant execute  on credential2 to hr;
  10. select  * from dba_scheduler_external_dests;
  11. --查到STATION41
  12. begin
  13.    dbms_scheduler.create_file_watcher(
  14.    file_watcher_name => 'filewatcher2',
  15.    directory_path => '/home/oracle/yourfile',
  16.    file_name =>  'botang*.txt',
  17.    credential_name => 'credential2',
  18.    destination => 'STATION41');
  19. end;

  20. begin
  21. DBMS_SCHEDULER.enable('filewatcher2');
  22. end;

  23. --em界面做也可以
  24. By default, file watchers only check for the arrival of files every 10 minutes, but this default interval can be changed by issuing the following statement.

  25. BEGIN
  26.   DBMS_SCHEDULER.set_attribute(
  27.     'file_watcher_schedule',
  28.     'repeat_interval',
  29.     'freq=minutely; interval=1');
  30. END;
  31. /
  32.    
  33. select  * from dba_scheduler_file_watchers;
  34. grant execute on filewatcher2 to hr;

  35. --HR:   
  36. create table hr.tfilewatcher2( a  varchar2(200)  ) ;  

  37. create or replace procedure hr.procfilewatcher2( p_1  SYS.SCHEDULER_FILEWATCHER_RESULT)
  38. is
  39. begin
  40.   insert into  hr.tfilewatcher2 values ( to_char( p_1.file_timestamp,'YYYY-MM-DD:HH24:MI:SS') ||'      '
  41.                                                       ||p_1.directory_path||'        '
  42.                                                       ||p_1.actual_file_name||'       '
  43.                                                       ||p_1.file_size  ) ;
  44.   commit;
  45. end;
  46.   
  47. begin
  48.     dbms_scheduler.create_program(
  49.      program_name => 'HR.program12',
  50.      program_type => 'STORED_PROCEDURE',
  51.      program_action => 'HR.procfilewatcher2',
  52.      number_of_arguments => 1,
  53.      enabled => false);
  54. end;

  55. begin
  56.    dbms_scheduler.define_metadata_argument(
  57.    program_name => 'HR.program12',
  58.    metadata_attribute => 'event_message',argument_position => 1 ) ;
  59. end;

  60. begin
  61.   dbms_scheduler.enable('HR.program12');
  62. end;

  63. BEGIN
  64.   DBMS_SCHEDULER.CREATE_JOB(
  65.    jOB_NAME=> 'hr.job12',
  66.    PROGRAM_NAME=> 'hr.program12',
  67.    EVENT_CONDITION => 'tab.user_data.file_size > 10',
  68.    QUEUE_SPEC=> 'filewatcher2',
  69.    AUTO_DROP=> FALSE,
  70.    ENABLED=> true);
  71. END;

  72. begin
  73.    dbms_scheduler.set_attribute('hr.job12','parallel_instances',true);
  74. end;

  75. select  * from  hr.tfilewatcher2;
复制代码
远程数据库作业(12c有bug):
  1. select * from dba_scheduler_dests;

  2. select  * from dba_scheduler_external_dests;

  3. select  * from dba_scheduler_db_dests;

  4. begin
  5.    dbms_scheduler.drop_agent_destination('STATION199');
  6. end;   

  7. begin
  8.    dbms_scheduler.create_credential('cred2','hr','oracle_4U');
  9. end;

  10. grant execute on cred2 to hr;

  11. select  * from dba_scheduler_credentials;

  12. begin
  13.    dbms_scheduler.create_database_destination(
  14.    destination_name => 'remotedb39',
  15.    agent => 'station39',tns_name => 'pdb1_1');
  16. end;

  17. grant all on remotedb39 to hr;


  18. select  * from dba_Tab_privs t where t.grantee='HR';

  19. BEGIN
  20. sys.dbms_scheduler.create_job(
  21. job_name => 'hr.job131',
  22. job_type => 'PLSQL_BLOCK',
  23. job_action => 'begin
  24.    update employees set salary=salary+1  where employee_id=100;
  25.    commit;
  26. end;',
  27. start_date => systimestamp at time zone 'Asia/Shanghai',
  28. job_class => '"DEFAULT_JOB_CLASS"',
  29. comments => 'JOB131',
  30. auto_drop => FALSE,
  31. credential_name =>'"SYS"."CRED2"' ,destination_name =>'sys.remotedb39' ,
  32. enabled => true);
  33. END;
复制代码

作业组:
  1. select  * from dba_scheduler_groups;

  2. select  * from dba_scheduler_group_members;

  3. ----

  4. BEGIN
  5.   DBMS_SCHEDULER.create_group(
  6.     group_name    => 'hr.group1',
  7.     group_type    => 'EXTERNAL_DEST',
  8.     member => 'sys.cred1@LOCAL,sys.cred1@sys.station39'
  9.     );
  10. END;

  11. ---
  12. select  * from dba_scheduler_groups g where g.group_name='GROUP1';
  13. select  * from dba_scheduler_group_members gm where gm.group_name='GROUP1';


  14. ----

  15. BEGIN
  16.    DBMS_SCHEDULER.CREATE_JOB (
  17.        job_name            =>  'hr.JOB14',
  18.        job_type            =>  'executable',
  19.        job_action          =>  '/home/oracle/job2.sh',
  20.        start_date          =>  SYSTIMESTAMP,
  21.        repeat_interval     =>  'freq=minutely; bysecond=0',
  22.        end_date            =>  SYSTIMESTAMP + 1/24,
  23.        credential_name     =>  'sys.cred1',
  24.        destination_name    =>  'group1',
  25.        enabled             =>  TRUE);
  26. END;
复制代码
Screenshot.png

Screenshot-1.png
回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-3 04:59 , Processed in 0.044471 second(s), 27 queries .

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