Managing Resouces

Database Resource Manager allows the database more control over how machine resources are allocated regardless of the load on the system and the number of users.  The Database Resource Manager involves the user of resource plans (how resource should be allocated), resource consumer groups (users, sessions), and resource plan directives (how resource is shared).  You can manage database and OS resource such as:
  •  CPU
  •  Number of active sessions
  •  Degree of Parallelism
  • Undo generation
  • Operation execution time
  • Idle Time


SYSTEM_PLAN --The Initial Plan


Resource consumer Group                                                  Allocation Methods
WHO? CPU_P1CPU_P2CPU_P3
SYS_GROUPSys & System users100%0%0%
OTHER_GROUPSessions who are not part of the active resource plan0%100%0%
LOW_GROUPLower priority than SYS_GROUP and OTHER_GROUP0%0%100%
There are 3 ways you can create a resource plan: 
1)  Enterprise Manager

2) CREATE_SIMPLE_PLAN:  Up to 8 consumer groups can be specified and the only plan directive is for CPU.  The plan uses the Emphasis CPU allocation policy and each consumer group uses the ROUND_ROBIN scheduling policy.

3) DBMS_RESOURCE_MANAGER package – to create a complex plan as follow:
            Create a Pending Area
            Create resource plans
            Create resource consumer groups
            Create Plan directives
            Validate the pending area
            Submit the pending area


ACTIVE_SESS_POOL_P1:  Number of active sessions that establishes the resource consumer gorup’s threashold and thus its active session pool (default is 1000000)
QUEUEING_P1:  How long (in seconds) an session will wait on the queue before aborting the current operation.

For example:  DSS group
ACTIVE_SESS_POOL_P1 = 5
QUEUEING_P1 = 600
All resource consumer group DSS has an active session pool value of 5 and all DSS sessions waiting on the queue for more than 10 minutes will abort with an error.

MAX_EST_EXEC_TIME – the operation’s estimate is more than MAX_EST_EXEC_TIME, then the operation will not start
MAX_IDDLE_TIME  =>600 :  Pmon process kills sessions that are idle for longer than 600 seconds
MAX_IDDLE_BLOCKER_TIME=>:  Pmon kills sessions that are idle for more than 300 seconds if they’re blocking oter sessions.

Resource Application Methods for Resource Plans

·         CPU_MTH:  how much CPU each consumer group or subplan gets.  There are 2 ways - EMPAHSIS (default) is for multilevel plans that use percentages to specify how CPU is distributed among consumer groups.  RATIO is for single-level plans to specify how CPU is distributed.

EMPHASIS CPU
RATIO CPU
Maxium % of CPU resouces a consumer gorup can use
Ratio of CPUto be allocated to a consumer group
You can allocate CPU levels from 1 to 8
You can only specify values for one level
Based on specified % and <=100
Must use Integer value
Default:  NULL
Default:  NULL

2 possible values: 

ROUND_ROBIN (default...Round-robin scheduler to ensure sessions are fairly executed) 
RUN_TO_COMPLETION:  Sessions with the largest active time ar scheduled ahead of other session.

·         PARALLEL_DEGREE_LIMIT_MTH:  Limits the maximum degree of parallelism of any operation for resource consumer groups only.  The ABSOLUTE method is the possible value, specifying how many processes may be assigned to an operation.
·         ACTIVE_SESS_POOL_MTH:  Limits number of active sessions
·         QUEUING_MTH:  Controls order in which queued inactive sessions will execute


To view Database Resouce Manager Information:

Select plan, num_plan_directives, status, mandatory dba_rsrc_plans;

PLAN                           NUM_PLAN_DIRECTIVES STATUS                         MAN
------------------------------ ------------------- ------------------------------ ---
IMPORTER_PLAN                                    2                                NO
SYSTEM_PLAN                                      3                                NO
EDOC_DAILY_PLAN                                  7                                NO
INTERNAL_PLAN                                    1                                YES
READER_PLAN                                      1                                NO
INTERNAL_QUIESCE                                 2                                YES


select plan, group_or_subplan, cpu_p1, cpu_p2, cpu_p3, parallel_degree_limit_p1, status
from dba_rsrc_plan_directives;

