know about and are free - oracledoug.comoracledoug.com/graham_wood_hidden_features.pdf ·...
TRANSCRIPT
Database Vault
Transparent Data Encryption
Grid Computing
Self Managing Database
XML Database
Oracle Data Guard
Real Application Clusters
Flashback Query
Virtual Private Database
Built in Java VM
Partitioning Support
Built in Messaging
Object Relational Support
Multimedia Support
Data Warehousing Optimizations
Parallel Operations
Distributed SQL & Transaction Support
Cluster and MPP Support
Multi-version Read Consistency
Client/Server Support
Platform Portability
Commercial SQL Implementation
1977
Oracle Database30 Years of Sustained Innovation
2007
5
Things that you might not know about
DBMS_MONITOR.SESSION_TRACE_ENABLE(
session_id IN BINARY_INTEGER DEFAULT NULL,
serial_num IN BINARY_INTEGER DEFAULT NULL,
waits IN BOOLEAN DEFAULT TRUE,
binds IN BOOLEAN DEFAULT FALSE,
plan_stat IN VARCHAR2 DEFAULT NULL);
6
Things that you might not know about
DBMS_MONITOR.SESSION_TRACE_ENABLE(
session_id IN BINARY_INTEGER DEFAULT NULL,
serial_num IN BINARY_INTEGER DEFAULT NULL,
waits IN BOOLEAN DEFAULT TRUE,
binds IN BOOLEAN DEFAULT FALSE,
plan_stat IN VARCHAR2 DEFAULT NULL);
• Frequency at which we dump row source statistics.
Value should be 'NEVER', 'FIRST_EXECUTION'
(equivalent to NULL) or 'ALL_EXECUTIONS'.
7
Things that you might not know about
• SQL trace
– Enabling
– Capture row source data for more executions
– Trace file contents
– CLOSE statements captured
– Previously this was missing time
– Cursor mapping broken (11gR1)
– Statement text printed on every execute
– Long cursor numbers (11gR2)
– Not so „human readable‟
8
Things that you might not know about
• SQL trace
– Enabling
– Capture row source data for more executions
– Trace file contents
– CLOSE statements captured
– Previously this was missing time
– Cursor mapping broken (11gR1)
– Statement text printed on every execute
– Long cursor numbers (11gR2)
– Tkprof enhancements
– Prints SQL id and plan hash for each statement
– Reports First, Avg, Max from multiple row source dumps
9
Things that you might not know about
• SQL trace
– Enabling
– Capture row source data for more executions
– Trace file contents
– CLOSE statements captured
– Previously this was missing time
– Cursor mapping broken (11gR1)
– Statement text printed on every execute
– Long cursor numbers (11gR2)
– Tkprof enhancements
– Prints SQL id and plan hash for each statement
– Reports First, Avg, Max from multiple row source dumps
– But not CLOSE … doh!
10
Things that you might not know about
• SQL trace
– Enabling trace for individual SQL statements
alter session set events 'sql_trace [sql: g3yc1js3g2689 |
7ujay4u33g337]'
11
Things that you might not know about
• SQL
– Getting SQL info without making problem worse
V$SQLstat
12
Things that you might not know about
• SQL
– Get outline data for a single statement
SELECT * FROM table (
DBMS_XPLAN.DISPLAY_CURSOR
('atfwcg8anrykp', NULL, „ADVANCED'));
– Get Estimated and Actual rows
SELECT * FROM table (
DBMS_XPLAN.DISPLAY_CURSOR
(FORMAT=>'ALLSTATS LAST'));
Things that you might not know aboutSELECT /*+ gather_plan_statistics */ p.prod_name, SUM(s.quantity_sold)
FROM sales s, products p
WHERE s.prod_id =p.prod_id GROUP By p.prod_name ;
SELECT * FROM table (
DBMS_XPLAN.DISPLAY_CURSOR(FORMAT=>'ALLSTATS LAST'));
14
Things that you might not know about
• SQL
– Set a parameter for running an individual statement
OPT_PARAM hint
SELECT /*+
OPT_PARAM('star_transformation_enabled„,'true') */ *
FROM …..
15
Things that you might not know about
• SQL
– Cause all statements to run without hints
_optimizer_ignore_hints=TRUE
– Extremely useful for testing
16
Things that you might not know about
• Optimizer Statistics
– Pending Statistics
– Separates stats collection from stats publishing
– Capture stats as Pending
– Test using pending stats
– Publish once verified
Pending Statistics
• Controlled by parameter
• optimizer_use_pending_statistics
• Determines if the optimizer will use pending statistics
• Set to false by default in 11gR1
• Set at session level for testing
• Use dbms_stats package
• set_table_prefs
• All tables preferences have “publish” set to true by default
• publish_private_stats
• Once stats have been tested publish them for general use
• Monitor
• Look at dictionary table user_*_pending_stats (* = tab, col, ind)
18
Things that you might not know about
• Optimizer Statistics
– Pending Statistics
– Separates stats collection from stats publishing
– Capture stats as Pending
– Test using pending stats
– Publish once verified
– Setting Statistics
– Use dbms_stats.set_*_stats
– Very useful for min/max values
– Be careful!
Setting Statistics
declare
minmax dbms_stats.numarray;
da dbms_stats.datearray;
sr dbms_stats.statrec;
begin
/* prepare min/max values */
/* date type column example */
da := dbms_stats.datearray
(to_date('01/01/1999','MM/DD/YYYY'),sysdate);
sr.epc := 2;
sr.bkvals := null;
dbms_stats.prepare_column_values(sr, da);
dbms_stats.set_column_stats('scott','emp','hiredate',srec=>sr);
end; /
AnalyticsSQL> select deptno,
2 listagg( ename, '; ' )
3 within group
4 (order by ename) enames
5 from emp
6 group by deptno
7 order by deptno
8 /
DEPTNO ENAMES
---------- --------------------
10 CLARK; KING; MILLER
20 ADAMS; FORD; JONES;
SCOTT; SMITH
30 ALLEN; BLAKE;
JAMES; MARTIN;
TURNER; WARD
Analytics
SQL> select deptno,
2 ename,
3 row_number()
4 over (partition by deptno
5 order by ename) rn,
6 first_value(ename)
7 over (partition by deptno
8 order by ename) "1st ename",
9 nth_value(ename,3)
10 over (partition by deptno
11 order by ename) "3rd ename",
12 last_value(ename)
13 over (partition by deptno
14 order by ename
15 rows between current row
16 and unbounded following) "last ename"
17 from emp
18 order by deptno, ename
19 /
Analytics
SQL> select deptno,
2 ename,
3 row_number()
4 over (partition by deptno
5 order by ename) rn,
6 first_value(ename)
7 over (partition by deptno
8 order by ename) "1st ename",
9 nth_value(ename,3)
10 over (partition by deptno
11 order by ename) "3rd ename",
12 last_value(ename)
13 over (partition by deptno
14 order by ename
15 rows between current row
16 and unbounded following) "last ename"
17 from emp
18 order by deptno, ename
19 /
DEPTNO ENAME RN 1st e 3rd ena last en
---------- -------- -- ----- ------- -------
10 CLARK 1 CLARK MILLER
KING 2 CLARK MILLER
MILLER 3 CLARK MILLER MILLER
20 ADAMS 1 ADAMS SMITH
FORD 2 ADAMS SMITH
JONES 3 ADAMS JONES SMITH
SCOTT 4 ADAMS JONES SMITH
SMITH 5 ADAMS JONES SMITH
30 ALLEN 1 ALLEN WARD
BLAKE 2 ALLEN WARD
JAMES 3 ALLEN JAMES WARD
MARTIN 4 ALLEN JAMES WARD
TURNER 5 ALLEN JAMES WARD
WARD 6 ALLEN JAMES WARD
Things that you might not know about
• External tables allow for a preprocessor
– Program is run when you SELECT from external table
– The „location‟ is passed to the script/executable
– The executable does whatever it wants and writes to stdout
– Stdout is treated as the input file
– Most common use: gzip
External Table PreprocessorSQL> CREATE TABLE EMP_ET
2 (
3 "EMPNO" NUMBER(4),
4 "ENAME" VARCHAR2(10),
5 "JOB" VARCHAR2(9),
6 "MGR" NUMBER(4),
7 "HIREDATE" DATE,
8 "SAL" NUMBER(7,2),
9 "COMM" NUMBER(7,2),
10 "DEPTNO" NUMBER(2)
11 )
12 ORGANIZATION external
13 ( TYPE oracle_loader
14 DEFAULT DIRECTORY load_dir
15 ACCESS PARAMETERS
16 ( RECORDS DELIMITED BY NEWLINE
17 preprocessor exec_dir:'run_gunzip.sh'
18 FIELDS TERMINATED BY "|" LDRTRIM
19 )
20 location ( 'emp.dat.gz')
21 )
22 /
Table created.
External Table Preprocessor
SQL> !file emp.dat.gz
emp.dat.gz: gzip compressed data, was "emp.dat", from Unix, last
modified: Wed Oct 7 12:48:53 2009
SQL> !cat run_gunzip.sh
#!/bin/bash
/usr/bin/gunzip -c $*
SQL> select empno, ename from emp_et where rownum <= 5;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
27
Things that you might not know about
• Other stuff
– Out of line upgrade
– Full install rather than upgrade of $ORACLE_HOME
– 11.2.0.2
28
Things that you might not know about
• Other stuff
– Connecting to a Hung Database
– Primarily to get diagnostic etc
Sqlplus –prelim / as sysdba
30
Things that you might not know about
• SQL
– Change number of SQL captured by AWR
dbms_workload_repository.modify_snapshot_settings
(topnsql=> 200)
31
Things that you might not know about
• SQL
– Always capture a statement even if not high load
dbms_workload_repository.add_colored_sql(:sql_id)
32
Things that you might not know about
• Reporting
– AWR SQL Report
– Report history of execution of a SQL statement
– Plans in use during different time periods
– AWR Diff Report
– Highlights differences between two periods of AWR data
– AWR RAC Report
– Reports on distribution of workload across instances
– ASH Report
– Any time period
– Instance or filtered
– Filtering at sessions level almost equivalent of SQL trace
33
Things that you might not know about
• Reporting
– AWR SQL Report
– Report history of execution of a SQL statement
– Plans in use during different time periods
– AWR Diff Report
– Highlights differences between two periods of AWR data
– AWR RAC Report
– Reports on distribution of workload across instances
– ASH Report
– Any time period
– Instance or filtered
– Filtering at sessions level almost equivalent of SQL trace
AND DON‟T FORGET THE ADDM REPORT!
Check Cardinality using SQL Monitor
SQL Monitor allows you to compare the estimated number of rows returned for each operation in the plan to actual rows returned
Things that you might not know about
• Dumping ASH to file
Sqlplus –prelim / as sysdba
>oradebug setmypid
>oradebug dump ashdump 10
>alter session set events 'immediate
trace name ashdump level 10';
• 10 ==> minutes of history you want to dump
• Generated file can be loaded into database (or Excel)
Things that you might not know about
• Dumping ASH to file (normal operation)
Sqlplus / as sysdba
>create table my_ash_data as select *
from v$active_session_history;
exp my_ash_data
• Load into another database
• Run custom queries