天天看点

Can we deploy the RM on the standby DB?

Recently, One customer asked me, can we deploy the ‘resource_manager’ on the standby DB?

As per my test, I get the conclusion:"’Yes, we can!’.

The following are my test steps, they include four parts,

1. Prepare part  --- Create the users, resource plan, consumer group and so on.

2. Check part    --- Verify the validity of the objects, which created on prepare part. 

3. Test part(On Primary DB ) ---Test the RM effect on Primary DB.

4. Test part(On Standby DB ) ---Test the RM effect on Standby DB.

Now, start our test case.

Prepare part 

************************************************************

1. Create users:  

create user RUSER identified by ruser;  

grant dba to RUSER; 

create user liang identified by liang;  

grant dba to liang; 

2: Create a plan:  

begin  

dbms_resource_manager.create_pending_area();  

end;  

dbms_resource_manager.create_plan( plan => 'TEST_CPU_RES', comment => 'Resource plan/method for CPU resources');  

3. Create Consumer Groups:  

begin   

dbms_resource_manager.create_consumer_group ( consumer_group => 'NORMAL_Group' , comment =>'ALL normal Users'); dbms_resource_manager.create_consumer_group ( consumer_group => 'STATS_Group', comment => 'Statistic jobs');   

end;   

4. Create plan directives:  

dbms_resource_manager.create_plan_directive ( plan => 'TEST_CPU_RES', group_or_subplan =>'NORMAL_Group',comment => 'Limit CPU resource', cpu_p1 => 80 );   

dbms_resource_manager.create_plan_directive ( plan => 'TEST_CPU_RES', group_or_subplan => 'STATS_Group',comment => 'Limit CPU resource', cpu_p1 => 20);   

dbms_resource_manager.create_plan_directive ( plan => 'TEST_CPU_RES', group_or_subplan =>'OTHER_GROUPS',comment => 'Limit CPU resource', cpu_p1 => 0 );   

5. Validate and submit the plan:  

dbms_resource_manager.validate_pending_area();  

dbms_resource_manager.submit_pending_area();  

6. Group switching:  

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name=>'RUSER',consumer_group=>'STATS_Group',grant_option=>FALSE); 

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name=>'LIANG',consumer_group=>'NORMAL_Group',grant_option=>FALSE); 

7. Assign the user 'RUSER' of the database a default initial consumer group at connection time:  

dbms_resource_manager.set_initial_consumer_group(user => 'RUSER',consumer_group =>'STATS_Group');  

dbms_resource_manager.set_initial_consumer_group(user => 'LIANG',consumer_group =>'NORMAL_Group');  

Check part 

1. Check the relationship of the user and the consumer_group 

SQL> SELECT * FROM DBA_RSRC_CONSUMER_GROUP_PRIVS where grantee like 'RUSER%'; 

GRANTEE                        GRANTED_GROUP                  GRA INI  

------------------------------ ------------------------------ --- ---  

RUSER                            STATS_GROUP                    NO  YES 

SQL> SELECT * FROM DBA_RSRC_CONSUMER_GROUP_PRIVS where grantee like 'LIANG%'; 

LIANG                          NORMAL_GROUP                   NO  YES 

2. Check the resource plan, what consumer groups are include in this plan: 

SQL> SELECT group_or_subplan, mgmt_p1, mgmt_p2, mgmt_p3, mgmt_p4, max_utilization_limit  

FROM dba_rsrc_plan_directives WHERE plan = upper('TEST_CPU_RES');   

GROUP_OR_SUBPLAN                  MGMT_P1    MGMT_P2    MGMT_P3    MGMT_P4 MAX_UTILIZATION_LIMIT  

------------------------------ ---------- ---------- ---------- ---------- ---------------------  

NORMAL_GROUP                           80          0          0          0  

STATS_GROUP                            20          0          0          0  

OTHER_GROUPS                            0          0          0          0 

3. Query the current active plan  

SQL> SELECT NAME, IS_TOP_PLAN FROM V$RSRC_PLAN; 

NAME                             IS_TO  

-------------------------------- -----  

INTERNAL_PLAN                    TRUE                               <<<<<Is is not expect plan, which is the default plan 

SQL> set line 1000  

SQL> select group_or_subplan, mgmt_p1, mgmt_p2, mgmt_p3, mgmt_p4, mgmt_p5, mgmt_p6, mgmt_p7, mgmt_p8, max_utilization_limit from dba_rsrc_plan_directives  