PLAN                           GROUP_OR_SUBPLAN                   CPU_P1     CPU_P2     CPU_P3 PARALLEL_DEGREE_LIMIT_P1 STATUS
------------------------------ ------------------------------ ---------- ---------- ---------- ------------------------ --------
EDOC_DAILY_PLAN                DBA_GROUP                               0          0         50                        1
EDOC_DAILY_PLAN                SUPP_GROUP                              0          0          0                        1
EDOC_DAILY_PLAN                DEV_GROUP                               0          0         50                        1
EDOC_DAILY_PLAN                SSEARCH_GROUP                           0         50          0                        3
EDOC_DAILY_PLAN                SYS_GROUP                             100          0          0
SYSTEM_PLAN                    SYS_GROUP                             100          0          0
SYSTEM_PLAN                    OTHER_GROUPS                            0        100          0
SYSTEM_PLAN                    LOW_GROUP                               0          0        100
INTERNAL_QUIESCE               SYS_GROUP                               0          0          0
INTERNAL_QUIESCE               OTHER_GROUPS                            0          0          0
INTERNAL_PLAN                  OTHER_GROUPS                            0          0          0
EDOC_DAILY_PLAN                OTHER_GROUPS                            0          0          0                        1
EDOC_DAILY_PLAN                APP_GROUP                               0         50          0                        3


SQL> select consumer_group, status, mandatory from dba_rsrc_consumer_groups;

CONSUMER_GROUP                 STATUS                         MAN
------------------------------ ------------------------------ ---
OTHER_GROUPS                                                  YES
DEFAULT_CONSUMER_GROUP                                        YES
SYS_GROUP                                                     YES
LOW_GROUP                                                     NO
AUTO_TASK_CONSUMER_GROUP                                      NO
APP_GROUP                                                     NO
DBA_GROUP                                                     NO
SUPP_GROUP                                                    NO
DEV_GROUP                                                     NO
SSEARCH_GROUP                                                 NO

New Optimizer in 11g


OPTIMIZER_USE_INVISIBLE_INDEXES

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_use_invisible_indexes      boolean     FALSE

Invisible indexes is a Oracle 11g new feature.  This allows you to create an index on a table without affecting any execution plan and so will not affect the performance of the application.  If you want to test a potential index, you need to set OPTIMIZER_USE_INVISIBLE_INDEXES to TRUE within a session before executing SQL statements.  If the index is useful, you can mark it visible.

OPTIMIZER_USE_PENDING_STATISTICS

SQL> show parameter optimizer_use_pending_statistics

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_use_pending_statistics     boolean     FALSE

It’s possible to gather optimizer statistics but not published immediately in Oracle 11g.  You can test these pending statistics by alter session command to set OPTIMIZER_USE_PENDING_STATISTICS=TRUE.

OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_use_sql_plan_baselines     boolean     FALSE

When this parameter is set to TRUE, Oracle will automatically capture a SQL plan baseline for every repeatable SQL statement on the system


OPTIMIZER_SQL_PLAN_BASELINES

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_use_sql_plan_baselines     boolean     TRUE

The optimizer will only use one of these known plans even if a different plan is found during SQL-comilation. This gurantees that any plan change is verified to have a better performance before using it.

Automatic Statistics Gathering Job

Oracle will automatically collect statistics for all database objects, which are missing statistics of have stale statistics by running an Oracle AutoTask during a predefined maintenance window (10pm to 2am weekdays and 6am to 2am at the weekends).  Statistics on a table are considered stale when more than STALE_PERCENT (default 10% total of inserts,updates, deletes rows) in a table.  Oracle monitors DML activities for all objects and records the changes in the SGA.  The monitoring information is periodically flushed to disk and is stored in the *_tab_modifications view.

It’s also possible to manually flush this data by calling the procedure DBMS_STATS.FLUSH_MONITORING_INFO. 

SQL> SELECT client_name, status
  2  FROM DBA_AUTOTASK_TASK
  3  WHERE client_name like 'auto optimizer %';

CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  ENABLED


