Bo's Oracle Station

查看: 2718|回复: 0

远程数据库作业

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-12-13 16:43:15 | 显示全部楼层 |阅读模式
orcl:
  1. select  * from dba_users order by username;

  2. create user hr identified by oracle_4U ;

  3. grant connect,resource to hr;

  4. alter user hr quota unlimited on users;

  5. grant create job to hr;

  6. select  * from dba_sys_privs  where grantee='HR';

  7. select  * from dba_role_privs where grantee='HR';
复制代码
准备what部分:
HR用户操作
  1.         BEGIN
  2. DBMS_SCHEDULER.CREATE_PROGRAM(
  3. program_name=>'"HR"."PROGRAM13"',
  4. program_action=>'begin
  5.   update spoto.t062ad21_a set a=a+1;
  6.   commit;
  7. end;',
  8. program_type=>'PLSQL_BLOCK',
  9. number_of_arguments=>0,
  10. comments=>'',
  11. enabled=>TRUE);
  12. END;
复制代码

when部分:
HR用户操作
  1. BEGIN
  2. sys.dbms_scheduler.create_schedule(
  3. repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
  4. start_date => systimestamp at time zone 'Asia/Shanghai',
  5. schedule_name => '"HR"."SCHEDULE13"');
  6. END;
复制代码

where部分:
SYS来操作
prerequitise: 在目的地机器上装好scheduler agent(已经做好),如果有防火墙要把1025打来接受连接。

改参数前:
  1. [oracle@classroom ~]$ lsnrctl services

  2. LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 13-12月-2020 20:15:56

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

  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=classroom.example.com)(PORT=1521)))
  5. Services Summary...
  6. Service "+ASM" has 1 instance(s).
  7.   Instance "+ASM", status READY, has 1 handler(s) for this service...
  8.     Handler(s):
  9.       "DEDICATED" established:77 refused:0 state:ready
  10.          LOCAL SERVER
  11. Service "em12rep" has 1 instance(s).
  12.   Instance "em12rep", status READY, has 1 handler(s) for this service...
  13.     Handler(s):
  14.       "DEDICATED" established:4404 refused:0 state:ready
  15.          LOCAL SERVER
  16. Service "em12repXDB" has 1 instance(s).
  17.   Instance "em12rep", status READY, has 1 handler(s) for this service...
  18.     Handler(s):
  19.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  20.          DISPATCHER <machine: classroom.example.com, pid: 9504>
  21.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=14089))
  22. Service "orcl" has 1 instance(s).
  23.   Instance "orcl", status READY, has 1 handler(s) for this service...
  24.     Handler(s):
  25.       "DEDICATED" established:1112 refused:0 state:ready
  26.          LOCAL SERVER
  27. Service "orcl2" has 1 instance(s).
  28.   Instance "orcl2", status READY, has 1 handler(s) for this service...
  29.     Handler(s):
  30.       "DEDICATED" established:1391 refused:0 state:ready
  31.          LOCAL SERVER
  32. Service "orclXDB" has 1 instance(s).
  33.   Instance "orcl", status READY, has 1 handler(s) for this service...
  34.     Handler(s):
  35.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  36.          DISPATCHER <machine: classroom.example.com, pid: 28683>
  37.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=23035))
  38. Service "rcat.example.com" has 1 instance(s).
  39.   Instance "rcat", status READY, has 1 handler(s) for this service...
  40.     Handler(s):
  41.       "DEDICATED" established:1170 refused:0 state:ready
  42.          LOCAL SERVER
  43. Service "rcatXDB.example.com" has 1 instance(s).
  44.   Instance "rcat", status READY, has 1 handler(s) for this service...
  45.     Handler(s):
  46.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  47.          DISPATCHER <machine: classroom.example.com, pid: 10384>
  48.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=31917))
  49. The command completed successfully
  50. [oracle@classroom ~]$
复制代码
  1. alter system set dispatchers='(PROTOCOL=TCP) (dispatchers=3)';
