|
本帖最后由 botang 于 2016-5-22 16:17 编辑
- select * from dict
- where table_name like '%MODIFICATION%';
-
- select * from DBA_TAB_MODIFICATIONS m
- where m.table_owner <> 'SYS';
-
-
- select * from DBA_STAT_EXTENSIONS e
- where e.owner='HR'
- and e.table_name='EMPLOYEES';
-
-
- select
- dbms_stats.create_extended_stats('HR','EMPLOYEES','(salary,commission_pct)') from dual;
-
- begin
- dbms_stats.gather_table_stats(ownname => 'HR',tabname => 'EMPLOYEES',
- method_opt => 'for all columns size auto for columns (salary,commission_pct) size 254');
- end;
-
-
- select * from dba_tab_col_statistics s where s.owner='HR'
- and s.table_name='EMPLOYEES';
-
- select * from dba_histograms h
- where h.owner='HR' and h.table_name='EMPLOYEES';
-
- begin
- dbms_stats.create_stat_table(ownname => 'SYSTEM',stattab => 'MYSTAT');
- end;
-
- select * from system.mystat;
-
- begin
- dbms_stats.export_table_stats(ownname => 'HR',tabname => 'EMPLOYEES',
- statown => 'SYSTEM',
-
- stattab => 'MYSTAT');
- end;
-
-
- begin
- dbms_stats.delete_table_stats(ownname => 'HR',tabname => 'EMPLOYEES');
- end;
- select t.last_analyzed
- from dba_tables t where t.owner='HR' and t.table_name='EMPLOYEES';
-
- begin
- dbms_stats.import_table_stats(ownname => 'HR',tabname => 'EMPLOYEES',
- statown => 'SYSTEM',
-
- stattab => 'MYSTAT');
- end;
- ---
- select * from v$sql_monitor;
- select * from v$sql_plan_monitor;
- select *
- from v$sql where sql_id='05s9358mm6vrr';
-
-
- select * from dict
- where table_name like 'DBA%ACTIVE%';
-
-
- select * from DBA_HIST_ACTIVE_SESS_HISTORY;
复制代码 utlpwdmg.sql:
- Rem
- Rem $Header: utlpwdmg.sql 02-aug-2006.08:18:05 asurpur Exp $
- Rem
- Rem utlpwdmg.sql
- Rem
- Rem Copyright (c) 2006, Oracle. All rights reserved.
- Rem
- Rem NAME
- Rem utlpwdmg.sql - script for Default Password Resource Limits
- Rem
- Rem DESCRIPTION
- Rem This is a script for enabling the password management features
- Rem by setting the default password resource limits.
- Rem
- Rem NOTES
- Rem This file contains a function for minimum checking of password
- Rem complexity. This is more of a sample function that the customer
- Rem can use to develop the function for actual complexity checks that the
- Rem customer wants to make on the new password.
- Rem
- Rem MODIFIED (MM/DD/YY)
- Rem asurpur 05/30/06 - fix - 5246666 beef up password complexity check
- Rem nireland 08/31/00 - Improve check for username=password. #1390553
- Rem nireland 06/28/00 - Fix null old password test. #1341892
- Rem asurpur 04/17/97 - Fix for bug479763
- Rem asurpur 12/12/96 - Changing the name of password_verify_function
- Rem asurpur 05/30/96 - New script for default password management
- Rem asurpur 05/30/96 - Created
- Rem
- -- This script sets the default password resource parameters
- -- This script needs to be run to enable the password features.
- -- However the default resource parameters can be changed based
- -- on the need.
- -- A default password complexity function is also provided.
- -- This function makes the minimum complexity checks like
- -- the minimum length of the password, password not same as the
- -- username, etc. The user may enhance this function according to
- -- the need.
- -- This function must be created in SYS schema.
- -- connect sys/<password> as sysdba before running the script
- CREATE OR REPLACE FUNCTION verify_function_11G
- (username varchar2,
- password varchar2,
- old_password varchar2)
- RETURN boolean IS
- n boolean;
- m integer;
- differ integer;
- isdigit boolean;
- ischar boolean;
- ispunct boolean;
- db_name varchar2(40);
- digitarray varchar2(20);
- punctarray varchar2(25);
- chararray varchar2(52);
- i_char varchar2(10);
- simple_password varchar2(10);
- reverse_user varchar2(32);
- part1 varchar2(30);
- part2 varchar2(30);
- BEGIN
- digitarray:= '0123456789';
- chararray:= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- -- Check for the minimum length of the password
- IF length(password) < 8 or length(password) > 30 THEN
- raise_application_error(-20001, 'Password length less than 8 or more than 30');
- END IF;
- -- Check if the password is same as the username or username(1-100)
- IF NLS_LOWER(password) = NLS_LOWER(username) THEN
- raise_application_error(-20002, 'Password same as or similar to user');
- END IF;
- FOR i IN 1..100 LOOP
- i_char := to_char(i);
- if NLS_LOWER(username)|| i_char = NLS_LOWER(password) THEN
- raise_application_error(-20005, 'Password same as or similar to user name ');
- END IF;
- END LOOP;
- -- Check if the password is same as the username reversed
-
- FOR i in REVERSE 1..length(username) LOOP
- reverse_user := reverse_user || substr(username, i, 1);
- END LOOP;
- IF NLS_LOWER(password) = NLS_LOWER(reverse_user) THEN
- raise_application_error(-20003, 'Password same as username reversed');
- END IF;
-
-
- IF length(password)>length(username) THEN
- part1 := SUBSTR(password, 1, length(username));
- part2 := SUBSTR(password, length(username)+1);
- IF part1=username THEN
-
- isdigit:=FALSE;
- m := length(part2);
- FOR i IN 1..10 LOOP
- FOR j IN 1..m LOOP
- IF substr(part2,j,1) = substr(digitarray,i,1) THEN
- isdigit:=TRUE;
- END IF;
- END LOOP;
- END LOOP;
- IF isdigit=true THEN
- raise_application_error(-20013,'Password same as or similar to username');
- END IF;
- END IF;
- END IF;
- -- Check if the password is the same as server name and or servername(1-100)
- select name into db_name from sys.v$database;
- if NLS_LOWER(db_name) = NLS_LOWER(password) THEN
- raise_application_error(-20004, 'Password same as or similar to server name');
- END IF;
- FOR i IN 1..100 LOOP
- i_char := to_char(i);
- if NLS_LOWER(db_name)|| i_char = NLS_LOWER(password) THEN
- raise_application_error(-20005, 'Password same as or similar to server name ');
- END IF;
- END LOOP;
- -- Check if the password is too simple. A dictionary of words may be
- -- maintained and a check may be made so as not to allow the words
- -- that are too simple for the password.
- IF NLS_LOWER(password) IN ('welcome1', 'database1', 'account1', 'user1234', 'password1', 'oracle123', 'computer1', 'abcdefg1', 'change_on_install') THEN
- raise_application_error(-20006, 'Password too simple');
- END IF;
- -- Check if the password is the same as oracle (1-100)
- simple_password := 'oracle';
- FOR i IN 1..100 LOOP
- i_char := to_char(i);
- if simple_password || i_char = NLS_LOWER(password) THEN
- raise_application_error(-20007, 'Password too simple ');
- END IF;
- END LOOP;
- -- Check if the password contains at least one letter, one digit
- -- 1. Check for the digit
- isdigit:=FALSE;
- m := length(password);
- FOR i IN 1..10 LOOP
- FOR j IN 1..m LOOP
- IF substr(password,j,1) = substr(digitarray,i,1) THEN
- isdigit:=TRUE;
- GOTO findchar;
- END IF;
- END LOOP;
- END LOOP;
- IF isdigit = FALSE THEN
- raise_application_error(-20008, 'Password must contain at least one digit, one character');
- END IF;
- -- 2. Check for the character
- <<findchar>>
- ischar:=FALSE;
- FOR i IN 1..length(chararray) LOOP
- FOR j IN 1..m LOOP
- IF substr(password,j,1) = substr(chararray,i,1) THEN
- ischar:=TRUE;
- GOTO endsearch;
- END IF;
- END LOOP;
- END LOOP;
- IF ischar = FALSE THEN
- raise_application_error(-20009, 'Password must contain at least one \
- digit, and one character');
- END IF;
- <<endsearch>>
- -- Check if the password differs from the previous password by at least
- -- 3 letters
- IF old_password IS NOT NULL THEN
- differ := length(old_password) - length(password);
- differ := abs(differ);
- IF differ < 3 THEN
- IF length(password) < length(old_password) THEN
- m := length(password);
- ELSE
- m := length(old_password);
- END IF;
- FOR i IN 1..m LOOP
- IF substr(password,i,1) != substr(old_password,i,1) THEN
- differ := differ + 1;
- END IF;
- END LOOP;
- IF differ < 3 THEN
- raise_application_error(-20011, 'Password should differ from the \
- old password by at least 3 characters');
- END IF;
- END IF;
- END IF;
- -- Everything is fine; return TRUE ;
- RETURN(TRUE);
- END;
- /
- -- This script alters the default parameters for Password Management
- -- This means that all the users on the system have Password Management
- -- enabled and set to the following values unless another profile is
- -- created with parameter values set to different value or UNLIMITED
- -- is created and assigned to the user.
- ALTER PROFILE DEFAULT LIMIT
- PASSWORD_LIFE_TIME 180
- PASSWORD_GRACE_TIME 7
- PASSWORD_REUSE_TIME UNLIMITED
- PASSWORD_REUSE_MAX UNLIMITED
- FAILED_LOGIN_ATTEMPTS 10
- PASSWORD_LOCK_TIME 1
- PASSWORD_VERIFY_FUNCTION verify_function_11G;
- -- Below is the older version of the script
- -- This script sets the default password resource parameters
- -- This script needs to be run to enable the password features.
- -- However the default resource parameters can be changed based
- -- on the need.
- -- A default password complexity function is also provided.
- -- This function makes the minimum complexity checks like
- -- the minimum length of the password, password not same as the
- -- username, etc. The user may enhance this function according to
- -- the need.
- -- This function must be created in SYS schema.
- -- connect sys/<password> as sysdba before running the script
复制代码
OCM参考答案:
- **********************************************************
- Skillset 1: Database, RMAN, EM, and Network Configuration *
- **********************************************************
- Section 1: Network Configuration
- 配置链接串 对prod1/prod2进行验证。创建EMREP
- ---archive log list;
- ---show parameter db_recovery_
- ---enable flashback database
- ---check sys/system password
- ---check dedicate server
- ---both node alter user dbsnmp identified by oracle;
- Section 2: Collecting Statistics
- connect sys/oracle@prod1 as sysdba
- exec dbms_stats.gather_schema_stats('HR');
- Section 3: Authentication Method
- CONNECT sys/oracle@prod1 as SYSDBA
- ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON=true;
- orapwd file=orapwPROD1 password entries=5 ignorecase=n
- CONNECT sys/oracle@prod1 as SYSDBA
- --add code
- vi utlpwdmg.sql
- part1 varchar2(30);
- part2 varchar2(30);
- function is_number(i_str varchar2)
- return boolean
- is
- v_number number;
- begin
- select to_number(i_str) into v_number from dual;
- if v_number is not null then
- return true;
- else
- return false;
- end if;
- EXCEPTION
- WHEN OTHERS THEN
- return false;
- end;
- IF length(password)>30 then
- raise_application_error(-20012,'Password length more then 30');
- END IF;
- IF length(password)>length(username) THEN
- part1 := SUBSTR(password, 1, length(username));
- part2 := SUBSTR(password, length(username)+1, length(password)-length(username));
- IF part1=username THEN
- IF is_number(part2) THEN
- raise_application_error(-20013,'Password same as or similar to username');
- END IF;
- END IF;
- END IF;
- @?/rdbms/admin/utlpwdmg.sql
- ALTER PROFILE DEFAULT LIMIT PASSWORD_VERIFY_FUNCTION verify_function_11g;
- Section 4: Storing Diagnostic Information
- CONNECT sys/oracle@prod1 as SYSDBA
- alter system set DIAGNOSTIC_DEST='/u01/app/oracle/product/11.1.0/db_1'
- Section 5: Improving Access to the Network File Directories
- find this file in directory
- (1)$ORACLE_HOME/dbs/oranfstab
- (2)/etc/oranfstab
- (3)/etc/mtab
- cd $ORACLE_HOME/dbs
- vi oranfstab
- server: MyDataServer1
- path: 132.34.35.12
- export: /vol/oradata mount: /u02/oradata/prod1
- cd $ORACLE_HOME/lib
- mv libodm11.so libodm11.so_stub
- ln -s libnfsodm11.so libodm11.so
- conn sys/oracle@prod1 as sysdba
- shutdown immediate
- startup
- create tablespace SHARED_DATA datafile '/u02/oradata/prod1/shared_data.tbs.dbf' size 10m;
- --check
- select * from v$dnfs_servers;
- Section 6: Applying a Patch
- export PATH=$ORACLE_HOME/OPatch
- cd /home/oracle/scripts
- unzip p8342329_111070_linux-x86.zip
- cd 8342329
- $ORACLE_HOME/OPatch/opatch query -is_online_patch `pwd`
- --prod1/prod2 should be shutdown
- $ORACLE_HOME/OPatch/opatch apply
- $ORACLE_HOME/OPatch/opatch lsinventory
- Section 7: Enabling Grid Control to Manage Targets on the Database Machine
- http://oms:4889/agent_download/10.2.0.1.0/linux
- http://oms:4889/agent_download/10.2.0.5.0/linux
- download agentDownload.linux
- chmod a+x agentDownload.linux
- export PATH=$ORACLE_HOME/jdk/bin:$PATH
- java -version
- which java
- --10.2.0.5
- 1
- ./agentDownload.linux -b /u01/app/oracle/product/11.1.0/ -m oms.us.oracle.com -r 4889
- ssh oms-->tar -cvf agent10g.tar agent10g/-->scp agent10.tar to dbsever-->tar -xvf agent10g.tar
- cd oui/bin
- runInstaller -clone -forceClone ORACLE_HOME=/u01/app/oracle/product/11.1.0/agent10g ORACLE_HOME_NAME=agent10ghome -noconfig -silent
- agentca -f
- ./root.sh
- emctl secure agent
- --10.2.0.1
- ./agentDownload.linux -b /u01/app/oracle/product/11.1.0/
- Section 8: Creating a Recovery Catalog
- conn sys/oracle@emrep as sysdba
- create bigfile tablespace rc_data datafile '/u01/app/oracle/oradata/PROD2/rc_data.dbf' size 100m;
- ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON=true;
- create user rc_admin identified by RC_ADMIN default tablespace rc_data;
- grant resource,connect,recovery_catalog_owner to rc_admin;
- rman catalog rc_admin/RC_ADMIN@emrep
- create catalog tablespace rc_data;
- --from catalog register
- rman target sys/oracle@prod1 catalog rc_admin/RC_ADMIN@emrep
- register database;
- rman target sys/oracle@prod2 catalog rc_admin/RC_ADMIN@emrep
- register database;
- Section 9: Backups
- --prod1 and prod2
- rman target sys/oracle@prod1 catalog rc_admin/RC_ADMIN@emrep
- configure controlfile autobackup on;
- run {
- backup database tag='Q107' format '/home/oracle/files/%U' plus archivelog tag='Q107' format '/home/oracle/files/%U' KEEP FOREVER;}
- select bytes/1024/1024/30 from v$datafile a, v$tablespace b where b.tablespace_name='EXAMPLE' and b.ts#=a.ts#;
- run{
- allocate channel c1 device type disk;
- allocate channel c2 device type disk;
- allocate channel c3 device type disk;
- allocate channel c4 device type disk;
- backup tablespace example section size 30m format '/home/oracle/files/%U';}
- rman target sys/oracle@prod2 catalog rc_admin/RC_ADMIN@emrep
- configure controlfile autobackup on;
- backup database tag='prod2_full' format '/home/oracle/files/%U' plus archivelog tag='prod2_full' format '/home/oracle/files/%U' delete all input
- ************************
- Skillset 2: Data Guard*
- ************************
- Section 1: Creating a Physical Standby Database
- conn sys/oracle@prod1 as sysdba
- alter database force logging;
- alter database add standby logfile '/u01/app/oracle/oradata/PROD1/stdby01.log' size 50m;
- alter database add standby logfile '/u01/app/oracle/oradata/PROD1/stdby02.log' size 50m;
- alter database add standby logfile '/u01/app/oracle/oradata/PROD1/stdby03.log' size 50m;
- alter database add standby logfile '/u01/app/oracle/oradata/PROD1/stdby04.log' size 50m;
- ---primary role parameter setting
- alter system set log_archive_config='dg_config=(PROD1,SBDB1)';
- alter system set log_archive_dest_1='LOCATION=/home/oracle/files/arch/prod1 VALID_FOR=(online_logfiles,primary_role) db_unique_name=PROD1';
- alter system set log_archive_dest_2='service=SBDB1 SYNC AFFIRM valid_for=(online_logfiles,primary_role) db_unique_name=SBDB1';
-
- ---standby role parameter setting make a just parameter db_name=SBDB1 vi initSBDB1 in /home/oracle/files
- ---configure tnsnames.ora on primary and standby
- ---make static register in listener on standby
- ---copy password file to standby host ,and rename it
- ---make directory on standby host
- mkdir -p /u01/app/oracle/admin/SBDB1/adump
- mkdir -p /u01/app/oracle/flash_recovery_area
- mkdir -p /u01/app/oracle/oradata/SBDB1
- ---duplicate standby
- conn sys/oracle@sbdb1 as sysdba
- startup nomount pfile=/home/oracle/file/initSBDB1;
- rman target sys/oracle@prod1 auxiliary sys/oracle@sbdb1 catalog rc_admin/RC_ADMIN@emrep;
- run {
- allocate channel c1 device type disk;
- allocate channel c2 device type disk;
- allocate channel c3 device type disk;
- allocate channel c4 device type disk;
- allocate auxiliary channel stby type disk;
- duplicate target database for standby from active database
- spfile parameter_value_convert '/PROD1','/SBDB1'
- set db_unique_name='SBDB1'
- set db_file_name_convert='/u01/app/oracle/oradata/PROD1/','/u01/app/oracle/oradata/SBDB1/'
- set log_file_name_convert='/u01/app/oracle/oradata/PROD1/','/u01/app/oracle/oradata/SBDB1/'
- set standby_file_management='auto'
- set FAL_CLIENT='SBDB1'
- set FAL_SERVER='PROD1'
- set log_archive_dest_1='location=/home/oracle/files/arch/sbdb1 valid_for=(online_logfile,primary_role) db_unique_name=SBDB1'
- set log_archive_dest_3='location=/home/oracle/files/arch/prod1 valid_for=(standby_logfile,standby_role) db_unique_name=SBDB1'
- set log_archive_dest_2='service=PROD1 SYNC AFFIRM valid_for=(online_logfile,primary_role) db_unique_name=PROD1';}
-
- ---enable flashback database
- ---enable realtime-apply
- alter database flashback on;
- alter database recover managed standby database using current logfile disconnect from session;
-
- ----create dataguard broker
- ----make static register in listener.ora, global name must be PROD1_DGMGRL and SBDB1_DGMGRL/ make tnsnames.ora connect PROD1_DGMGRL and SBDB1_DGMGRL
- conn sys/oracle@prod1 as sysdba
- alter system set dg_broker_start=true;
- conn sys/oracle@sbdb1 as sysdba
- alter system set dg_broker_start=true;
-
- dgmgrl sys/oracle@prod1
- CREATE CONFIGURATION 'dgconfig' AS PRIMARY DATABASE IS PROD1 CONNECT IDENTIFIER IS PROD1;
- add database SBDB1 as connect identifier is sbdb1 MAINTAINED AS physical;
- ENABLE CONFIGURATION;
-
-
- Section 2: Testing the Standby Database
- --convert database from physical standby to snapshot standby
- convert database SBDB1 to snapshot standby;
- Section 3: Restoring the Standby Database
- --convert database from snapshot standby to phyical standby
- convert database SBDB1 to physical standby;
-
- --active dataguard
- edit database SBDB1 set state='apply-off';
- alter database open;
- edit database SBDB1 set state='apply-on';
- 4、
- ---ENABLE BLOCK CHANGE TRACKING ON STANDBY
- sqlplus /nolog
- conn sys/oracle@sbdb1 as sysdba
- alter database enable block change tracking using file '/home/oracle/files/block_change_tracking.f';
-
- ---PROTECT ARCHIVELOG
- rman target / catalog rc_admin/RC_ADMIN@emrep
- CONFIGURE ARCHIVELOG DELETION POLICY TO SHIPPED TO ALL STANDBY;
-
- ---ENABLE FAST-START FAILOVER
- 1、edit database PROD1 set property FastStartFailoverTarget="SBDB1";
- edit database SBDB1 set property FastStartFailoverTarget="PROD1";
-
- 2、enable fast_start failover;
- 3、start observer
-
- **********************************************************
- Skillset 3: Data and Data Warehouse Management *
- **********************************************************
- Section 1: Fast Refreshable Materialized View
- alter user hr identified by hr account unlock;
- alter user sh identified by sh account unlock;
- alter user bi identified by bi account unlock;
- alter user oe identified by OE account unlock;
- create directory dump_dir as '/home/oracle/files';
- grant dba,advisor to sh;
- conn sh/sh@prod1
- var adv_name varchar2(20)
- begin
- dbms_advisor.tune_mview
- (
- :adv_name,
- 'CREATE MATERIALIZED VIEW sh.prod_mv AS SELECT SUM(prod_list_price - prod_min_price) M1, COUNT(prod_category) M2, prod_category FROM products GROUP BY prod_category');
- end;
- /
- begin
- dbms_advisor.create_file (
- dbms_advisor.get_task_script(:adv_name),
- 'DUMP_DIR',
- 'mvtune_script.sql');
- end;
- /
- Answer :
- CREATE MATERIALIZED VIEW LOG ON "SH"."PRODUCTS"
- WITH ROWID, SEQUENCE ("PROD_CATEGORY","PROD_LIST_PRICE","PROD_MIN_PRICE")
- INCLUDING NEW VALUES
- /
-
- CREATE MATERIALIZED VIEW SH.PROD_MV
- REFRESH FAST WITH ROWID
- ENABLE QUERY REWRITE
- AS SELECT SH.PRODUCTS.PROD_CATEGORY C1, COUNT("SH"."PRODUCTS"."PROD_CATEGORY") M1,
- SUM("SH"."PRODUCTS"."PROD_LIST_PRICE"-"SH"."PRODUCTS"."PROD_MIN_PRICE")
- M2, COUNT("SH"."PRODUCTS"."PROD_LIST_PRICE"-"SH"."PRODUCTS"."PROD_MIN_PRICE")
- M3, COUNT(*) M4 FROM SH.PRODUCTS GROUP BY SH.PRODUCTS.PROD_CATEGORY;
- Section 2: Creating a Database Link
- CREATE PUBLIC DATABASE LINK "PROD_LINK" USING 'PROD1';
- Section 3: Creating a Plug-in Tablespace Using the Transportable Tablespace Feature
- create user sst identified by Sst1234;
- grant connect,resource to sst;
- rman target sys/oracle@prod1 catalog rc_admin/RC_ADMIN
- convert datafile '/home/oracle/scripts/TRPDATA_6' from platform 'Solaris[tm] OE (64-bit)' format='/home/oracle/files/TRPDATA_6.dbf';
- impdp system/oracle dumpfile=dump_dir:trans3_2.dmp transport_datafiles=/u01/app/oracle/oradata/PROD1/TRPDATA_6.dbf
- alter tablespace trpdata read write;
- Section 4: Optimizing Star Queries
- alter system set star_transformation_enabled=true;
- create bitmap index sales_channel_bix on sh.sales(channel_id);
- create bitmap index sales_time_bix on sh.sales(time_id);
- create bitmap index sales_cust_bix on sh.sales(cust_id);
- alter session set star_transformation_enabled=true;
- /
- SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc,
- SUM(s.amount_sold) sales_amount
- FROM sh.sales s, sh.times t, sh.customers c, sh.channels ch
- WHERE s.time_id = t.time_id
- AND s.cust_id = c.cust_id
- AND s.channel_id = ch.channel_id
- AND c.cust_state_province = 'CA'
- AND ch.channel_desc in ('Internet','Catalog')
- AND t.calendar_quarter_desc IN ('1999-Q1','1999-Q2')
- GROUP BY ch.channel_class, c.cust_city, t.calendar_quarter_desc
- /
- Section 5: Configuring Parallel Execution
- 1、
- alter system set parallel_max_servers=100;
- alter system set parallel_min_servers=10;
- 2、???????????
- alter system set PARALLEL_MIN_PERCENT=60 scope=spfile;
- 3、
- ALTER TABLE "SH"."SALES" PARALLEL 8;
- 4、????????????????????
- @utlxplan.sql
- alter session enable parallel dml
- /
- TRUNCATE TABLE plan_table
- /
- EXPLAIN PLAN
- SET STATEMENT_ID = 'Raise quantity'
- INTO plan_table
- FOR UPDATE sh.sales SET quantity_sold=quantity_sold+100
- /
- INSERT INTO sh.par_tab VALUES('Raise quantity')
- /
- COMMIT
- /
- SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY())
- /
- Section 6: Optimize the space usage for LOB Data
- 1、
- create tablespace sf_data datafile '/u01/app/oracle/oradata/PROD1/sf_data.dbf' size 150m
- autoextend on extent management local uniform size 64M;
- 2、5
- create table oe.CUSTOMER_PROFILES(
- CUST_ID NUMBER,
- FIRST_NAME VARCHAR2(20),
- LAST_NAME VARCHAR2(30),
- PROFILE_INFO BLOB
- )
- lob (profile_info) store as securefile
- (
- disable storage in row
- deduplicate
- compress high
- tablespace sf_data
- )
- tablespace sf_data
- /
- 3、
- create directory cust_files as '/home/oracle/scripts/cust_files';
- grant read,write on directory cust_files to oe;
- conn oe/OE
- 4、 @3_4_6.sql
-
- Section 7: Creating a Partitioned Table to save storing unnecessary columns
- conn sh/sh
- create table sh.new_order_items(
- order_id number(12) not null,
- product_id number not null,
- quantity number not null,
- sales_amount number not null,
- constraint fk_order_id foreign key (order_id)
- references sh.new_orders(order_id)
- )
- partition by reference (fk_order_id);
- /
- @3_7_1.sql
- Section 8: Using Partitioning to store non-existent partitions
- conn sys/oracle@prod1 as sysdba
- @3_8_1.sql
- create table sh.sales_history_2006(
- PROD_ID NUMBER NOT NULL,
- CUST_ID NUMBER NOT NULL,
- TIME_ID DATE NOT NULL,
- CHANNEL_ID NUMBER NOT NULL,
- PROMO_ID NUMBER NOT NULL,
- QUANTITY_SOLD NUMBER(10,2) NOT NULL,
- AMOUNT_SOLD NUMBER(10,2) NOT NULL
- )
- partition by range (time_id)
- interval (interval '1' month)
- (
- partition sal1 values less than (to_date('2003-01-01','YYYY-MM-DD')) tablespace SALES_TBS1,
- partition sal2 values less than (to_date('2004-01-01','YYYY-MM-DD')) tablespace SALES_TBS2,
- partition sal3 values less than (to_date('2005-01-01','YYYY-MM-DD')) tablespace SALES_TBS3,
- partition sal4 values less than (to_date('2006-01-01','YYYY-MM-DD')) tablespace SALES_TBS4
- )
- /
- @3_8_2.sql
- Section 9: Configuring the Database to Retrieve All Previous Versions of the Table Rows
- create tablespace fratbs datafile '/u01/app/oracle/oradata/PROD1/fratbs.dbf' size 50m;
- create user fra_admin identified by abc123456;
- grant FLASHBACK ARCHIVE ADMINISTER,connect,resource to fra_admin;
- connect fra_admin/abc123456
- create flashback archive fra1 tablespace fratbs retention 1 year;
- GRANT FLASHBACK ARCHIVE ON FRA1 TO SH;
- conn sh/sh
- alter table sh.promotions flashback archive fra1;
- Section 10: Capturing and Propagating Streams
- ---on emrep/prod1
- ---archive log list;
- ---check hr user on target
- alter system set global_names=true;
- create directory src_dir as '/home/oracle/files';
- create directory dst_dir as '/home/oracle/files';
- create tablespace streams_tbs datafile '/u01/app/oracle/oradata/PROD1/streams_tbs.dbf' size 100m
- /
- create user strmadmin identified by streams_123 default tablespace streams_tbs
- /
- grant dba,select_catalog_role,select any dictionary to strmadmin
- /
- begin
- dbms_streams_auth.grant_admin_privilege('STRMADMIN',true);
- end;
- /
- conn strmadmin/streams_123@prod1
- create database link emrep
- connect to strmadmin identified by streams_123
- using 'emrep'
- /
- conn strmadmin/streams_123@emrep
- create database link prod1
- connect to strmadmin identified by streams_123
- using 'prod1'
- /
- conn strmadmin/streams_123@prod1
- begin
- dbms_streams_adm.maintain_tables(
- table_names=>'hr.employees,hr.departments',
- source_directory_object=>'SRC_DIR',
- destination_directory_object=>'DST_DIR',
- source_database=>'PROD1',
- destination_database=>'EMREP',
- capture_name => 'PROD1_CAPTURE',
- propagation_name => 'PROD1_PROPAGATION',
- perform_actions=>true,
- bi_directional=>false,
- include_ddl=>true,
- instantiation=>dbms_streams_adm.instantiation_table_network
- );
- end;
- /
- select STREAMS_TYPE,rule_name,RULE_TYPE from DBA_STREAMS_TABLE_RULES
- conn hr/hr
- @3_10_4.sql
- BEGIN
- DBMS_STREAMS_ADM.SET_RULE_TRANSFORM_FUNCTION(
- rule_name => 'departments4',
- transform_function => 'hr.zero_sal');
- END;
- /
- ---if error see
- EXECUTE DBMS_STREAMS_ADM.REMOVE_STREAMS_CONFIGURATION();
- execute dbms_streams_adm.RECOVER_OPERATION(operation_mode = 'FORWARD'/operation_mode = 'ROLLBACK'/operation_mode = 'PURGE');
- DBA_RECOVERABLE_SCRIPT_ERRORS
- DBA_RECOVERABLE_SCRIPT
- DBA_RECOVERABLE_SCRIPT_PARAMS
- DBA_RECOVERABLE_SCRIPT_BLOCKS
- **********************************************************
- Skillset 4: Performance Management *
- **********************************************************
- Section 1: Configuring the Resource Manager
- alter user hr identified by hr account unlock;
- alter user sh identified by sh account unlock;
- alter user bi identified by bi account unlock;
- alter user oe identified by OE account unlock;
- BEGIN
- dbms_resource_manager.clear_pending_area();
- dbms_resource_manager.create_pending_area();
- dbms_resource_manager.create_consumer_group(consumer_group => 'OLTP',comment=>'');
- dbms_resource_manager.submit_pending_area();
- BEGIN
- dbms_resource_manager_privs.grant_switch_consumer_group(?,?,case ? when 'false' then false when 'true' then true else false end);
- END;
- END;
- BEGIN
- dbms_resource_manager.clear_pending_area();
- dbms_resource_manager.create_pending_area();
- dbms_resource_manager.create_plan( plan => 'DAYTIME',COMMENT=>'');
- dbms_resource_manager.create_plan_directive(
- plan =>'DAYTIME',
- group_or_subplan => 'LOW_GROUP',
- COMMENT=>''
- );
- dbms_resource_manager.create_plan_directive(
- plan =>'DAYTIME',
- group_or_subplan => 'OLTP',
- comment => '',
- switch_io_reqs =>10000 ,
- switch_io_megabytes =>2500,
- switch_group =>'LOW_GROUP',
- switch_for_call=> TRUE
- );
- dbms_resource_manager.create_plan_directive(
- plan =>'DAYTIME',
- group_or_subplan => 'OTHER_GROUPS',
- comment => '',
- switch_io_reqs =>10000 ,
- switch_io_megabytes =>2500,
- switch_group =>'LOW_GROUP',
- switch_for_call => TRUE
- );
- dbms_resource_manager.submit_pending_area();
- END;
- alter system set resource_manager_plan='DAYTIME';
- Section 2: Tuning SQL Statements
- 2.1
- alter system set RESULT_CACHE_MAX_SIZE=15m;
- alter system set CLIENT_RESULT_CACHE_SIZE = 128m;
-
- set feedback on
- set echo on
- pause Press enter to continue
- set autot on explain stat
- SELECT /*+RESULT_CACHE*/ department_id, AVG(salary)
- FROM employees
- GROUP BY department_id
- /
- set autot off
- pause Press enter to continue
- Update employees set salary=salary*.1+salary
- where department_id=20
- /
- commit
- /
- set autot on explain stat
- pause Press enter to continue
- SELECT /*+RESULT_CACHE*/ department_id, AVG(salary)
- FROM employees
- GROUP BY department_id
- /
- set autot off
- Update employees set salary=salary*.1+salary
- where job_id='SA_REP'
- /
- commit
- /
- pause Press enter to continue
- set autot on explain stat
- SELECT /*+RESULT_CACHE*/ department_id, AVG(salary)
- FROM employees
- GROUP BY department_id
- /
- set autot off
- 2.2
- select dbms_stats.create_extended_stats('SH','CUSTOMERS','(CUST_CITY,CUST_STATE_PROVINCE,COUNTRY_ID)') from dual;
- exec dbms_stats.gather_table_stats('SH','CUSTOMERS',method_opt=>'for all columns size 1 for columns (CUST_CITY,CUST_STATE_PROVINCE,COUNTRY_ID) size 3');
- select * from USER_STAT_EXTENSIONS
- select dbms_stats.show_extended_stats_name('SH','CUSTOMERS','(CUST_CITY,CUST_STATE_PROVINCE,COUNTRY_ID)') from dual;
-
- 2.3
- exec dbms_stats.set_table_prefs('SH','SALES','PUBLISH','false');
- exec dbms_stats.gather_table_stats('SH','SALES',NO_INVALIDATE=>TRUE);
- alter session set optimizer_use_pending_statistics = true;
-
- Section 3: Index Tuning
- CREATE INDEX PROD_IDX on sh.PRODUCT_INFORMATION_PART (PRODUCT_ID) GLOBAL PARTITION BY HASH (PRODUCT_ID) PARTITIONS 4 STORE IN (TBS1);
- (PARTITION p1 TABLESPACE tbs_1,PARTITION p2 TABLESPACE tbs_2,PARTITION p3 TABLESPACE tbs_3,PARTITION p4 TABLESPACE tbs_4);
- Section 4: Real Application Testing
- 4.1/4.2
- impdp apps/Apps1234 dumpfile=dump_dir:appsstg.dmp full=y logfile=dump_dir:impdp.log
- conn apps/Apps1234
- @?/rdbms/admin/utlxplan.sql
- grant advisor,dba to apps;
- begin
- dbms_sqltune.unpack_stgtab_sqlset(
- replace=>true,
- staging_table_name=>'STS_PS_TAB',
- staging_schema_owner=>'APPS'
- );
- end;
- /
- dbms_sqltune.create_tuning_task
- dbms_sqltune.execute_tuning_task('sql_tuning_test');
- USER_ADVISOR_TASKS
- dbms_sqltune.report_tning_task
- --SQL Performance Analyzer
- alter system set optimizer_features_enable='10.2.0.1';
- var tname varchar2(30);
- exec :tname:= dbms_sqlpa.create_analysis_task(sqlset_name => 'STS_PS', task_name => 'MYSPA');
- exec dbms_sqlpa.execute_analysis_task(task_name => :tname,execution_type => 'TEST EXECUTE', execution_name => 'before');
- select dbms_sqlpa.report_analysis_task(task_name => :tname,type=>'text', section=>'summary') FROM dual;
- alter system set optimizer_features_enable='11.1.0.7';
- exec dbms_sqlpa.execute_analysis_task(task_name => :tname,execution_type => 'TEST EXECUTE', execution_name => 'after');
- select dbms_sqlpa.report_analysis_task(task_name => :tname,type=>'text', section=>'summary') FROM dual;
- exec dbms_sqlpa.execute_analysis_task(task_name => :tname,execution_type => 'COMPARE PERFORMANCE');
- select dbms_sqlpa.report_analysis_task(task_name => :tname,type=>'text', section=>'summary') FROM dual;
- EXEC DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name =>:tname,execution_type => 'compare performance', execution_params =>
- dbms_advisor.arglist( 'execution_name1', 'before','execution_name2', 'after', 'comparison_metric', 'buffer_gets'));
- insert into plan_table select statement_id,plan_id,timestamp,remarks,OPERATION,OPTIONS,OBJECT_NODE,OBJECT_OWNER,OBJECT_NAME,OBJECT_ALIAS,OBJECT_INSTANCE,OBJECT_TYPE,OPTIMIZER,SEARCH_COLUMNS,ID,PARENT_ID,DEPTH,POSITION,COST,CARDINALITY,BYTES,OTHER_TAG,PARTITION_START,PARTITION_STOP,PARTITION_ID,OTHER,DISTRIBUTION,CPU_COST,IO_COST,TEMP_SPACE,ACCESS_PREDICATES,FILTER_PREDICATES,PROJECTION,TIME,QBLOCK_NAME,OTHER_XML
- from DBA_ADVISOR_SQLPLANS where task_name='MYSPA' and execution_name='SECOND_SQL_TRIAL' and sql_id in('',''
- 4.3
- export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
- create directory capture_dir '/home/oracle/scripts/capture';
- BEGIN
- DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE ('CAPTURE_DIR');
- END;
- /
- BEGIN
- DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY (replay_name => 'REPLAY1',replay_dir => 'CAPTURE_DIR');
- END;
- /
- select * from DBA_WORKLOAD_CONNECTION_MAP=>connection_id
- BEGIN
- DBMS_WORKLOAD_REPLAY.REMAP_CONNECTION (connection_id => 1,
- replay_connection => 'hostname:1521/PROD1');
- END;
- /
- BEGIN
- DBMS_WORKLOAD_REPLAY.REMAP_CONNECTION (connection_id => 2,
- replay_connection => 'hostname:1521/PROD1');
- END;
- /
- BEGIN
- DBMS_WORKLOAD_REPLAY.PREPARE_REPLAY (synchronization => TRUE);
- END;
- /
- wrc REPLAYDIR=/home/oracle/scripts/capture USERID=system PASSWORD=oracle
- wrc system/oracle@test mode=replay replaydir=/home/oracle/scripts/capture
- begin
- dbms_workload_replay.start_replay;
- end;
- /
- ----export to AWR
- BEGIN
- DBMS_WORKLOAD_REPLAY.EXPORT_AWR (replay_id => 1);
- END;
- /
- -----interpruted replay
- BEGIN
- DBMS_WORKLOAD_REPLAY.CANCEL_REPLAY ();
- END;
- /
- BEGIN
- DBMS_WORKLOAD_REPLAY.DELETE_REPLAY_INFO(REPLAY_ID=>?);
- END;
- /
- DBMS_WORKLOAD_CAPTURE
- select * from DBA_WORKLOAD_CONNECTION_MAP
- select * from DBA_WORKLOAD_REPLAYS
- Section 5: Evolving SQL Plan Baselines
- 5.1
- alter system set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=true;
- @4_5_1.sql
- select sql_handle, plan_name, enabled, accepted, fixed from dba_sql_plan_baselines;
- declare
- test binary_integer;
- begin
- test := dbms_spm.LOAD_PLANS_FROM_CURSOR_CACHE(sql_id=>'')
- end;
- /
- variable ret clob
- declare
- begin
- :ret :=
- dbms_spm.evolve_sql_plan_baseline(
- 'SYS_SQL_f6cb7f742ef93547',
- 'SYS_SQL_PLAN_2ef9354754bc8843'
- );
- end;
- /
- print ret
- select sql_handle, plan_name, enabled, accepted, fixed from dba_sql_plan_baselines;
- Section 6: Capturing Performance Statistics
- BEGIN
- DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE_TEMPLATE (
- start_time => '2010-07-31 18:00:00',
- end_time => '2010-08-01 18:00:00',
- baseline_name => 'WEEKEND',
- template_name => 'WEEKEND');
- END;
- /
- PERFORMANCE TUNNING GUIDE 5
复制代码
|
|