DBAFUSExtract.sql 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. SET ECHO OFF
  2. SET PAUSE OFF
  3. SET TERMOUT OFF
  4. REM ORACLE - Global Licensing and Advisory Services - DBA_FEATURE_USAGE_STATISTICS Extract Script
  5. REM
  6. REM Prerequisites:
  7. REM - path separator (/ or \) has already been set into PSEP variable (by db_conn_coll_main.sql)
  8. REM
  9. REM
  10. REM Change History
  11. REM ---------------------------------
  12. REM Date Release Author
  13. REM ----------- ------- ---------------
  14. REM 2017-03-12 17.2 sserban
  15. REM 2018-09-06 19.1 cpanait
  16. define SCRIPT_RELEASE=19.1
  17. SET DEFINE ON
  18. SET MARKUP HTML OFF
  19. SET COLSEP ' '
  20. -- Settings for customized functionality - the last definition of each parameter will dictate the customization
  21. -- Set SCRIPT_TS to generate filenames with or without timestamp
  22. define SCRIPT_TS=_TS_IGNORE_THIS_ERR -- include timestamp in names of the output directory and output files: YYYY.MM.DD.HH24.MI.SS
  23. define SCRIPT_TS='' -- standard names for output directory and output files [default behavior]
  24. -- Set SCRIPT_SD to create output subdirectory
  25. define SCRIPT_SD='' -- no output subdirectory
  26. define SCRIPT_SD=DBA_FUS -- create output subdirectory
  27. SET TERMOUT ON
  28. alter session set NLS_LANGUAGE='AMERICAN';
  29. alter session set NLS_TERRITORY='AMERICA';
  30. alter session set NLS_DATE_FORMAT='YYYY-MM-DD_HH24:MI:SS';
  31. alter session set NLS_TIMESTAMP_FORMAT='YYYY-MM-DD_HH24:MI:SS';
  32. alter session set NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD_HH24:MI:SS_TZH:TZM';
  33. SET TERMOUT OFF
  34. SET TAB OFF
  35. SET TRIMOUT ON
  36. SET TRIMSPOOL ON
  37. SET PAGESIZE 5000
  38. SET LINESIZE 300
  39. SET SERVEROUTPUT ON
  40. col DESCRIPTION format A65 wrap
  41. -- Get SYSDATE
  42. define SYSDATE_START=UNKNOWN
  43. col C0 new_val SYSDATE_START
  44. select SYSDATE C0 from dual;
  45. -- Get host_name and instance_name
  46. prompt Getting HOST_NAME and INSTANCE_NAME ...
  47. define INSTANCE_NAME=UNKNOWN
  48. define HOST_NAME=UNKNOWN
  49. col C1 new_val INSTANCE_NAME
  50. col C2 new_val HOST_NAME
  51. -- Oracle7
  52. SELECT min(machine) C2 FROM v$session WHERE type = 'BACKGROUND';
  53. SELECT name C1 FROM v$database;
  54. -- Oracle8 and higher
  55. SELECT instance_name C1, host_name C2 FROM v$instance;
  56. -- Oracle12 and higher
  57. SELECT '&&INSTANCE_NAME' || decode(value, 'TRUE', '~' || replace(sys_context('USERENV', 'CON_NAME'), '$', '_'), '') C1
  58. from v$parameter where name = 'enable_pluggable_database';
  59. define OUTPUT_PATH=***
  60. col C3 new_val OUTPUT_PATH
  61. select '&&HOST_NAME._&&INSTANCE_NAME.' ||
  62. decode('&SCRIPT_TS', null, null, '_'||to_char(to_date('&SYSDATE_START', 'YYYY-MM-DD_HH24:MI:SS'), 'YYYY.MM.DD.HH24.MI.SS')) C3 from DUAL;
  63. define GREP_PREFIX=***
  64. col C4 new_val GREP_PREFIX noprint
  65. SELECT 'GREP'||'ME>>,&&HOST_NAME.,&&INSTANCE_NAME.,' || '&SYSDATE_START' || ',&&HOST_NAME.,' || name as C4 FROM v$database;
  66. --{
  67. --Detect SQL*Plus client path separator
  68. --Using some Unix/Linux specific syntax
  69. host echo select \'$PWD\' as PWD_, \'rm\' as RMDEL_, \'/\' as PSEP_ from dual where \'$PWD\' like \'%/%\'\; > psep.sql 2> fii_err.txt
  70. define PWD=*
  71. define RMDEL=del
  72. define PSEP=\
  73. col PWD_ new_val PWD noprint
  74. col RMDEL_ new_val RMDEL noprint
  75. col PSEP_ new_val PSEP noprint
  76. -- The query syntax is correct only on Unix/Linux
  77. @psep.sql
  78. -- Cleanup
  79. host &RMDEL psep.sql 2> fii_err.txt
  80. --}
  81. HOST mkdir &SCRIPT_SD 2> fii_err.txt
  82. define OUTPUT_PATH_SD=***
  83. col C3 new_val OUTPUT_PATH_SD
  84. select decode('&&SCRIPT_SD', null, '&&OUTPUT_PATH', '&&SCRIPT_SD&&PSEP&&OUTPUT_PATH') C3 from DUAL;
  85. HOST mkdir &&OUTPUT_PATH_SD
  86. col C3 new_val OUTPUT_PATH
  87. select decode(instr('&&OUTPUT_PATH_SD', '&&PSEP', -1),
  88. length('&&OUTPUT_PATH_SD'), '&&OUTPUT_PATH_SD', -- if terminated by path separator, do not prefix the files
  89. '&&OUTPUT_PATH_SD&&PSEP&&OUTPUT_PATH._') as C3
  90. from dual;
  91. col C3 clear
  92. SET TERMOUT ON
  93. SET VERIFY OFF
  94. PROMPT ***** Collecting DBA_FEATURE_USAGE_STATISTICS information ... *****
  95. spool &&OUTPUT_PATH.dbafus.csv
  96. SET HEADING OFF
  97. SET FEEDBACK OFF
  98. SET LINESIZE 1500
  99. prompt &&GREP_PREFIX.,DBAFUS_EXTRACT,VERSION,,,&SCRIPT_RELEASE.,
  100. -- 10g DBA_FEATURE_USAGE_STATISTICS (10g and higher)
  101. ----------------------------------------------------
  102. define OPTION_NAME=DBA_FEATURE_USAGE_STATISTICS
  103. define OPTION_QUERY=10g
  104. define OPTION_QUERY_COLS=DBID,NAME,VERSION,DETECTED_USAGES,TOTAL_SAMPLES,CURRENTLY_USED,FIRST_USAGE_DATE,LAST_USAGE_DATE,AUX_COUNT,FEATURE_INFO,LAST_SAMPLE_DATE,LAST_SAMPLE_PERIOD,SAMPLE_INTERVAL
  105. define OCOUNT=-942
  106. col OCOUNT new_val OCOUNT noprint
  107. select ltrim(rtrim(to_char(count(*)))) as OCOUNT
  108. FROM DBA_FEATURE_USAGE_STATISTICS;
  109. select '&&GREP_PREFIX.,&OPTION_NAME.~HEADER,&OPTION_QUERY.~HEADER,&&OCOUNT.,count,&OPTION_QUERY_COLS.,'
  110. from dual where &&OCOUNT. > 0;
  111. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,count,'||
  112. DBID || ',"'||
  113. NAME || '","'||
  114. VERSION || '",' ||
  115. DETECTED_USAGES || ',' ||
  116. TOTAL_SAMPLES || ',"'||
  117. CURRENTLY_USED || '",' ||
  118. FIRST_USAGE_DATE || ',' ||
  119. LAST_USAGE_DATE || ',' ||
  120. AUX_COUNT || ',"'||
  121. replace(replace(replace(to_char(substr(FEATURE_INFO, 1, 1000)), chr(10), '[LF]'), chr(13), '[CR]'),'"','''') || '",' ||
  122. LAST_SAMPLE_DATE || ',' ||
  123. LAST_SAMPLE_PERIOD || ',' ||
  124. SAMPLE_INTERVAL || ','
  125. FROM DBA_FEATURE_USAGE_STATISTICS;
  126. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,'||
  127. decode(&&OCOUNT., 0, 'count,', '"ORA-00942: table or view does not exist",')
  128. from dual where &&OCOUNT. in (-942, 0);
  129. -- DBA_REGISTRY (9i_r2 and higher)
  130. ----------------------------------
  131. define OPTION_NAME=DBA_REGISTRY
  132. define OPTION_QUERY=>=9i_r2
  133. define OPTION_QUERY_COLS=COMP_NAME,VERSION,STATUS,MODIFIED,SCHEMA
  134. define OCOUNT=-942
  135. col OCOUNT new_val OCOUNT noprint
  136. select ltrim(rtrim(to_char(count(*)))) as OCOUNT
  137. from DBA_REGISTRY;
  138. select '&&GREP_PREFIX.,&OPTION_NAME.~HEADER,&OPTION_QUERY.~HEADER,&&OCOUNT.,count,&OPTION_QUERY_COLS.,'
  139. from dual where &&OCOUNT. > 0;
  140. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,count,'||
  141. '"' || COMP_NAME || '",' || VERSION || ',' || STATUS || ',' || MODIFIED || ',' || SCHEMA || ','
  142. from DBA_REGISTRY;
  143. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,'||
  144. decode(&&OCOUNT., 0, 'count,', '"ORA-00942: table or view does not exist",')
  145. from dual where &&OCOUNT. in (-942, 0);
  146. -- GV$PARAMETER
  147. --------------------------------------------
  148. define OPTION_NAME=GV$PARAMETER
  149. define OPTION_QUERY=NULL
  150. define OCOUNT=-942
  151. col OCOUNT new_val OCOUNT noprint
  152. select ltrim(rtrim(to_char(count(*)))) as OCOUNT
  153. from GV$PARAMETER
  154. where upper(NAME) like '%CPU_COUNT%'
  155. or upper(NAME) like '%FAL_CLIENT%'
  156. or upper(NAME) like '%FAL_SERVER%'
  157. or upper(NAME) like '%CLUSTER%'
  158. or upper(NAME) like '%CONTROL_MANAGEMENT_PACK_ACCESS%'
  159. or upper(NAME) like '%ENABLE_DDL_LOGGING%'
  160. or upper(NAME) like '%COMPATIBLE%'
  161. or upper(NAME) like '%LOG_ARCHIVE_DEST%'
  162. or upper(NAME) like '%O7_DICTIONARY_ACCESSIBILITY%' -- for troubleshooting access privileges issues
  163. or upper(NAME) like '%ENABLE_PLUGGABLE_DATABASE%'
  164. or upper(NAME) like '%INMEMORY%'
  165. or upper(NAME) like '%DB_UNIQUE_NAME%'
  166. or upper(NAME) like '%LOG_ARCHIVE_CONFIG%'
  167. or upper(NAME) like '%HEAT_MAP%'
  168. ;
  169. SET LINESIZE 5000
  170. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,count,"'||
  171. INST_ID ||'","'||
  172. NAME ||'","'||
  173. replace(VALUE,'"','''') ||'","'||
  174. ISDEFAULT ||'","'||
  175. DESCRIPTION ||'",'
  176. from GV$PARAMETER
  177. where upper(NAME) like '%CPU_COUNT%'
  178. or upper(NAME) like '%FAL_CLIENT%'
  179. or upper(NAME) like '%FAL_SERVER%'
  180. or upper(NAME) like '%CLUSTER%'
  181. or upper(NAME) like '%CONTROL_MANAGEMENT_PACK_ACCESS%'
  182. or upper(NAME) like '%ENABLE_DDL_LOGGING%'
  183. or upper(NAME) like '%COMPATIBLE%'
  184. or upper(NAME) like '%LOG_ARCHIVE_DEST%'
  185. or upper(NAME) like '%O7_DICTIONARY_ACCESSIBILITY%' -- for troubleshooting access privileges issues
  186. or upper(NAME) like '%ENABLE_PLUGGABLE_DATABASE%'
  187. or upper(NAME) like '%INMEMORY%'
  188. or upper(NAME) like '%DB_UNIQUE_NAME%'
  189. or upper(NAME) like '%LOG_ARCHIVE_CONFIG%'
  190. or upper(NAME) like '%HEAT_MAP%'
  191. order by NAME, INST_ID;
  192. SET LINESIZE 500
  193. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,'||
  194. decode(&&OCOUNT., 0, 'count,', '"ORA-00942: table or view does not exist",')
  195. from dual where &&OCOUNT. in (-942, 0);
  196. -- V$VERSION - DB Version
  197. -------------------------
  198. define OPTION_NAME=V$VERSION
  199. define OPTION_QUERY=NULL
  200. define OCOUNT=-942
  201. col OCOUNT new_val OCOUNT noprint
  202. select ltrim(rtrim(to_char(count(*)))) as OCOUNT
  203. FROM V$VERSION;
  204. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,count,"'||
  205. BANNER ||'",'
  206. FROM V$VERSION;
  207. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,'||
  208. decode(&&OCOUNT., 0, 'count,', '"ORA-00942: table or view does not exist",')
  209. from dual where &&OCOUNT. in (-942, 0);
  210. --- OEM 10G AND HIGHER --- components
  211. ----------------------
  212. define OPTION_NAME=OEM
  213. define OPTION_QUERY=MGMT_INV_COMPONENT
  214. define OPTION_QUERY_COLS=CONTAINER_TYPE,CONTAINER_NAME,CONTAINER_LOCATION,OUI_PLATFORM,IS_CLONABLE,NAME,VERSION,DESCRIPTION,EXTERNAL_NAME,INSTALLED_LOCATION,INSTALLER_VERSION,MIN_DEINSTALLER_VERSION,IS_TOP_LEVEL,TIMESTAMP
  215. define OCOUNT=-942
  216. col OCOUNT new_val OCOUNT noprint
  217. select ltrim(rtrim(to_char(count(*)))) as OCOUNT
  218. from SYSMAN.MGMT_INV_CONTAINER a
  219. full outer join SYSMAN.MGMT_INV_COMPONENT b on a.CONTAINER_GUID = b.CONTAINER_GUID
  220. ;
  221. select '&&GREP_PREFIX.,&OPTION_NAME.~HEADER,&OPTION_QUERY.~HEADER,&&OCOUNT.,count,&OPTION_QUERY_COLS.,'
  222. from dual where &&OCOUNT. > 0;
  223. SET LINESIZE 1500
  224. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,count,"'||
  225. a.CONTAINER_TYPE || '","' ||
  226. a.CONTAINER_NAME || '","' ||
  227. a.CONTAINER_LOCATION || '","' ||
  228. a.OUI_PLATFORM || '","' ||
  229. a.IS_CLONABLE || '","' ||
  230. NAME || '","' ||
  231. VERSION || '","' ||
  232. substr(replace(replace(replace(to_char(substr(b.DESCRIPTION, 1, 1000)), chr(10), '[LF]'), chr(13), '[CR]'),'"',''''), 1, 255) || '","' ||
  233. EXTERNAL_NAME || '","' ||
  234. INSTALLED_LOCATION || '","' ||
  235. INSTALLER_VERSION || '","' ||
  236. MIN_DEINSTALLER_VERSION || '","' ||
  237. IS_TOP_LEVEL || '","' ||
  238. TIMESTAMP || '",'
  239. from SYSMAN.MGMT_INV_CONTAINER a
  240. full outer join SYSMAN.MGMT_INV_COMPONENT b on a.CONTAINER_GUID = b.CONTAINER_GUID
  241. ;
  242. SET LINESIZE 500
  243. -- OEM PACK USAGE (12c Cloud Control)
  244. define OPTION_NAME=OEM
  245. define OPTION_QUERY=PACK_USAGE
  246. define OPTION_QUERY_COLS=PACK_NAME,TARGET_NAME,TARGET_DISPLAY_NAME,TARGET_TYPE,HOST_NAME,CURRENTLY_USED,DETECTED_USAGES,TOTAL_SAMPLES,LAST_USAGE_DATE,FIRST_SAMPLE_DATE,LAST_SAMPLE_DATE,PACK_ID
  247. define OCOUNT=-942
  248. col OCOUNT new_val OCOUNT noprint
  249. select ltrim(rtrim(to_char(count(*)))) as OCOUNT
  250. FROM SYSMAN.mgmt_fu_registrations reg,
  251. SYSMAN.mgmt_fu_statistics stat,
  252. SYSMAN.mgmt_targets tgts
  253. WHERE (stat.isused = 1 or stat.detected_samples > 0) -- current or past usage
  254. AND stat.target_guid = tgts.target_guid
  255. AND reg.feature_id = stat.feature_id
  256. AND reg.collection_mode = 2
  257. --AND tgts.display_name = 'TARGET_NAME'
  258. ;
  259. select '&&GREP_PREFIX.,&OPTION_NAME.~HEADER,&OPTION_QUERY.~HEADER,&&OCOUNT.,count,&OPTION_QUERY_COLS.,'
  260. from dual where &&OCOUNT. > 0;
  261. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,count,"'||
  262. reg.feature_name || '","' ||
  263. tgts.target_name || '","' ||
  264. tgts.display_name || '","' ||
  265. tgts.type_display_name || '","' ||
  266. tgts.host_name || '","' ||
  267. DECODE(stat.isused, 1, 'TRUE', 'FALSE') || '",' ||
  268. stat.detected_samples || ',' ||
  269. stat.total_samples || ',' ||
  270. stat.last_usage_date || ',' ||
  271. stat.first_sample_date || ',' ||
  272. stat.last_sample_date || ',"' ||
  273. reg.feature_id || '",'
  274. FROM SYSMAN.mgmt_fu_registrations reg,
  275. SYSMAN.mgmt_fu_statistics stat,
  276. SYSMAN.mgmt_targets tgts
  277. WHERE (stat.isused = 1 or stat.detected_samples > 0) -- current or past usage
  278. AND stat.target_guid = tgts.target_guid
  279. AND reg.feature_id = stat.feature_id
  280. AND reg.collection_mode = 2
  281. --AND tgts.display_name = 'TARGET_NAME'
  282. ORDER BY decode(tgts.target_type, 'oracle_database', 1, 'rac_database', 1, 2), -- db packs first
  283. reg.feature_name,
  284. tgts.type_display_name,
  285. tgts.display_name,
  286. tgts.host_name;
  287. select '&&GREP_PREFIX.,&OPTION_NAME.,&OPTION_QUERY.,&&OCOUNT.,'||
  288. decode(&&OCOUNT., 0, 'count,', '"ORA-00942: table or view does not exist",')
  289. from dual where &&OCOUNT. in (-942, 0);
  290. PROMPT
  291. select 'Review Lite Script runtime:' " ",
  292. (sysdate - to_date('&SYSDATE_START', 'YYYY-MM-DD_HH24:MI:SS'))*24*60*60 " ",
  293. 'seconds' " "
  294. from dual;
  295. PROMPT END OF SCRIPT
  296. SPOOL OFF
  297. -- Log collection completed
  298. SET VERIFY OFF
  299. SPOOL DB_sql_&&LOGS.002.log
  300. DECLARE
  301. INSTANCE_N VARCHAR2(900) := '&&INSTANCE_NAME_0';
  302. HOST_N VARCHAR2(200) := '&&HOST_NAME';
  303. PDB_N VARCHAR2(200) := '';
  304. BEGIN
  305. begin
  306. -- Get PDB name if applicable
  307. execute immediate 'select '' PDB: '' || sys_context(''USERENV'', ''CON_NAME'') from V$PARAMETER where NAME = ''enable_pluggable_database'' and VALUE = ''TRUE''' into PDB_N;
  308. exception
  309. when others then
  310. null;
  311. end;
  312. dbms_output.put_line('DB: CT-02000: COLLECTED: Database Instance: ' || INSTANCE_N || PDB_N || ' running on Host: ' || HOST_N);
  313. END;
  314. /
  315. SPOOL OFF