复制代码
  1. [oracle@classroom ~]$ lsnrctl services

  2. LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 13-12月-2020 20:19:43

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

  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=classroom.example.com)(PORT=1521)))
  5. Services Summary...
  6. Service "+ASM" has 1 instance(s).
  7.   Instance "+ASM", status READY, has 1 handler(s) for this service...
  8.     Handler(s):
  9.       "DEDICATED" established:78 refused:0 state:ready
  10.          LOCAL SERVER
  11. Service "em12rep" has 1 instance(s).
  12.   Instance "em12rep", status READY, has 1 handler(s) for this service...
  13.     Handler(s):
  14.       "DEDICATED" established:4452 refused:0 state:ready
  15.          LOCAL SERVER
  16. Service "em12repXDB" has 1 instance(s).
  17.   Instance "em12rep", status READY, has 1 handler(s) for this service...
  18.     Handler(s):
  19.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  20.          DISPATCHER <machine: classroom.example.com, pid: 9504>
  21.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=14089))
  22. Service "orcl" has 1 instance(s).
  23.   Instance "orcl", status READY, has 4 handler(s) for this service...
  24.     Handler(s):
  25.       "DEDICATED" established:1126 refused:0 state:ready
  26.          LOCAL SERVER
  27.       "D001" established:0 refused:0 current:0 max:1022 state:ready
  28.          DISPATCHER <machine: classroom.example.com, pid: 24983>
  29.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=23793))
  30.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  31.          DISPATCHER <machine: classroom.example.com, pid: 28683>
  32.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=23035))
  33.       "D002" established:1 refused:0 current:1 max:1022 state:ready
  34.          DISPATCHER <machine: classroom.example.com, pid: 24985>
  35.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=21427))
  36. Service "orcl2" has 1 instance(s).
  37.   Instance "orcl2", status READY, has 1 handler(s) for this service...
  38.     Handler(s):
  39.       "DEDICATED" established:1406 refused:0 state:ready
  40.          LOCAL SERVER
  41. Service "orclXDB" has 1 instance(s).
  42.   Instance "orcl", status READY, has 0 handler(s) for this service...
  43. Service "rcat.example.com" has 1 instance(s).
  44.   Instance "rcat", status READY, has 1 handler(s) for this service...
  45.     Handler(s):
  46.       "DEDICATED" established:1185 refused:0 state:ready
  47.          LOCAL SERVER
  48. Service "rcatXDB.example.com" has 1 instance(s).
  49.   Instance "rcat", status READY, has 1 handler(s) for this service...
  50.     Handler(s):
  51.       "D000" established:0 refused:0 current:0 max:1022 state:ready
  52.          DISPATCHER <machine: classroom.example.com, pid: 10384>
  53.          (ADDRESS=(PROTOCOL=tcp)(HOST=classroom.example.com)(PORT=31917))
  54. The command completed successfully
  55. [oracle@classroom ~]$
复制代码
  1. alter system set shared_servers=3;
复制代码
  1. SQL> conn / as sysdba
  2. Connected.
  3. SQL> @?/rdbms/admin/prvtrsch.plb

  4. PL/SQL procedure successfully completed.


  5. PL/SQL procedure successfully completed.


  6. PL/SQL procedure successfully completed.


  7. no rows selected


  8. Package created.


  9. Package body created.

  10. No errors.

  11. PL/SQL procedure successfully completed.


  12. PL/SQL procedure successfully completed.


  13. User altered.


  14. User altered.


  15. 1 row updated.


  16. Commit complete.


  17. Grant succeeded.


  18. Procedure created.

  19. No errors.

  20. Audit policy altered.


  21. Function created.


  22. Procedure created.


  23. Procedure created.


  24. Procedure created.


  25. Procedure created.


  26. Procedure created.


  27. Procedure created.

  28. No errors.

  29. Procedure created.

  30. No errors.

  31. Procedure created.

  32. No errors.

  33. PL/SQL procedure successfully completed.


  34. Commit complete.


  35. PL/SQL procedure successfully completed.


  36. Commit complete.

  37. SQL>
复制代码
走了上面的脚本,多一个用户:
REMOTE_SCHEDULER_AGENT    98        EXPIRED & LOCKED    13-DEC-20    13-DEC-20    USERS    TEMP    13-DEC-20    DEFAULT    DEFAULT_CONSUMER_GROUP            N    PASSWORD    N    NO        N

  1. BEGIN
  2. DBMS_XDB.SETHTTPPORT(8888);
  3. END;
  4. /
复制代码
  1. BEGIN
  2. DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('mypassword');
  3. END;
  4. /
复制代码
  1. begin
  2. dbms_scheduler.create_credential( 'credential1','spoto','oracle_4U'  );
  3. end;
  4. /
复制代码
---------------------------------------------------------------------------------------------------------
where部分的目的地机器操作:

  1. [oracle@classroom ~]$ cd /u01/app/oracle/product/12.1.0/client_1/bin/
  2. [oracle@classroom bin]$ ./schagent -h
  3. Oracle Scheduler Agent V 12.1.0.1.1 Usage

  4. -registerdatabase databaseHost databasePort
  5. Register with a database.

  6. -unregisterdatabase databaseHost databasePort
  7. Unregister from a database.

  8. -start
  9. Start the Scheduler agent

  10. -status
  11. Get the current status of this agent

  12. -stop
  13. Stop the Scheduler agent gracefully

  14. -abort
  15. Stop the Scheduler agent forcefully

  16. [oracle@classroom bin]$ ./schagent -stop

  17. Agent not running or agent.pid file removed

  18. [oracle@classroom bin]$ ./schagent -registerdatabase classroom.example.com 8888
  19. Agent Registration Password ? ***********
  20. *
  21. Oracle Scheduler Agent Registration for 12.1 Agent
  22. Agent Registration Successful!
  23. [oracle@classroom bin]$ ./schagent -start
  24. Scheduler agent started