select
num_rows, last_analyzed, tot_updates, table_owner, table_name, partition_name, subpartition_name,
inserts, updates, deletes, timestamp, truncated
, to_char(perc_updates, 'FM999,999,999,990.00') perc_updates
from (
        select a.*
        , nvl(decode(num_rows, 0, '-1', 100 * tot_updates / num_rows), -1) perc_updates
        from (
          select
                  (select num_rows from dba_tables where dba_tables.table_name = DBA_TAB_MODIFICATIONS.table_name
                  and DBA_TAB_MODIFICATIONS.table_owner = dba_tables.owner) num_rows
                , (select last_analyzed from dba_tables where dba_tables.table_name = DBA_TAB_MODIFICATIONS.table_name
                  and DBA_TAB_MODIFICATIONS.table_owner = dba_tables.owner) last_analyzed
                , (inserts + updates + deletes) tot_updates
                , DBA_TAB_MODIFICATIONS.*
                from sys.DBA_TAB_MODIFICATIONS
        ) a
) b
where perc_updates > 5 and
table_owner = 'TRAX_OWNER'
/


If you like to change the ‘STALE_PERCENT’ you can use

SQL> BEGIN
  2  DBMS_STATS.SET_GLOBAL_PREFS('STALE_PERCENT','5');
  3  END;
  4  /

PL/SQL procedure successfully completed.

To disable automatic statistics job gathering altogether:

BEGIN
DBMS_AUTO_TASK_ADMIN.DISABLE(
client_name => 'auto optimizer stats collection',
operation => NULL,
window_name => NULL);
END;

Password Enhancement

Passwords in Oracle Database 11g:
Are case-sensitive
Contain mutibyte characters without being enclosed in quotation marks
Use more secure hash algorithm
Use salt in the hash algorithm

By default:
            Default password profile is enabled
            Account is locked after 10 failed login attempts

To enable built-in Password Complexity checker


SQL> connect / as sysdba
Connected.
SQL> @?/rdbms/admin/utlpwdmg.sql

Function created.

Profile altered.
 
Function created.

SQL> show parameter sec_case_sensitive_

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sec_case_sensitive_logon             boolean     FALSE

SQL> alter system set sec_case_sensitive_logon=TRUE;

You can set limits on the number of time an unauthorized user attempts to login by setting the parameter

SQL> alter system set sec_max_failed_login_attempts=3 scope=spfile;

Gather ASM Information

SPOOL ASM_FIRST<instance#>.HTML
SET MARKUP HTML ON
SET ECHO ON

SET PAGESIZE 200

SELECT * FROM V$ASM_DISKGROUP;

SELECT * FROM  V$ASM_DISK ORDER BY GROUP_NUMBER,DISK_NUMBER; 

SELECT * FROM V$ASM_OPERATION;


SELECT * FROM V$VERSION;

SHOW PARAMETER ASM
SHOW PARAMETER CLUSTER
SHOW PARAMETER INSTANCE_TYPE
SHOW PARAMETER INSTANCE_NAME
SHOW PARAMETER SPFILE

SPOOL OFF

EXIT

SPOOL ASM_SECOND<instance#>.HTML 
SET MARKUP HTML ON
SET ECHO ON

SET PAGESIZE 200

SELECT * FROM  V$ASM_CLIENT;
SELECT * FROM  V$ASM_DISK_STAT ORDER BY GROUP_NUMBER,DISK_NUMBER;
SELECT * FROM  V$ASM_DISKGROUP_STAT ORDER BY GROUP_NUMBER;
SELECT * FROM  V$ASM_FILE ORDER BY GROUP_NUMBER,FILE_NUMBER;
SELECT * FROM  V$ASM_ALIAS ORDER BY GROUP_NUMBER,FILE_NUMBER;
SELECT * FROM  V$ASM_TEMPLATE ORDER BY GROUP_NUMBER,ENTRY_NUMBER;

SPOOL OFF

EXIT

SQL trace

set autotrace on statistics

set autotrace traceonly statistics




set lines 340

COLUMN plan_plus_exp format a300

COLUMN parent_id_plus_exp format 9990

COLUMN id_plus_exp format 9990