where plan = (select name from v$rsrc_plan where is_top_plan = 'TRUE');  2 

GROUP_OR_SUBPLAN                  MGMT_P1    MGMT_P2    MGMT_P3    MGMT_P4    MGMT_P5    MGMT_P6    MGMT_P7    MGMT_P8 MAX_UTILIZATION_LIMIT  

------------------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------------  

OTHER_GROUPS                            0          0          0          0          0          0          0          0   <<<<<Only OTHER_GROUPS in the default INTERNAL_PLAN plan 

4.  Take effect for the setting of your resource_manager_plan. 

SQL> alter system set resource_manager_plan='plan_test' scope=both; 

SQL> show parameter resource_manager_plan 

NAME                                 TYPE        VALUE  

------------------------------------ ----------- ------------------------------  

resource_manager_plan                string      TEST_CPU_RES                                     <<<<<This plan was created by ourselves 

---The current active plan  

TEST_CPU_RES                     TRUE       

5. check current setting of plan 

where plan = (select name from v$rsrc_plan where is_top_plan = 'TRUE');    

NORMAL_GROUP                           80          0          0          0          0          0          0          0  

STATS_GROUP                            20          0          0          0          0          0          0          0  

OTHER_GROUPS                            0          0          0          0          0          0          0          0 

Test part----On Primary DB

1.  Executes this script by user liang/RUSER to produce the workload 

DECLARE  

n NUMBER;  

BEGIN  

WHILE (TRUE)  

LOOP  

n:= dbms_random.random();  

END LOOP;  

END; 

2. The output of the command top  

-----First fetch -----  

top - 04:58:29 up 22 days, 23:24,  6 users,  load average: 1.49, 1.81, 1.19  

Tasks: 323 total,   2 running, 321 sleeping,   0 stopped,   0 zombie  

Cpu(s): 99.0%us,  1.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st  

Mem:   3361028k total,  3178564k used,   182464k free,   186904k buffers  

Swap:  2433836k total,   916564k used,  1517272k free,  1136416k cached 

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND  

15308 oracle    20   0  945m  33m  29m R 79.1  1.0   9:22.40 oracle       <<<<<<<<<<<<<<<< user liang  

15294 oracle    20   0  946m  38m  34m S 15.9  1.2   5:35.10 oracle       <<<<<<<<<<<<<<<< user RUSER  

-----sencond fetch-----  

top - 05:02:21 up 22 days, 23:28,  6 users,  load average: 1.09, 1.40, 1.15  

Tasks: 325 total,   2 running, 323 sleeping,   0 stopped,   0 zombie  

Mem:   3361028k total,  3188012k used,   173016k free,   187256k buffers  

Swap:  2433836k total,   916560k used,  1517276k free,  1136912k cached 

15308 oracle    20   0  945m  33m  29m R 75.1  1.0  12:16.24 oracle      <<<<<<<<<<<<<<<< user liang  

15294 oracle    20   0  946m  38m  34m S 18.9  1.2   6:19.51 oracle      <<<<<<<<<<<<<<<< user RUSER 

3. Query the current session 

SQL> select s.username,s.STATUS,p.SPID  

     from v$session s, v$process p  

     where s.PADDR=p.ADDR and s.username='LIANG' OR s.username='RUSER' order by s.username; 

RUSER                            ACTIVE   15294  

LIANG                          ACTIVE   15308 

4. Only executes this script by user liang, the output idicates, if there isn't other process, it can obtain all the CPU resource. 

top - 04:45:27 up 22 days, 23:11,  6 users,  load average: 1.20, 0.51, 0.19  

Tasks: 322 total,   2 running, 320 sleeping,   0 stopped,   0 zombie  

Mem:   3361028k total,  3171100k used,   189928k free,   185980k buffers  

Swap:  2433836k total,   916580k used,  1517256k free,  1134700k cached 

15308 oracle    20   0  945m  33m  29m R 94.6  1.0   2:44.50 oracle           <<<<<<<<<<<<<<<< user liang    

5. Only executes this script by user RUSER, which can obtain all the resource.  

top - 05:03:34 up 22 days, 23:29,  6 users,  load average: 1.02, 1.31, 1.14  

Tasks: 324 total,   2 running, 322 sleeping,   0 stopped,   0 zombie  

Mem:   3361028k total,  3185392k used,   175636k free,   187332k buffers  

