1、调整配置。
alter system set audit_trail='NONE' scope=spfile;
alter system set log_archive_format='ARC_ERP5_%s_%r_%t.log' scope=spfile;
alter system set log_archive_dest_1='location=/oraarch' scope=spfile;
alter system set session_cached_cursors=100 scope=spfile;
alter system set open_cursors=1000 scope=spfile;
alter system set undo_retention=25200 scope=spfile;
alter system set recyclebin='OFF' scope=spfile;
alter system set distributed_lock_timeout=300 scope=spfile;
alter system set "_high_priority_processes"='LMS*|LGWR|PMON' scope=spfile;
alter system set memory_max_target=85G scope=spfile;
alter system set memory_target=85G scope=spfile;
show parameter db_files
alter system set db_files=400 scope=spfile;
alter database backup controlfile to trace as '/home/oracle/ctl0505.txt';
alter system set event= '10949 trace name context forever, level 1' scope=spfile;
alter system set event='10949 TRACE NAME CONTEXT FOREVER' scope=spfile;
select action_name, count(*) from dba_audit_trail group by action_name;
show parameter cursor_sharing
alter system set cursor_sharing=FORCE scope=both;
alter system set cursor_sharing=EXACT scope=both;
alter session set cursor_sharing=similar;
2、调整定时任务
exec DBMS_AUTO_TASK_ADMIN.disable (client_name => 'auto optimizer stats collection',operation => NULL,window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.disable (client_name => 'auto space advisor', operation => NULL, window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.disable (client_name => 'sql tuning advisor',operation => NULL,window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.ENABLE (client_name => 'auto optimizer stats collection',operation => NULL,window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.ENABLE (client_name => 'auto space advisor', operation => NULL, window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.ENABLE (client_name => 'sql tuning advisor',operation => NULL,window_name => NULL);
SQL> select client_name,status from dba_autotask_client;
CLIENT_NAME STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection ENABLED
auto space advisor DISABLED
sql tuning advisor DISABLED
SQL>
建议设置 "_enable_shared_pool_durations"=false, 将防止shared pool 发生SHRINK 操作:
alter system set "_enable_shared_pool_durations"=false scope=spfile;
BEGIN
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'SYS.FRIDAY_WINDOW'
,attribute => 'REPEAT_INTERVAL'
,value => 'freq=daily;byday=FRI;byhour=23;byminute=0; bysecond=0');
END;
/
3、调整归档和redo大小,关闭EM(最好别装)。
exec sysman.emd_maintenance.remove_em_dbms_jobs;
commit;
采用UNDO 表空间时,会有一个参数UNDO_RETENTION,该参数用来指定undo 记录保存的最长时间,以秒为单位,是个动态参数,完全可以在实例运行时随时修改,通常默认是900 秒,也就是15 分钟。
show parameter undo
select tablespace_name,status,trunc(sum(blocks) * 8 / 1024) as "Size M",count(*) undo_extent_num
from dba_undo_extents
group by tablespace_name, status;
select 3600*7 from dual;
alter system set undo_retention=25200;
需要空间大小:
select (select value as ur from v$parameter where name = 'undo_retention')*
(select max(undoblks / ((end_time - begin_time) * 24 * 3600)) as ups from v$undostat)*
(select value as dbs from v$parameter where name = 'db_block_size')/1024/1024*1.1 as size_mb
from dual;
只有在一种情况下,undo 表空间能够确保undo 中的数据在undo_retention 指定时间过期前一定有效,就是为undo 表空间指定Retention Guarantee,指定之后,oracle 对于undo 表空间中未过期的undo 数据不会覆盖,例如:
SQL> alter tablespace undotbs1 retention guarantee;
--禁止undo 表空间retention guarantee,例如:
SQL> alter tablespace undotbs1 retention noguarantee;
select RETENTION from dba_tablespaces where tablespace_name='UNDOTBS1';
ALTER TABLESPACE UNDOTBS1 ADD DATAFILE '+DATA' SIZE 1024M AUTOEXTEND ON NEXT 100M MAXSIZE 8192M;
SQL> show parameter dis
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
asm_diskgroups string
asm_diskstring string
disk_asynch_io boolean TRUE
dispatchers string (PROTOCOL=TCP) (SERVICE=sgcrm5
XDB)
distributed_lock_timeout integer 60
max_dispatchers integer
ORA-10949: Disable autotune direct path read for full table scan
alter system set event= '10949 trace name context forever, level 1' scope=spfile;
在session级别设置:
ALTER SESSION SET EVENTS '10949 TRACE NAME CONTEXT FOREVER';
其他参数
REM ===============================FOR STABLE OPTIMIZER===================================
alter system set "_enable_automatic_sqltune"=false scope=both; Automatic SQL Tuning Advisory enabled parameter
#以下优化器参数均可以在session/system级别设置,一般优化器参数均可以在线修改
alter session set "_serial_direct_read"=false;
alter session set "_nlj_batching_enabled" = 0;
alter session set "_optimizer_undo_cost_change" = '10.2.0.4'; -- 11.2.0.1
alter session set "_optimizer_null_aware_antijoin" = false; -- true
alter session set "_optimizer_extend_jppd_view_types" = false; -- true
alter session set "_replace_virtual_columns" = false; -- true
alter session set "_first_k_rows_dynamic_proration" = false; -- true
alter session set "_bloom_pruning_enabled" = false; -- true
alter session set "_optimizer_multi_level_push_pred" = false; -- true
alter session set "_optimizer_group_by_placement" = false; -- true
alter session set "_optimizer_extended_cursor_sharing_rel" = none; -- simple
alter session set "_optimizer_adaptive_cursor_sharing" = false; -- true
alter session set "_optimizer_improve_selectivity" = false ; -- true
alter session set "_optimizer_enable_density_improvements" = false; -- true
alter session set "_optimizer_native_full_outer_join" = off; -- force
alter session set "_optimizer_enable_extended_stats" = false; -- true
alter session set "_nlj_batching_enabled" = 0; -- 1
alter session set "_optimizer_extended_stats_usage_control" = 255; -- 224
alter session set "_bloom_folding_enabled" = false; -- true
alter session set "_optimizer_coalesce_subqueries" = false; -- true
alter session set "_optimizer_fast_pred_transitivity" = false; -- true
alter session set "_optimizer_fast_access_pred_analysis" = false; -- true
alter session set "_optimizer_unnest_disjunctive_subq" = false; -- true
alter session set "_optimizer_unnest_corr_set_subq" = false; -- true
alter session set "_optimizer_distinct_agg_transform" = false; -- true
alter session set "_aggregation_optimization_settings" = 32; -- 0
alter session set "_optimizer_connect_by_elim_dups" = false; -- true
alter session set "_optimizer_eliminate_filtering_join" = false; -- true
alter session set "_connect_by_use_union_all" = old_plan_mode; --true
alter session set "_optimizer_join_factorization" = false; -- true
alter session set "_optimizer_use_cbqt_star_transformation" = false; -- true
alter session set "_optimizer_table_expansion" = false ; -- true
alter session set "_and_pruning_enabled" = false ; -- true
alter session set "_optimizer_distinct_placement" = false ; -- true
alter session set "_optimizer_use_feedback" = false ; -- true
alter session set "_optimizer_try_st_before_jppd" = false ; -- true
REM ===============================MEMORY===================================
alter system set "_memory_imm_mode_without_autosga"=false scope=both;
alter system set "_enable_shared_pool_durations"=false scope=spfile;
REM ===============================SEGMENT==================================
alter system set deferred_segment_creation=false;
@?/rdbms/admin/utlrp.sql
SQL> select * from utl_recomp_errors;
未选定行(这里说明没有错误)
exec dbms_utility.compile_schema('xxx');
select object_name, object_type, owner from dba_objects where status='INVALID';
3、调整AWR
可以通过dbms_workload_repository包对AWR进行配置,也可以通过OEM来配置AWR。例如利用dbms_workload_repository包将AWR自动收集信息的时间间隔改为30分钟,保留策略改为30天。
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>30*24*60);
PL/SQL 过程已成功完成。
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVAL RETENTION TOPNSQL
---------- ------------------------------ -------------------- ----------
1520519778 +00000 00:30:00.0 +00030 00:00:00.0 DEFAULT
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>0);
PL/SQL 过程已成功完成。
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVAL RETENTION TOPNSQL
---------- ------------------------------ -------------------- ----------
1520519778 +40150 00:00:00.0 +00030 00:00:00.0 DEFAULT
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30,
如果在数据库非常繁忙的情况下,希望关闭AWR节省资源,只需要将interval设置为0即可。
如果需要手动抓取快照,收集更精确的信息,只需要执行以下命令。
SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();
PL/SQL 过程已成功完成。
4、收集统计信息
select 'execute DBMS_STATS.gather_table_stats (ownname =>''"'||''||'"'', tabname =>'''||table_name||''','||'estimate_percent =>DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => '''||'FOR ALL COLUMNS SIZE AUTO'',degree => DBMS_STATS.AUTO_DEGREE, cascade => TRUE);'
from dba_tables
where owner=''
and last_analyzed<to_date('2012/11/29 0:51:34','yyyy/mm/dd hh24:mi:ss')
order by last_analyzed desc;
5、观察磁盘IO读写的速度。
注意 :一定要运行并行或并发SQL。这个值很重要。
6、修改密码及profiles文件
ALTER profile DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS unlimited;
ALTER profile DEFAULT LIMIT PASSWORD_LIFE_TIME unlimited;