1SQL> define SRDCNAME='XDB_USAGE_CHECK'
2set pagesize 200 verify off sqlprompt "" term off entmap off echo off
3set markup html on spool on
4COLUMN SRDCSPOOLNAME NOPRINT NEW_VALUE SRDCSPOOLNAME
5select 'SRDC_'||upper('&&SRDCNAME')||'_'||upper(instance_name)||'_'||
6 to_char(sysdate,'YYYYMMDD_HH24MISS') SRDCSPOOLNAME from v$instance;
7spool &&SRDCSPOOLNAME..htm
8select 'Diagnostic-Name: ' || '&&SRDCNAME' as "SRDC COLLECTION HEADER" from dual
9union all
10select 'Time: ' || to_char(systimestamp, 'YYYY-MM-DD HH24MISS TZHTZM' ) from dual
11union all
12select 'Machine: ' || host_name from v$instance
13union all
14select 'Version: '|| version from v$instance
15union all
16select 'DBName: '||name from v$database
17union all
18select 'Instance: '||instance_name from v$instance
19/
20set serveroutput on
21alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'
22/
23
24define LOWTHRESHOLD=10
25define MIDTHRESHOLD=62
26define VERBOSE=TRUE
27
28set veri off;
29set feedback off;
30REM === -- end of standard header -- ===
31set lines 150 trimspool on pages 50000 long 100000 tab off
32set serveroutput on
33set HEADING on MARKUP html preformat off
34declare
35 --define cursors
36 --check for version
37 cursor c_ver is select version from v$instance;
38 --check for invalids owned by XDB
39 cursor c_inval is select * from dba_objects where status='INVALID' and OWNER in ('SYS','XDB');
40 -- Check status of other database features
41 cursor c_feat is select comp_name,status,version from dba_registry;
42 --check for xml type tables
43 cursor c_xml_tabs is select owner,storage_type,count(*) "TOTAL" from dba_xml_tables group by owner,storage_type;
44 --check for xml type colmns
45 cursor c_xml_tab_cols is select owner,storage_type,count(*) "TOTAL" from dba_xml_tab_cols group by owner,storage_type;
46 --check for xml type views
47 cursor c_xml_vw is select owner,count(*) "TOTAL" from dba_xml_views group by owner;
48 --check for xml type Indexes
49 cursor c_xml_idx is select index_owner,type,count(*) "TOTAL" from dba_xml_indexes group by index_owner,type;
50 --check for API's bbuilt with XML API's
51 cursor c_api is select owner,name,type from dba_dependencies where referenced_name in
52 (select object_name from dba_objects
53 where object_name like 'DBMS_XML%' or object_name like 'DBMS_XSL%')
54 and TYPE !='SYNONYM' and owner !='SYS';
55 --check for registered Schemas
56 cursor c_xml_schemas is select owner,count(*) "TOTAL" from dba_xml_schemas group by owner;
57 --check for user defined resources in the repository
58 cursor c_res is select distinct (a.username) "USER",count (r.xmldata) "TOTAL"
59 from dba_users a, xdb.xdb$resource r
60 where sys_op_rawtonum (extractvalue (value(r),'/Resource/OwnerID/text()')) =a.USER_ID group by a.username;
61 -- check xdbconfig.xml values
62 cursor c_config is select value(x).GETROOTELEMENT() NODENAME, extractValue(value(x),'/*') NODEVALUE
63 from table(xmlsequence(extract(xdburitype('/xdbconfig.xml').getXML(),'//*[text()]'))) x;
64 --check for Network ACLs
65 cursor c_net_acls is select host, nvl(trim(lower_port),'NULL') l_port, nvl(trim(upper_port),'NULL') u_port from dba_network_acls;
66 --define variables for fetching data from cursors
67 v_ver c_ver%ROWTYPE;
68 v_inval c_inval%ROWTYPE;
69 v_feat c_feat%ROWTYPE;
70 v_xml_tabs c_xml_tabs%ROWTYPE;
71 v_xml_tab_cols c_xml_tab_cols%ROWTYPE;
72 v_xml_vw c_xml_vw%rowtype;
73 v_xml_idx c_xml_idx%rowtype;
74 v_api c_api%rowtype;
75 v_c_net_acls c_net_acls%rowtype;
76 v_xml_schemas c_xml_schemas%rowtype;
77 v_res c_res%ROWTYPE;
78 v_config c_config%rowtype;
79 -- Static variables
80 v_errcode NUMBER := 0;
81 v_errmsg varchar2(50) := ' ';
82 l_dad_names DBMS_EPG.varchar2_table;
83 --stylesheet for xdbconfig.xml reading
84 v_style clob :='';
85begin
86 open c_ver;
87 fetch c_ver into v_ver;
88 --check minimum XDB requirements
89 if v_ver.version like '9.%' or v_ver.version like '10.%' then
90 DBMS_OUTPUT.PUT_LINE('!!!!!!!!!!!!! UNSUPPORTED VERSION !!!!!!!!!!!!!');
91 DBMS_OUTPUT.PUT_LINE('Minimun version is 11.2.0.4. actual version is: '||v_ver.version);
92 end if;
93 DBMS_OUTPUT.PUT_LINE('############# Status/Version #############');
94 DBMS_OUTPUT.PUT_LINE('XDB Status is: '||dbms_registry.status('XDB')||' at version '||dbms_registry.version('XDB'));
95 if v_ver.version != dbms_registry.version('XDB') then
96 DBMS_OUTPUT.PUT_LINE('Database is at version '||v_ver.version||' XDB is at version '||dbms_registry.version('XDB'));
97 end if;
98 --Check Status. If invalid, gather invalid objects list and check for usage. If valid, simply check for usage
99 if dbms_registry.status('XDB') != 'VALID' then
100 DBMS_OUTPUT.PUT_LINE('############# Invalid Objects #############');
101 open c_inval;
102 loop
103 fetch c_inval into v_inval;
104 DBMS_OUTPUT.PUT_LINE('Type: '||v_inval.object_type||' '||v_inval.owner||'.'||v_inval.object_name);
105 exit when c_inval%NOTFOUND;
106 end loop;
107 close c_inval;
108 end if;
109 -- Check XDBCONFIG.XML paramareters
110 DBMS_OUTPUT.PUT_LINE('############# OTHER DATABASE FEATURES #############');
111 open c_feat;
112 loop
113 fetch c_feat into v_feat;
114 exit when c_feat%NOTFOUND;
115 if c_feat%rowcount >0 then
116 DBMS_OUTPUT.PUT_LINE(v_feat.comp_name||' is '||v_feat.status||' at version '||v_feat.version);
117 else DBMS_OUTPUT.PUT_LINE('No Data Found');
118 end if;
119 end loop;
120 close c_feat;
121 -- Check XDBCONFIG.XML paramareters
122 DBMS_OUTPUT.PUT_LINE('############# XDBCONFIG INFORMATION #############');
123 open c_config;
124 loop
125 fetch c_config into v_config;
126 exit when c_config%NOTFOUND;
127 if c_config%rowcount >0 then
128 DBMS_OUTPUT.PUT_LINE(v_config.NODENAME||'= = = '||v_config.NODEVALUE);
129 else DBMS_OUTPUT.PUT_LINE('No Data Found');
130 end if;
131 end loop;
132 close c_config;
133 -- Check if they have any xmltype tables or columns and if they are schema based, clob or binary
134 DBMS_OUTPUT.PUT_LINE('############# XMLTYPE Tables #############');
135 open c_xml_tabs;
136 loop
137 fetch c_xml_tabs into v_xml_tabs;
138 exit when c_xml_tabs%NOTFOUND;
139 DBMS_OUTPUT.PUT_LINE(v_xml_tabs.owner||' has '||v_xml_tabs.TOTAL||' XMLTYPE TABLES stored as '||v_xml_tabs.storage_type);
140 end loop;
141 close c_xml_tabs;
142 DBMS_OUTPUT.PUT_LINE('############# XMLTYPE Columns #############');
143 open c_xml_tab_cols;
144 loop
145 fetch c_xml_tab_cols into v_xml_tab_cols;
146 exit when c_xml_tab_cols%NOTFOUND;
147 if c_xml_tab_cols%rowcount > 0 then
148 DBMS_OUTPUT.PUT_LINE(v_xml_tab_cols.owner||' has '||v_xml_tab_cols.TOTAL||' XMLTYPE Columns stored as ' ||v_xml_tab_cols.storage_type);
149 else DBMS_OUTPUT.PUT_LINE('No Data Found');
150 end if;
151 end loop;
152 close c_xml_tab_cols;
153 DBMS_OUTPUT.PUT_LINE('############# XMLTYPE Views #############');
154 open c_xml_vw;
155 loop
156 fetch c_xml_vw into v_xml_vw;
157 exit when c_xml_vw%NOTFOUND;
158 if c_xml_vw%rowcount > 0 then
159 DBMS_OUTPUT.PUT_LINE(v_xml_vw.owner||' has '||v_xml_vw.TOTAL||' XMLTYPE Views');
160 else DBMS_OUTPUT.PUT_LINE('No Data Found');
161 end if;
162 end loop;
163 close c_xml_vw;
164 DBMS_OUTPUT.PUT_LINE('############# XMLTYPE INDEXES #############');
165 open c_xml_idx;
166 loop
167 fetch c_xml_idx into v_xml_idx;
168 exit when c_xml_idx%NOTFOUND;
169 if c_xml_idx%rowcount > 0 then
170 DBMS_OUTPUT.PUT_LINE(v_xml_idx.index_owner||' has '||v_xml_idx.TOTAL||' XMLTYPE Indexes of type '||v_xml_idx.type);
171 else DBMS_OUTPUT.PUT_LINE('No Data Found');
172 end if;
173 end loop;
174 close c_xml_idx;
175 DBMS_OUTPUT.PUT_LINE('############# Items built with XML API''s #############');
176 open c_api;
177 loop
178 fetch c_api into v_api;
179 exit when c_api%NOTFOUND;
180 if c_api%rowcount > 0 then
181 DBMS_OUTPUT.PUT_LINE(v_api.type||' '||v_api.owner||'.'||v_api.name);
182 else DBMS_OUTPUT.PUT_LINE('No Data Found');
183 end if;
184 end loop;
185 close c_api;
186 DBMS_OUTPUT.PUT_LINE('############# XML SCHEMAS #############');
187 open c_xml_schemas;
188 loop
189 fetch c_xml_schemas into v_xml_schemas;
190 exit when c_xml_schemas%NOTFOUND;
191 if c_xml_schemas%rowcount >0 then
192 DBMS_OUTPUT.PUT_LINE(v_xml_schemas.owner||' has '||v_xml_schemas.TOTAL||' registered.');
193 else DBMS_OUTPUT.PUT_LINE('No Data Found');
194 end if;
195 end loop;
196 close c_xml_schemas;
197 -- Check for repository resources
198 DBMS_OUTPUT.PUT_LINE('############# Repository Resources #############');
199 open c_res;
200 loop
201 fetch c_res into v_res;
202 exit when c_res%NOTFOUND;
203 if c_res%rowcount >0 then
204 DBMS_OUTPUT.PUT_LINE(v_res.USER||' has '||v_res.TOTAL||' resources.');
205 else DBMS_OUTPUT.PUT_LINE('No Data Found');
206 end if;
207 end loop;
208 close c_res;
209 -- Check Network ACLS
210 DBMS_OUTPUT.PUT_LINE('############# Network ACLs Configured #############');
211 open c_net_acls;
212 loop
213 fetch c_net_acls into v_c_net_acls;
214 if c_net_acls%rowcount >0 then
215 DBMS_OUTPUT.PUT_LINE(v_c_net_acls.host||' has network acls configured for ports '||v_c_net_acls.l_port||' through '|| v_c_net_acls.u_port);
216 else DBMS_OUTPUT.PUT_LINE('No Data Found');
217 end if;
218 exit when c_net_acls%NOTFOUND;
219 end loop;
220 close c_net_acls;
221 --Check DAD configuration to see if DBMS_EPG is being used
222 DBMS_OUTPUT.put_line('############# DBMS_EPG DAD USAGE #############');
223 DBMS_EPG.GET_DAD_LIST (l_dad_names);
224 FOR i IN 1 .. l_dad_names.count LOOP
225 DBMS_OUTPUT.put_line(l_dad_names(i));
226 END LOOP;
227 close c_ver;
228EXCEPTION
229WHEN no_data_found THEN
230 DBMS_OUTPUT.PUT_LINE('No Data Found');
231WHEN others THEN
232 v_errcode := sqlcode;
233 v_errmsg := SUBSTR(sqlerrm, 1, 50);
234 DBMS_OUTPUT.PUT_LINE('ERROR: '||v_errcode||': ' || v_errmsg);
235end;
236/
237--End XDB health and usage check
238SET SERVEROUTPUT OFF
239Rem===========================================================================================================================================
240spool off
241set markup html off spool off
242set sqlprompt "SQL> " term on echo off
243PROMPT
244PROMPT
245PROMPT REPORT GENERATED : &SRDCSPOOLNAME..htm
246set verify on echo on
247Rem===========================================================================================================================================
248exit;