Swap:  2433836k total,   916560k used,  1517276k free,  1137264k cached 

15294 oracle    20   0  946m  39m  35m R 94.3  1.2   6:43.45 oracle           <<<<<<<<<<<<<<<< user RUSER  

6. Executes this script by both liang and RUSER, the CPU resource was allotted as the resource manager plan.(80/20)  

top - 05:04:25 up 22 days, 23:30,  6 users,  load average: 1.09, 1.27, 1.13  

Cpu(s): 98.7%us,  1.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st  

Mem:   3361028k total,  3185160k used,   175868k free,   187384k buffers  

Swap:  2433836k total,   916560k used,  1517276k free,  1137368k cached 

15308 oracle    20   0  945m  33m  30m R 75.1  1.0  13:04.20 oracle  

15294 oracle    20   0  946m  39m  35m S 18.9  1.2   7:27.63 oracle 

Test part----On Standby DB

************************************************************ 

1. Confirm if the standby DB is sync with the primary DB  

select max(SEQUENCE#),applied from  v$archived_log group by applied; 

2. Query the parameter  

resource_manager_plan                string       

INTERNAL_PLAN                    TRUE                              <<<<<the current plan is the default. 

4. Manually set the parameter to the expect plan.  

SQL> alter system set resource_manager_plan='TEST_CPU_RES' scope=both;  

resource_manager_plan                string      TEST_CPU_RES 

TEST_CPU_RES                     TRUE 

5. Executes this script by both liang and RUSER, the CPU resource was allotted as the resource manager plan.(80/20)  

top - 05:28:04 up 7 days, 17:34,  4 users,  load average: 0.79, 0.27, 0.09  

Tasks: 211 total,   2 running, 209 sleeping,   0 stopped,   0 zombie  

Cpu(s): 99.7%us,  0.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st  

Mem:   1035164k total,   695316k used,   339848k free,    26168k buffers  

Swap:  2433836k total,   151692k used,  2282144k free,   349500k cached 

22690 oracle    20   0  732m  34m  31m R 78.6  3.4   1:07.45 oracle  

22719 oracle    20   0  732m  30m  27m S 19.9  3.0   0:26.37 oracle 

6. Query the current session  

from v$session s, v$process p  

where s.PADDR=p.ADDR and s.username='LIANG' OR s.username='RUSER' order by s.username;  2    3 

USERNAME                       STATUS   SPID  

------------------------------ -------- ------------------------  

RUSER                            ACTIVE   22719  

LIANG                          ACTIVE   22690 

7. Only executes this script by user RUSER, which can obtain all the resource.  

top - 05:29:59 up 7 days, 17:36,  4 users,  load average: 1.04, 0.51, 0.20  

Mem:   1035164k total,   698036k used,   337128k free,    26324k buffers  

Swap:  2433836k total,   151692k used,  2282144k free,   351000k cached 

22719 oracle    20   0  732m  30m  27m R 98.9  3.0   0:53.12 oracle 

8. Executes this script by both liang and RUSER, the CPU resource was allotted as the resource manager plan.(80/20)  

top - 05:30:47 up 7 days, 17:37,  4 users,  load average: 1.02, 0.58, 0.23  

Mem:   1035164k total,   698160k used,   337004k free,    26404k buffers  

Swap:  2433836k total,   151692k used,  2282144k free,   351048k cached 

22690 oracle    20   0  732m  34m  31m R 76.0  3.4   2:51.84 oracle  

22719 oracle    20   0  732m  30m  27m S 23.2  3.0   1:22.57 oracle 

9. Only executes this script by user RUSER, which can obtain all the resource.  

top - 05:31:05 up 7 days, 17:37,  4 users,  load average: 1.01, 0.61, 0.25  

Mem:   1035164k total,   698400k used,   336764k free,    26428k buffers  

Swap:  2433836k total,   151692k used,  2282144k free,   351076k cached 

22690 oracle    20   0  732m  34m  31m R 98.8  3.4   3:07.22 oracle  

22565 oracle    -2   0  730m  15m  13m S  0.7  1.6   0:05.59 oracle 

<a href="http://down.51cto.com/data/2362084" target="_blank">附件:http://down.51cto.com/data/2362084</a>

本文转自 hsbxxl 51CTO博客,原文链接:http://blog.51cto.com/hsbxxl/1106787,如需转载请自行联系原作者