复制代码
在orcl验证:
sys运行:
  1. set serveroutput on;


  2. DECLARE
  3.   versionnum VARCHAR2(30);
  4. BEGIN
  5.   versionnum := DBMS_SCHEDULER.GET_AGENT_VERSION('classroom.example.com');
  6. DBMS_OUTPUT.PUT_LINE(versionnum);
  7. END;
  8. /
复制代码
anonymous block completed
12.1.0.1.1

  1. select  * from dba_scheduler_external_dests;
复制代码
SYS    CLASSROOM    classroom.example.com    1025    172.25.250.254    TRUE    Registered on 13-DEC-20 08.49.31.646611 PM PRC

--------------------------------------------------------------------------
在orcl机器上准备tnsnames.ora,使其能够tnsping通orcl2

/u01/app/oracle/product/12.1.0/dbhome_2/network/admin

  1. ORCL2 =
  2.   (DESCRIPTION =
  3.     (ADDRESS = (PROTOCOL = TCP)(HOST = classroom.example.com)(PORT = 1521))
  4.     (CONNECT_DATA =
  5.       (SERVER = DEDICATED)
  6.       (SERVICE_NAME = orcl2)
  7.     )
  8.   )
复制代码
  1. begin
  2.    dbms_scheduler.create_database_destination(
  3.    destination_name => 'orcl2',
  4.    agent => 'CLASSROOM',tns_name => 'orcl2');
  5. end;
  6. /
复制代码

把where部分授权给hr:
  1. grant execute on credential1 to hr;

  2. grant all on orcl2 to hr;

  3. grant all on classroom to hr;
复制代码
  1. select  * from dba_tab_privs where grantee='HR';
复制代码
HR    SYS    CREDENTIAL1    SYS    EXECUTE    NO    NO    NO    UNKNOWN
HR    SYS    CLASSROOM    SYS    ALTER    NO    NO    NO    DESTINATION
HR    SYS    ORCL2    SYS    ALTER    NO    NO    NO    DESTINATION


---------------------------------------------------------------------------------------------------------------------
从界面上取下来以后并不能运行(书上也是不对的):
  1.        
  2.                        
  3. BEGIN
  4. sys.dbms_scheduler.create_job(
  5. job_name => '"HR"."JOB13"',
  6. program_name => '"HR"."PROGRAM13"',
  7. schedule_name => '"HR"."SCHEDULE13"',
  8. job_class => '"DEFAULT_JOB_CLASS"',
  9. auto_drop => FALSE,
  10. enabled => FALSE);
  11. DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB13"', attribute => 'destination', value => 'sys.orcl2' );
  12. DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB13"', attribute => 'credential_name', value => '"SYS"."CREDENTIAL1"' );
  13. sys.dbms_scheduler.enable( '"HR"."JOB13"' );
  14. END;
复制代码

Perform the following tasks to create a remote job:
1. Set up the originating database for remote jobs.
2. Create the job by using DBMS_SCHEDULER.CREATE_JOB.
3 Create a credential by using
3.DBMS_SCHEDULER.CREATE_CREDENTIAL.
4. Set the job CREDENTIAL_NAME attribute by using
DBMS_SCHEDULER.SET_ATTRIBUTE.
5. Set the job DESTINATION attribute by using
DBMS_SCHEDULER.SET_ATTRIBUTE
DBMS_SCHEDULER.SET_ATTRIBUTE
.
6. Enable the job by using DBMS_SCHEDULER.ENABLE.
正确的方式:
  1. BEGIN
  2. sys.dbms_scheduler.create_job(
  3. job_name => '"HR"."JOB13"',
  4. program_name => '"HR"."PROGRAM13"',
  5. schedule_name => '"HR"."SCHEDULE13"',
  6. job_class => '"DEFAULT_JOB_CLASS"',
  7. auto_drop => FALSE,
  8. enabled => true,
  9. destination_name => 'sys.orcl2',
  10. credential_name=> 'SYS.CREDENTIAL1' );
  11. END;
  12. /
复制代码


回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-21 15:09 , Processed in 0.039093 second(s), 24 queries .

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