set autotrace traceonly explain




alter system set timed_statistics=true;

SQL> exec dbms_system.set_sql_trace_in_session(sid,serial#,TRUE)
SQL> exec dbms_system.set_sql_trace_in_session(sid,serial#,FALSE)

Manage and Monitor Standby Database

Stop data guard:

alter database recover managed standby database cancel;

Check DG:

select process, status, thread#, sequence#, block#, blocks from   v$managed_standby; 

check DB role

col db_unique_name format a10
select database_role, db_unique_name, open_mode, protection_mode, protection_level, switchover_status from v$database




DG standby proc
set time on
set lines 132
set pagesize 9999
col client_pid format a12
select pid, process, status, client_process, client_pid, thread#, sequence#, block#, blocks, delay_mins from v$managed_standby
;

Useful RAC commands

oifcfg getif
netstat -p udp
ocfconfig -h
crsctl check crs
crsctl lsmodules css

crsctl trace check css
ocrconfig -showbackup
srvctl config database -d TRXQAC -a -t
srvctl config asm -n serv708
srvctl config listener -n serv708
srvctl status database -d DGDBA -f -v

./cluvfy comp peer -n node1, node2 | more
./cluvf comp -list
./cluvf state -pre crsinst -n node1,node2 -verbose
cluvfy -stage -pre crsinst -n serv171

export SRVM_TRACE=TRUE
truss -aefio /tmp/truss.log crsctl check boot

cat /etc/oracle/ocr.loc

cd $CRS_HOME/log/serv171/racg

ocrcheck

cd /tmp/.oracle

ps -ef | grep init


olsnodes -p
oifcfg getif (select * from v$cluster_interconects)

clusterware miscount : 2 heartbeats network miscount default 30 secon, disk IOT css disktimeout default to 200 seconds (do not change miscount or disktime unless from Oracle Support)

ocrdump
string OCRDUMPFILE | more
ocrconfig -export

****************************RAC DEBUGS******************************************
errpt -a


crsctl lsmodules crs
      crsctl lsmodules evm
      crsctl lsmodules css

$CRSHOME/bin/diagcollection.pl


Syntax,
sudo -u root crsctl debug log res "ora.vip.com:1"
sudo -u root crsctl debug log res "ora.serv709.LTCDGDBA_SERV709.lsnr:0"
sudo -u root crsctl debug log res "ora.serv709.LTCDGDBA_SERV709.lsnr:1"

voting disk and heart beat timeouts (ocssd.log)

racg:  /apps/oracle/product/CRS/log/serv708/racg
ifconfig -a
oifcfg getif

srvctl modify nodeapps -A ip -address/netmask/interface -node node
eDit ORA_CRS_HOME/bin/racgwrap (baisc trace _USR_ORA_DEBUG=1, SQL trace _USR_ORA_DEBUG=10)

export SRV_TRACE=true

netstat -s (receiving package diskcards, fragmentation or reassembly errors for IP and UDP, collisions, errors, dropped packages
ifconfig -a

ocrcheck, $CRS_HOME/log/serv157/client
ocrconfig -showbackup
ocrconfig -export
ocrdump

crs_stat -v resource_name


Daily useful Oracle 10g RAC troubleshooting commands

oifcfg getif
netstat -p udp
ocfconfig -h
crsctl check crs
crsctl lsmodules css

crsctl trace check css
ocrconfig -showbackup
srvctl config database -d TRXQAC -a -t
srvctl config asm -n serv708
srvctl config listener -n serv708
srvctl status database -d DGDBA -f -v

./cluvfy comp peer -n node1, node2 | more
./cluvf comp -list
./cluvf state -pre crsinst -n node1,node2 -verbose
cluvfy -stage -pre crsinst -n serv171

export SRVM_TRACE=TRUE
truss -aefio /tmp/truss.log crsctl check boot

cat /etc/oracle/ocr.loc

cd $CRS_HOME/log/serv171/racg

ocrcheck

cd /tmp/.oracle

ps -ef | grep init


olsnodes -p
oifcfg getif (select * from v$cluster_interconects)

clusterware miscount : 2 heartbeats network miscount default 30 secon, disk IOT css disktimeout default to 200 seconds (do not change miscount or disktime unless from Oracle Support)

ocrdump
string OCRDUMPFILE | more
ocrconfig -export

****************************RAC DEBUGS******************************************
errpt -a


crsctl lsmodules crs
      crsctl lsmodules evm
      crsctl lsmodules css

$CRSHOME/bin/diagcollection.pl


Syntax,
sudo -u root crsctl debug log res "ora.vip.com:1"
sudo -u root crsctl debug log res "ora.serv709.LTCDGDBA_SERV709.lsnr:0"
sudo -u root crsctl debug log res "ora.serv709.LTCDGDBA_SERV709.lsnr:1"

voting disk and heart beat timeouts (ocssd.log)

racg:  /apps/oracle/product/CRS/log/serv708/racg
ifconfig -a
oifcfg getif

srvctl modify nodeapps -A ip -address/netmask/interface -node node
eDit ORA_CRS_HOME/bin/racgwrap (baisc trace _USR_ORA_DEBUG=1, SQL trace _USR_ORA_DEBUG=10)

export SRV_TRACE=true

netstat -s (receiving package diskcards, fragmentation or reassembly errors for IP and UDP, collisions, errors, dropped packages
ifconfig -a

ocrcheck, $CRS_HOME/log/serv157/client
ocrconfig -showbackup
ocrconfig -export
ocrdump

crs_stat -v resource_name


Copy Datafile from one diskgroup to another using RMAN


TAKE TABLESPACES OFFLINEset echo on
set timing on
spool 1_offline_tblsp.lst
alter tablespace POL_IMG_2006_Q2 offline;
alter tablespace ATTUNITY_Q2 offline;
alter tablespace POL_XML_2006_Q2 offline;
alter tablespace COM_XML_2006_Q2 offline;
spool off

COPY DATAFILE TO ALTERNATE DISKGROUP USING RMAN
copy datafile '+DG_DATA/DBDOC/datafile/attunity_q2.330.594123977' to '+DG_EDOC_PD501';
copy datafile '+DG_DATA/DBDOC/datafile/attunity_q2.384.594123991' to '+DG_EDOC_PD501';
copy datafile '+DG_DATA/DBDOC/datafile/attunity_q2.479.594124003' to '+DG_EDOC_PD501';
copy datafile '+DG_DATA/DBDOC/datafile/attunity_q2.486.594124013' to '+DG_EDOC_PD501';
copy datafile '+DG_DATA/DBDOC/datafile/com_xml_2006_q2.625.594124423' to '+DG_EDOC_PD501';
copy datafile '+DG_DATA/DBDOC/datafile/pol_img_2006_q2.420.593888097' to '+DG_EDOC_PD501';
copy datafile '+DG_DATA/DBDOC/datafile/pol_img_2006_q2.419.593894551' to '+DG_EDOC_PD501';
RENAME DATAFILE USING SQLPLUSalter database rename file '+DG_DATA/DBDOC/datafile/attunity_q2.330.594123977'  to '<new location>';
alter database rename file '+DG_DATA/DBDOC/datafile/attunity_q2.384.594123991'  to '<new location>';
alter database rename file '+DG_DATA/DBDOC/datafile/attunity_q2.479.594124003'  to '<new location>';
alter database rename file '+DG_DATA/DBDOC/datafile/attunity_q2.486.594124013'  to '<new location>';
alter database rename file '+DG_DATA/DBDOC/datafile/com_xml_2006_q2.625.594124423'  to '<new location>';
alter database rename file '+DG_DATA/DBDOC/datafile/pol_img_2006_q2.420.593888097'  to '<new location>';
alter database rename file '+DG_DATA/DBDOC/datafile/pol_img_2006_q2.419.593894551'  to '<new location>';

ONLINE THE TABLESPACES AFTER VERIFICATION
spool 5_online_tblsp.lst
alter tablespace POL_IMG_2006_Q2 online;
alter tablespace ATTUNITY_Q2 online;
alter tablespace POL_XML_2006_Q2 online;
alter tablespace COM_XML_2006_Q2 online;
spool off