Documente Academic
Documente Profesional
Documente Cultură
log;
SET DEF ON TERM OFF ECHO ON;
CL TIMI;
REM
REM $Header: coe_siebel_profile.sql 11.2 2010/11/19 csierra $
REM
REM Copyright (c) 1990-2010, Oracle. All rights reserved.
REM
REM The Programs (which include both the software and documentation) contain
REM proprietary information; they are provided under a license agreement contain
ing
REM restrictions on use and disclosure and are also protected by copyright, pate
nt,
REM and other intellectual and industrial property laws. Reverse engineering,
REM disassembly, or decompilation of the Programs, except to the extent required
to
REM obtain interoperability with other independently created software or as spec
ified
REM by law, is prohibited.
REM
REM Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of
REM Oracle Corporation and/or its affiliates. Other names may be trademarks
REM of their respective owners.
REM
REM If you have received this software in error, please notify Oracle Corporatio
n
REM immediately at 1.800.ORACLE1.
REM
REM AUTHOR
REM carlos.sierra@oracle.com
REM
REM SCRIPT
REM coe_siebel_profile.sql
REM
REM DESCRIPTION
REM Collects schema object details for Siebel on 10g and 11g.
REM
REM PARAMETERS
REM 1. Proces Type: (N)ormal or (E)xpert. Default N.
REM 2. Schema Owner: Default SIEBEL.
REM 3. Repository Name: Default Siebel Repository.
REM
REM EXECUTION
REM 1. Connect into SQL*Plus as SYSDBA.
REM 2. Execute this script with or without inline parameters.
REM
REM EXAMPLE
REM # sqlplus / as sysdba
REM SQL> START coe_siebel_profile.sql N SIEBEL Siebel_Repository
REM or
REM SQL> START coe_siebel_profile.sql
REM
REM NOTES
REM 1. Expert process type should only by used by Expert Services.
REM 2. Please notice that when passing parameters inline
REM
spaces must be converted to underscore, for example
REM
"Siebel Repository" is passed as "Siebel_Repository".
REM
-- default parameters
DEF default_schema_owner = 'SIEBEL';
END IF;
END;
/
SET TERM ON VER OFF;
SELECT name repository_name FROM &&schema_owner..s_repository;
PRO Parameter 3:
PRO Repository Name: Default "Siebel Repository".
PRO
DEF repository_name = '&3';
PRO
PRO wait...
SET TERM OFF VER ON;
-- prepares parameters
VAR repository_name VARCHAR2(75);
VAR repository_id VARCHAR2(15);
EXEC :repository_name := REPLACE(UPPER(NVL(TRIM(' ' FROM '&&repository_name.'),
'&&default_repository.')), '_', ' ');
PRINT repository_name;
-- validates repository name
BEGIN
SELECT row_id INTO :repository_id FROM &&schema_owner..s_repository WHERE REPL
ACE(UPPER(name), '_', ' ') = :repository_name;
END;
/
PRINT repository_id;
COL repository_id NEW_V repository_id;
SELECT :repository_id repository_id FROM DUAL;
-- validates this is 10g or 11g
VAR rdbms_version VARCHAR2(17);
VAR rdbms_release NUMBER;
DECLARE
dot1 NUMBER;
dot2 NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT version FROM v$instance' INTO :rdbms_version;
dot1 := INSTR(:rdbms_version, '.');
dot2 := INSTR(:rdbms_version, '.', dot1 + 1);
:rdbms_release :=
TO_NUMBER(SUBSTR(:rdbms_version, 1, dot1 - 1)) +
(TO_NUMBER(SUBSTR(:rdbms_version, dot1 + 1, dot2 - dot1 - 1)) / POWER(10, (dot
2 - dot1 - 1)));
IF :rdbms_release < 10 THEN
RAISE_APPLICATION_ERROR(-20200, 'Use on 10g or higher, not in '||:rdbms_rele
ase);
END IF;
END;
/
PRINT rdbms_release;
PRINT rdbms_version;
WHENEVER SQLERROR CONTINUE;
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ".,";
/********************************* create temp tables **************************
*******/
WHERE
AND
AND
AND
AND
AND
AND
&&schema_owner..s_index si
i.table_owner = '&&schema_owner.'
i.index_type NOT IN ('DOMAIN', 'LOB', 'FUNCTION-BASED DOMAIN')
i.table_name = st.table_name
st.tbl_id = si.tbl_id
i.index_name = si.name
si.repository_id = '&&repository_id.'
si.stat_cd = '&&default_stat_cd.';
CASE
WHEN t.num_rows < 16 THEN '<16'
WHEN t.num_rows BETWEEN 16 AND 1e2 THEN '16-100'
WHEN t.num_rows BETWEEN 1e2 AND 1e3 THEN '100-1000'
WHEN t.num_rows BETWEEN 1e3 AND 1e4 THEN '1K-10K'
WHEN t.num_rows BETWEEN 1e4 AND 1e5 THEN '10K-100K'
WHEN t.num_rows BETWEEN 1e5 AND 1e6 THEN '100K-1M'
WHEN t.num_rows BETWEEN 1e6 AND 1e7 THEN '1M-10M'
WHEN t.num_rows BETWEEN 1e7 AND 1e8 THEN '10M-100M'
WHEN t.num_rows BETWEEN 1e8 AND 1e9 THEN '100M-1B'
WHEN t.num_rows > 1e9 THEN '>1B'
ELSE 'UNKNOWN' END table_size,
DECODE(NVL(i.indexes_count, 0), 0, 'NO', 'YES') indexed,
i.indexes_count,
t.*
FROM &&schema_owner..siebel_tables t,
(SELECT table_name, COUNT(*) indexes_count
FROM &&schema_owner..siebel_indexes
GROUP BY
table_name) i
WHERE t.table_name = i.table_name(+);
CREATE OR REPLACE VIEW &&schema_owner..siebel_indexes_v AS
SELECT t.table_stats,
t.table_size,
DECODE(i.last_analyzed, NULL, 'NO', 'YES') index_stats,
ROUND(SYSDATE - i.last_analyzed) stats_age_days,
i.*,
ic.columns,
ic1.column_name column1,
ic2.column_name column2,
ic3.column_name column3,
ic4.column_name column4,
ic5.column_name column5,
ic6.column_name column6
FROM &&schema_owner..siebel_indexes i,
&&schema_owner..siebel_tables_v t,
(SELECT index_name, COUNT(*) columns
FROM &&schema_owner..siebel_ind_columns
GROUP BY index_name ) ic,
(SELECT index_name, SUBSTR(column_name||DECODE(descend,
, 1, 40) column_name
FROM &&schema_owner..siebel_ind_columns
WHERE column_position = 1 ) ic1,
(SELECT index_name, SUBSTR(column_name||DECODE(descend,
, 1, 40) column_name
FROM &&schema_owner..siebel_ind_columns
WHERE column_position = 2 ) ic2,
(SELECT index_name, SUBSTR(column_name||DECODE(descend,
, 1, 40) column_name
FROM &&schema_owner..siebel_ind_columns
WHERE column_position = 3 ) ic3,
(SELECT index_name, SUBSTR(column_name||DECODE(descend,
, 1, 40) column_name
FROM &&schema_owner..siebel_ind_columns
WHERE column_position = 4 ) ic4,
(SELECT index_name, SUBSTR(column_name||DECODE(descend,
, 1, 40) column_name
FROM &&schema_owner..siebel_ind_columns
WHERE column_position = 5 ) ic5,
'DESC', '(DESC)')
'DESC', '(DESC)')
'DESC', '(DESC)')
'DESC', '(DESC)')
'DESC', '(DESC)')
tc.global_stats,
tc.hidden_column,
tc.table_size,
tc.table_num_rows,
tc.indexes,
tc.predicates,
tc.equality_preds,
tc.equijoin_preds,
tc.nonequijoin_preds,
tc.range_preds,
tc.like_preds,
tc.null_preds,
tc.timestamp
FROM &&schema_owner..siebel_ind_columns ic,
&&schema_owner..siebel_tab_cols_v tc
WHERE ic.table_name = tc.table_name
AND ic.column_name = tc.column_name;
/********************************* counts *********************************/
SET ECHO OFF VER OFF FEED OFF PAGES 50000 LIN 2000 TRIMS ON;
SPO &&schema_owner._&¤t_time._S_profile_cols_with_no_index.txt;
PRO Columns with no index
PRO ~~~~~~~~~~~~~~~~~~~~~
PRO Complete list of non-indexed columns referenced by at least one SQL predicat
e.
SELECT
FROM
WHERE
AND
ORDER
SPO OFF;
SPO &&schema_owner._&¤t_time._S_profile_summary.txt;
PRO Top &&default_col_count. columns in need of an index
PRO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRO Partial list of non-indexed columns referenced by at least one SQL predicate
.
SELECT
SELECT
FROM
WHERE
AND
ORDER
* FROM (
predicates, table_name, column_name
&&schema_owner..siebel_tab_cols_v
col_in_predicates = 'YES'
col_in_indexes = 'NO'
BY
predicates DESC,
table_name,
column_name )
WHERE ROWNUM <= &&default_col_count.;
Tables
~~~~~~
Count and rollup of tables grouped by the following 3 attributes:
1. Table has CBO statistics. 2. Statistics are locked. 3. Statistics are sta
ORDER BY
DECODE(table_size,
'UNKNOWN', 0,
'<16', 1,
'16-100', 2,
'100-1000', 3,
'1K-10K', 4,
'10K-100K', 5,
'100K-1M', 6,
'1M-10M', 7,
'10M-100M', 8,
'100M-1B', 9,
'>1B', 10) NULLS LAST,
stats_age_days NULLS LAST;
COL indexes FOR 9999999;
COL table_size FOR A10;
COL index_stats FOR A11;
PRO
PRO Indexes
PRO ~~~~~~~
PRO Count and rollup of indexes grouped by the following 2 attributes:
PRO 1. Corresponding table size according to number of rows. 2. Index has CBO st
atistics.
SELECT COUNT(*) indexes,
table_size,
index_stats
FROM &&schema_owner..siebel_indexes_v
GROUP BY
ROLLUP(table_size, index_stats)
ORDER BY
DECODE(table_size,
'UNKNOWN', 0,
'<16', 1,
'16-100', 2,
'100-1000', 3,
'1K-10K', 4,
'10K-100K', 5,
'100K-1M', 6,
'1M-10M', 7,
'10M-100M', 8,
'100M-1B', 9,
'>1B', 10) NULLS LAST,
index_stats NULLS LAST;
COL indexes FOR 9999999;
COL table_size FOR A10;
COL stats_age_days FOR 99999999999999;
PRO
PRO Count and rollup of indexes grouped by the following 2 attributes:
PRO 1. Corresponding table size according to number of rows. 2. Age of index CBO
statistics in days.
SELECT COUNT(*) indexes,
table_size,
stats_age_days
FROM &&schema_owner..siebel_indexes_v
PRO
PRO Columns
PRO ~~~~~~~
PRO Count and rollup of columns grouped by the following 5 attributes:
PRO 1. Corresponding table has CBO statistics. 2. Column is referenced by at lea
st one SQL predicate.
PRO 3. Column exists in at least an index. 4. Column has CBO statistics. 5. Colu
mn has a histogram.
SELECT COUNT(*) columns,
table_stats, col_in_predicates, col_in_indexes, col_stats, col_histogram
FROM &&schema_owner..siebel_tab_cols_v
GROUP BY
ROLLUP(table_stats, col_in_predicates, col_in_indexes, col_stats, col_his
togram)
ORDER BY
table_stats DESC NULLS LAST,
col_in_predicates DESC NULLS LAST,
col_in_indexes DESC NULLS LAST,
col_stats DESC NULLS LAST,
col_histogram DESC NULLS LAST;
COL columns FOR 9999999;
COL stats_age_days FOR 99999999999999;
COL table_size FOR A10;
PRO
PRO Count and rollup of columns grouped by the following 2 attributes:
PRO 1. Corresponding table size according to number of rows. 2. Age of column CB
O statistics in days.
SELECT COUNT(*) columns,
table_size,
stats_age_days
FROM &&schema_owner..siebel_tab_cols_v
SPO &&schema_owner._&¤t_time._&&process_type._profile_tables.csv;
SELECT table_name,
table_size,
num_rows,
blocks,
table_stats,
stats_age_days,
TO_CHAR(last_analyzed, 'YYYY/MM/DD HH24:MI:SS') last_analyzed,
sample_size,
avg_row_len,
indexes_count,
degree,
partitioned,
temporary,
global_stats,
stattype_locked,
stale_stats,
inserts,
updates,
deletes,
TO_CHAR(timestamp, 'YYYY/MM/DD HH24:MI:SS') timestamp
FROM &&schema_owner..siebel_tables_v
WHERE :process_type = 'E'
ORDER BY
table_name;
SPO OFF;
COL
COL
COL
COL
COL
COL
COL
SPO &&schema_owner._&¤t_time._&&process_type._profile_indexes.csv;
SELECT owner,
index_name,
index_type,
table_name,
table_size,
uniqueness,
blevel,
num_rows,
leaf_blocks,
index_stats,
stats_age_days,
TO_CHAR(last_analyzed, 'YYYY/MM/DD HH24:MI:SS') last_analyzed,
sample_size,
distinct_keys,
avg_leaf_blocks_per_key,
avg_data_blocks_per_key,
clustering_factor,
degree,
partitioned,
temporary,
global_stats,
columns,
column1,
column2,
column3,
column4,
column5,
column6
FROM &&schema_owner..siebel_indexes_v
WHERE :process_type = 'E'
ORDER BY
owner,
index_name;
SPO OFF;
COL
COL
COL
COL
COL
COL
COL
SPO &&schema_owner._&¤t_time._&&process_type._profile_tab_cols.csv;
SELECT table_name,
table_size,
column_id,
column_name,
col_stats,
stats_age_days,
TO_CHAR(last_analyzed, 'YYYY/MM/DD HH24:MI:SS') last_analyzed,
sample_size,
num_nulls,
num_distinct,
num_buckets,
density,
col_histogram,
histogram,
avg_col_len,
global_stats,
hidden_column,
col_in_predicates,
col_in_indexes,
table_num_rows,
indexes,
predicates,
equality_preds,
equijoin_preds,
nonequijoin_preds,
range_preds,
like_preds,
null_preds,
TO_CHAR(timestamp, 'YYYY/MM/DD HH24:MI:SS') timestamp
FROM &&schema_owner..siebel_tab_cols_v
WHERE :process_type = 'E'
ORDER BY
table_name,
column_id NULLS LAST,
column_name;
SPO OFF;
COL
COL
COL
COL
COL
COL
COL
COL
SPO &&schema_owner._&¤t_time._&&process_type._profile_ind_cols.csv;
SELECT table_name,
index_name,
column_position,
column_name,
descend,
col_in_predicates,
col_stats,
col_histogram,
stats_age_days,
TO_CHAR(last_analyzed, 'YYYY/MM/DD HH24:MI:SS') last_analyzed,
sample_size,
num_nulls,
num_distinct,
num_buckets,
density,
histogram,
avg_col_len,
global_stats,
hidden_column,
table_size,
table_num_rows,
indexes,
predicates,
equality_preds,
equijoin_preds,
nonequijoin_preds,
range_preds,
like_preds,
null_preds,
TO_CHAR(timestamp, 'YYYY/MM/DD HH24:MI:SS') timestamp
FROM &&schema_owner..siebel_ind_cols_v
WHERE :process_type = 'E'
ORDER BY
table_name,
index_name,
column_position;
SPO OFF;
/********************************* zip *********************************/
HOS zip -m &&schema_owner._&¤t_time._profile coe_siebel_profile.log &&sche
ma_owner._&¤t_time.*
HOS zip -d &&schema_owner._&¤t_time._profile &&schema_owner._&¤t_tim
e._N*
/********************************* drop temp objects ***************************
******/
DROP
DROP
DROP
DROP
DROP
DROP
DROP
DROP
DROP
VIEW &&schema_owner..siebel_ind_cols_v;
VIEW &&schema_owner..siebel_tab_cols_v;
VIEW &&schema_owner..siebel_indexes_v;
VIEW &&schema_owner..siebel_tables_v;
TABLE &&schema_owner..siebel_col_usage;
TABLE &&schema_owner..siebel_ind_columns;
TABLE &&schema_owner..siebel_indexes;
TABLE &&schema_owner..siebel_tab_cols;
TABLE &&schema_owner..siebel_tables;