├── Bug ├── invoke_procedure_in_trigger.sql └── session_tz_and_timestamp_ltz_bug.sql ├── CSV_Files ├── crbc_oracle_lps_tps_in_last_1_hour.csv ├── crbc_oracle_lps_tps_in_last_24_hours.csv ├── crbc_oracle_lps_tps_in_last_31_days.csv ├── crtc_oracle_io_mbps_in_last_1_hour.csv ├── crtc_oracle_io_mbps_in_last_1_minute.csv ├── crtc_oracle_iops_in_last_1_hour.csv ├── crtc_oracle_iops_in_last_1_minute.csv ├── oracle_lps_tps_in_last_1_hour.csv ├── oracle_lps_tps_in_last_24_hours.csv └── oracle_lps_tps_in_last_31_days.csv ├── DB_Design_Demo └── annual_report_demo.sql ├── Dev Requirements ├── grant_tables_from_one_user_to_another.sql └── revoke_tables_of_one_user_from_another.sql ├── EXCEL_Reports ├── ARP │ ├── arp.xlsx │ ├── arp_1.csv │ ├── arp_2.csv │ ├── arp_3.csv │ ├── arp_4.csv │ ├── arp_5.csv │ ├── arp_6.csv │ ├── arp_7.csv │ ├── arp_8.csv │ └── arp_demo_1.csv └── ARP_DEMO_csv_excel │ ├── arp.xlsx │ ├── arp_1.csv │ ├── arp_2.csv │ ├── arp_3.csv │ ├── arp_4.csv │ ├── arp_5.csv │ ├── arp_6.csv │ ├── arp_7.csv │ ├── arp_8.csv │ └── arp_demo_1.csv ├── LICENSE ├── LiveSQL Demo └── order_by_function.sql ├── README.md ├── SCN ├── database_scn.sql ├── datafile_header_scn.sql └── datafile_scn.sql ├── SQL Quiz └── quiz_intersect.sql ├── SQL Set Demos └── minus_inline_external_table.sql ├── ShinData ├── all_prod_user_privs.sql ├── all_prod_users.sql ├── arch_total_size_from_everyday.sql ├── ash_activity_pct_by_top10sessions.sql ├── ash_activity_pct_by_top10sqls.sql ├── ash_counts_by_wait_class.sql ├── asm_arch_size.sql ├── asm_rman_size.sql ├── backup_files_by_piece.sql ├── buffer_cache_hit_ratio.sql ├── buffer_pool_size.sql ├── cdb_pdbs.sql ├── check_dataguard_basic_info.sql ├── check_ip_by_monitor_user.sql ├── check_redo_log_size.sql ├── check_redo_switch_numbers.sql ├── check_session_longops.sql ├── check_sql_commits.sql ├── current_running_sqls.sql ├── datafile_io_responsetime.sql ├── datafile_used_rate_pagination.sql ├── dbtime_dbcpu.sql ├── dg_gap_and_lag.sql ├── dg_gap_status.sql ├── dg_messages.sql ├── dg_mrp.sql ├── dg_param_configuration.sql ├── dg_process_status.sql ├── dg_rec_apply_max_seq.sql ├── dg_redo_apply_rate.sql ├── invalid_objects.sql ├── is(a)dg_unqname.sql ├── isadg.sql ├── kill_sessions_base_on_sqlid.sql ├── kill_sessions_by_row_lock.sql ├── lock_waitevent.sql ├── log_buffer_space_avg_wait_time.sql ├── log_file_avg_wait_time.sql ├── max_connections_from_sqlid.sql ├── oracle_built-in_username.sql ├── params_all.sql ├── params_basic.sql ├── params_default.sql ├── params_dynamic.sql ├── params_not_default.sql ├── params_pdb.sql ├── params_static.sql ├── permanent_tablespace_used_rate.sql ├── pga_used_rate.sql ├── pga_used_rate_hist.sql ├── redo_total_size_in_recent_1_hour.sql ├── rman_async_io.sql ├── rman_backup_job_details.sql ├── row_lock_contention.sql ├── scheduler_jobs.sql ├── sessions_and_objects_by_row_lock.sql ├── sessions_blocking_chains.sql ├── sessions_by_row_lock.sql ├── sessions_hist_blocking_chains.sql ├── sessions_sqls_in_curr_temp_seg_usage.sql ├── set_sqlprompt.sql ├── sga_used_rate.sql ├── sga_used_rate_hist.sql ├── sql_avg_elap_time_top60.sql ├── sql_by_hist_row_lock.sql ├── sql_by_row_lock.sql ├── sql_tuning_advisor_report.sql ├── table_fragment.sql ├── table_stale_statistics.sql ├── tablespace_datafile_used_rate.sql ├── tablespace_fragment.sql ├── tablespace_used_increased_size.sql ├── top10_hot_tables.sql ├── top10_index_partitions_occupied_by_size.sql ├── top10_index_subpartitions_occupied_by_size.sql ├── top10_indexes_occupied_by_size.sql ├── top10_lob_partitions_occupied_by_size.sql ├── top10_lobsegments_occupied_by_size.sql ├── top10_segment_occupied_tablespace.sql ├── top10_table_partitions_occupied_by_size.sql ├── top10_table_subpartitions_occupied_by_size.sql ├── top10_tables_occupied_by_size.sql ├── total_parse_count_per_sec.sql └── workload.sql ├── Tips ├── ASM清理磁盘头信息.txt ├── Oracle SQL优化技巧.txt ├── Oracle-RMAN恢复数据库操作步骤.txt ├── OracleDG备库定时删除已应用的归档日志.txt ├── Oracle查看Data Guard Apply速度脚本.txt ├── Oracle查看完整的sql_fulltext内容.txt ├── Oracle用sqlprompt修改sqlplus的连接提示符.txt ├── check_io_setup.txt ├── 使用授权用户查看Oracle服务器的物理IP地址-原版.txt ├── 使用授权用户查看Oracle服务器的物理IP地址.txt ├── 批量杀掉Oracle连接会话.txt ├── 查看DG主备库的角色_打开模式_保护模式等.txt ├── 查看Oracle中Redo日志组和StandbyRedo日志组的信息.txt ├── 查看Oracle中SGA各组件的内存动态分配情况.txt ├── 查看Oracle中修改过的隐藏参数.txt ├── 查看Oracle中占用临时表空间的session或SQL.txt ├── 查看Oracle中多租户(CDB,PDB)架构.txt ├── 查看Oracle中表空间SYSTEM和SYSAUX的top10占用对象大小.txt ├── 查看Oracle标准审计和清理审计表aud$数据的策略.txt ├── 查看Oracle的service名_数据库名_实例名_pdb名.txt ├── 查看Oracle的所有用户(排除系统内置).txt ├── 查看Oracle长时间运行的任务及完成进度.txt ├── 查看Oracle非系统内置用户的权限(包括系统权限,角色权限和对象权限).txt ├── 查看RMAN备份任务的作业.txt ├── 查看RMAN备份的异步IO.txt ├── 查看Redo Log文件的大小及每天的归档日志量.txt ├── 查看SQL的执行计划.txt ├── 查看SQL的调优建议报告.txt ├── 查看归档日志使用容量.txt ├── 终止Oracle中正在运行的RMAN备份任务.txt └── 调整Oracle的undo表空间大小.txt ├── XML_Reports ├── Active_Sessions_Per_Activity_Class │ └── Active_Sessions_Per_Activity_Class.xml ├── Active_Sessions_Per_Wait_Class │ ├── Active_Sessions_Per_Wait_Class.xml │ ├── Active_Sessions_Per_Wait_Class_amend.xml │ ├── aspwc_in_last_1_hour.xml │ ├── aspwc_in_last_1_hour_amend.xml │ ├── aspwc_in_last_1_minute.xml │ └── aspwc_in_last_1_minute_amend.xml ├── Average_Active_Sessions │ ├── Average Active Sessions Custom Time Period (interval by each day).xml │ ├── Average Active Sessions Custom Time Period (interval by each hour).xml │ ├── Average Active Sessions in Last 24 Hours.xml │ ├── Average Active Sessions in Last 31 Days (interval by each day).xml │ ├── Average Active Sessions in Last 31 Days (interval by each hour).xml │ ├── Average Active Sessions in Last 7 Days (interval by each day).xml │ ├── Average Active Sessions in Last 7 Days (interval by each hour).xml │ ├── Average Active Sessions in Real Time.xml │ └── Average Active Sessions.xml ├── Average_Active_Sessions_and_Logic_CPUs │ ├── Average Active Sessions & Logic CPUs Custom Time Period (interval by each day).xml │ ├── Average Active Sessions & Logic CPUs Custom Time Period (interval by each hour).xml │ ├── Average Active Sessions & Logic CPUs in Last 24 Hours.xml │ ├── Average Active Sessions & Logic CPUs in Last 31 Days (interval by each day).xml │ ├── Average Active Sessions & Logic CPUs in Last 31 Days (interval by each hour).xml │ ├── Average Active Sessions & Logic CPUs in Last 7 Days (interval by each day).xml │ ├── Average Active Sessions & Logic CPUs in Last 7 Days (interval by each hour).xml │ ├── Average Active Sessions & Logic CPUs in Real Time.xml │ └── Average Active Sessions & Logic CPUs.xml ├── Average_Runnable_Processes.xml ├── Average_Runnable_Processes │ ├── Average Runnable Processes in Last 1 Hour.xml │ └── Average Runnable Processes.xml ├── Current_Logons_Count │ ├── Current Logons Count Custom Time Period (interval by each day).xml │ ├── Current Logons Count Custom Time Period (interval by each hour).xml │ ├── Current Logons Count in Last 24 Hours.xml │ ├── Current Logons Count in Last 31 Days (interval by each day).xml │ ├── Current Logons Count in Last 31 Days (interval by each hour).xml │ ├── Current Logons Count in Last 7 Days (interval by each day).xml │ ├── Current Logons Count in Last 7 Days (interval by each hour).xml │ ├── Current Logons Count in Real Time.xml │ └── Current Logons Count.xml ├── Current_OS_Load │ ├── Current OS Load Custom Time Period (interval by each day).xml │ ├── Current OS Load Custom Time Period (interval by each hour).xml │ ├── Current OS Load in Last 24 Hours.xml │ ├── Current OS Load in Last 31 Days (interval by each day).xml │ ├── Current OS Load in Last 31 Days (interval by each hour).xml │ ├── Current OS Load in Last 7 Days (interval by each day).xml │ ├── Current OS Load in Last 7 Days (interval by each hour).xml │ ├── Current OS Load in Real Time.xml │ └── Current OS Load.xml ├── DB_time │ ├── DB time Custom Time Period (interval by each day).xml │ ├── DB time Custom Time Period (interval by each hour).xml │ ├── DB time in Last 1 Hour.xml │ ├── DB time in Last 24 Hours.xml │ ├── DB time in Last 31 Days (interval by each day).xml │ ├── DB time in Last 31 Days (interval by each hour).xml │ ├── DB time in Last 7 Days (interval by each day).xml │ ├── DB time in Last 7 Days (interval by each hour).xml │ └── DB time.xml ├── Latency_For_Synchronous_Single_Block_Reads │ ├── Latency For Synchronous Single Block Reads Custom Time Period (interval by each day).xml │ ├── Latency For Synchronous Single Block Reads Custom Time Period (interval by each hour).xml │ ├── Latency For Synchronous Single Block Reads in Last 24 Hours.xml │ ├── Latency For Synchronous Single Block Reads in Last 31 Days (interval by each day).xml │ ├── Latency For Synchronous Single Block Reads in Last 31 Days (interval by each hour).xml │ ├── Latency For Synchronous Single Block Reads in Last 7 Days (interval by each day).xml │ ├── Latency For Synchronous Single Block Reads in Last 7 Days (interval by each hour).xml │ ├── Latency For Synchronous Single Block Reads in Real Time (in Last 1 Hour).xml │ └── Latency For Synchronous Single Block Reads.xml ├── Physical_Reads (KB)_and_Physical_Writes (KB)_Redo_Size (KB) │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) Custom Time Period (interval by each day).xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) Custom Time Period (interval by each hour).xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) in Last 24 Hours.xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) in Last 31 Days (interval by each day).xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) in Last 31 Days (interval by each hour).xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) in Last 7 Days (interval by each day).xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) in Last 7 Days (interval by each hour).xml │ ├── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB) in Real Time (in Last 1 Hour).xml │ └── Physical Reads (KB) & Physical Writes (KB) & Redo Size (KB).xml ├── Total_Physical_Reads (KB)_and_Total_Physical_Writes (KB)_and_Total_IO (KB) │ ├── Total Physical Reads (KB) & Total Physical Writes (KB) & Total IO (KB) in Real Time (in Last 1 Hour).xml │ └── Total Physical Reads (KB) & Total Physical Writes (KB) & Total IO (KB).xml └── User_Transaction_Per_Sec_and_Logons_Per_Sec │ ├── Logons Per Sec & User Transaction Per Sec Custom Time Period (interval by each day).xml │ ├── Logons Per Sec & User Transaction Per Sec Custom Time Period (interval by each hour).xml │ ├── Logons Per Sec & User Transaction Per Sec in Last 24 Hours.xml │ ├── Logons Per Sec & User Transaction Per Sec in Last 31 Days (interval by each day).xml │ ├── Logons Per Sec & User Transaction Per Sec in Last 31 Days (interval by each hour).xml │ ├── Logons Per Sec & User Transaction Per Sec in Last 7 Days (interval by each day).xml │ ├── Logons Per Sec & User Transaction Per Sec in Last 7 Days (interval by each hour).xml │ ├── Logons Per Sec & User Transaction Per Sec in Real Time.xml │ └── User Transaction Per Sec & Logons Per Sec.xml ├── acquiring_pool_sql ├── buffer_gets_rank_top_5_sql_on_sqlstats.sql ├── disk_reads_rank_top_5_sql_on_sqlstats.sql ├── poor_parsing_applications_rank_top_5_sql_on_sqlstats.sql └── shared_memory_rank_top_5_sql_on_sqlstats.sql ├── adg ├── check_dg_phystdby_log_apply.sql ├── check_dg_redo_apply.sql └── set_newname_for_df_and_tf_on_rac_stb_from_pry.sql ├── ash ├── active_sessions.sql ├── active_sessions_per_session_state.sql ├── active_sessions_per_wait_class.sql ├── ash_event_count_topN.sql ├── ash_event_count_topN_2.sql └── ash_event_count_topN_new.sql ├── awr_trend ├── acquire_aas.sql ├── acquire_aas_2.sql ├── acquire_arp.sql ├── acquire_arp_2.sql ├── acquire_aspac.sql ├── acquire_aspwc.sql ├── acquire_assbrl.sql ├── acquire_clc.sql ├── acquire_cocc.sql ├── acquire_col.sql ├── acquire_cpu_load.sql ├── acquire_cpu_load_2.sql ├── acquire_cpu_usage.sql ├── acquire_dbcps.sql ├── acquire_dbcpt.sql ├── acquire_dbgps.sql ├── acquire_dbgpt.sql ├── acquire_dbtime.sql ├── acquire_dbtime_2.sql ├── acquire_eps.sql ├── acquire_ept.sql ├── acquire_io_mbps.sql ├── acquire_io_mbps_2.sql ├── acquire_io_mbps_by_function.sql ├── acquire_iops.sql ├── acquire_iops_2.sql ├── acquire_iops_by_function.sql ├── acquire_logic_cpus_union_aas.sql ├── acquire_lps.sql ├── acquire_lps_union_tps.sql ├── acquire_lrps.sql ├── acquire_network_mbps.sql ├── acquire_prps.sql ├── acquire_prps_union_pwps_union_rsps.sql ├── acquire_redo_gen_mbps.sql ├── acquire_rtpt.sql ├── acquire_rwps.sql ├── acquire_session_count.sql ├── acquire_ssrt.sql ├── acquire_tps.sql ├── acquire_tps_2.sql ├── acquire_ucps.sql └── acquire_ucpt.sql ├── capacity_planning ├── checking_table_growth.sql ├── checking_table_growth_2.sql ├── checking_table_used_size.sql ├── checking_tablespace_growth.sql ├── checking_tablespace_growth_2.sql └── monitor_big_table_size.sql ├── dig_ip_via_function └── dig_ip_via_function.sql ├── dig_ip_via_trigger └── dig_ip_via_trigger.sql ├── dig_listener_log_xml ├── dig_ip_via_listener_log_xml.sql └── dig_ip_via_listener_log_xml_2.sql ├── expdp └── expdp_exclude_stats.sql ├── grant ├── bgs_role_syn.sql ├── bgs_role_syn_tab.sql ├── bgs_role_syn_tab_2.sql ├── bgs_role_syn_tab_3.sql ├── bgs_scheduler.sql └── bth_grt_sel.sql ├── lock └── row_lock.sql ├── migration_compare └── migration_before_and_after_compare.sql ├── mview └── materialized_view_demo.sql ├── plsql ├── brgs_role_syn_tab.sql ├── brgs_role_syn_tab_2.sql ├── brgs_role_syn_tab_3.sql ├── brst2_scheduler.sql ├── brst3_scheduler.sql ├── brst_scheduler.sql ├── collect_empty_dba_hist_tables.sql ├── dyn_crt_table │ ├── dyn_crt_table.sql │ ├── dyn_crt_table_2.sql │ ├── dyn_crt_table_3.sql │ └── dyn_crt_table_4.sql ├── grant │ ├── bgs_role_syn_2.sql │ ├── bgs_role_syn_3.sql │ ├── bth_grt_sel_2.sql │ └── bth_grt_sel_3.sql ├── performance_compare │ ├── identity_column_compare.sql │ └── insert_approach_compare.sql ├── puzzle_plsql │ ├── compare_plsql_output.sql │ ├── compare_plsql_output_2.sql │ └── string-indexed_collection.sql ├── revoke │ ├── brs_role_syn_2.sql │ ├── brs_role_syn_3.sql │ ├── bth_rvk_sel_2.sql │ └── bth_rvk_sel_3.sql ├── rgy_refresh_mview_uts.sql └── switch_redo_log_for_recycle.sql ├── recent_metrics ├── acquire_recent_aas.sql ├── acquire_recent_clc.sql ├── acquire_recent_cocc.sql ├── acquire_recent_col.sql ├── acquire_recent_cpu_load.sql ├── acquire_recent_cpu_usage.sql ├── acquire_recent_dbcps.sql ├── acquire_recent_dbcpt.sql ├── acquire_recent_dbcpu_time_ratio.sql ├── acquire_recent_dbgps.sql ├── acquire_recent_dbgpt.sql ├── acquire_recent_dbtime.sql ├── acquire_recent_dbwait_time_ratio.sql ├── acquire_recent_eps.sql ├── acquire_recent_ept.sql ├── acquire_recent_io_mbps.sql ├── acquire_recent_iops.sql ├── acquire_recent_lps.sql ├── acquire_recent_lrps.sql ├── acquire_recent_network_mbps.sql ├── acquire_recent_prps.sql ├── acquire_recent_redo_gen_mbps.sql ├── acquire_recent_rtpt.sql ├── acquire_recent_rwps.sql ├── acquire_recent_session_count.sql ├── acquire_recent_ssrt.sql ├── acquire_recent_tps.sql ├── acquire_recent_ucps.sql └── acquire_recent_ucpt.sql ├── revoke ├── brs_role_syn.sql ├── brs_role_syn_tab.sql ├── brs_role_syn_tab_2.sql ├── brs_role_syn_tab_3.sql └── bth_rvk_sel.sql ├── routine_inspection ├── all_prod_user.sql ├── break_compute_demo.sql ├── check_his_sql_temp_space.sql ├── check_non_default_parameter.sql ├── check_sequence_ddl_and_used.sql ├── check_tab_part_range_situation.sql ├── check_table_blocks_and_rows.sql ├── check_table_dml.sql ├── check_tbs_fragmentation_ratio.sql ├── check_total_size_oracle_db.sql ├── connect_machine_via_sql_id.sql ├── ctl_file_path_in_rman_backupsets.sql ├── db_buffer_cache_hit_ratio.sql ├── dropped_object_of_recyclebin.sql ├── get_ddl_of_object_via_passing_in_arguments.sql ├── get_ddl_of_object_via_using_accept.sql ├── get_ddl_of_object_via_using_substitution_variable.sql ├── get_dyn_perf_view_def.sql ├── get_dyn_perf_view_def_2.sql ├── get_dyn_perf_view_def_3.sql ├── hit_ratio_db_buffer_cache.sql ├── hit_ratio_db_buffer_cache_2.sql ├── hit_ratio_db_buffer_cache_3.sql ├── listagg_redo_log_group_members.sql ├── listagg_redo_log_group_members_2.sql ├── per_machine_act_conn_num_aggr_by_user.sql ├── rman_backup_check.sql ├── rman_backup_check_2.sql ├── rman_backup_check_3.sql ├── rman_backup_check_4.sql ├── rman_backup_check_plsql_1.sql ├── rman_backup_check_plsql_2.sql ├── spfile_path_in_rman_backupsets.sql ├── spool_prod_tables_ddl.sql ├── tablespace_free_space.sql ├── tablespace_non-temp_compare_total_size.sql ├── tablespace_non-temp_compare_total_size_simple_version.sql ├── tablespace_non-temp_compare_total_size_with_as.sql ├── tablespace_non-temp_recyclebin_rollup_segment_name.sql ├── tablespace_per_used_size_and_rollup.sql ├── tablespace_per_used_size_and_total_size.sql ├── tablespace_used_size_1.sql ├── tablespace_used_size_2.sql ├── tablespace_utilization_rate.sql ├── tablespace_utilization_rate_2.sql ├── temporary_tablespace_used_size.sql ├── temporary_tablespace_used_size_2.sql ├── top_10_segment_on_sysaux_tbs.sql ├── top_10_segment_on_system_tbs.sql ├── top_10_segments_on_specific_tbs.sql ├── ts_used_size_with_lob_in_recyclebin.sql └── ts_used_size_without_lob_in_recyclebin.sql ├── scheduler ├── scheduler_demo.sql ├── user_scheduler_job_log.sql └── user_scheduler_jobs.sql ├── sql_tuning ├── check_data_dictionary_tables_and_views.sql ├── check_sql_execution_plan_table.sql ├── check_sql_multiple_execution_plans.sql ├── check_sql_multiple_execution_plans_2.sql ├── like_expression.sql ├── like_expression_2.sql ├── optimize_query_null_value.sql ├── pagination_query_ascending_index.sql ├── pagination_query_bug.sql ├── topN_query_descending_index(bug).sql ├── user_index_columns.sql ├── user_index_expressions.sql └── user_indexes.sql ├── statistics_info ├── all_tables_mods_on_all_proc_users.sql ├── all_tables_stats_on_all_proc_users.sql ├── table_column_statistics.sql ├── table_mods_on_proc_user.sql └── table_stats_on_proc_user.sql └── wallet └── playing with ora19c_ora21c wallet.txt /CSV_Files/crbc_oracle_lps_tps_in_last_24_hours.csv: -------------------------------------------------------------------------------- 1 | "SNAP_DATE_TIME","Logons","Transactions" 2 | "2021-12-19 14:59:51",3.28,0.03 3 | "2021-12-19 15:59:52",3.28,0.04 4 | "2021-12-19 16:59:53",3.29,0.02 5 | "2021-12-19 18:00:53",3.29,0.03 6 | "2021-12-19 18:59:54",3.28,0.05 7 | "2021-12-19 19:59:54",3.29,0.05 8 | "2021-12-19 20:59:55",3.28,0.07 9 | "2021-12-19 21:59:55",3.28,0.05 10 | "2021-12-19 22:59:56",3.29,0.06 11 | "2021-12-20 00:00:57",3.29,0.03 12 | "2021-12-20 00:59:57",3.29,0.01 13 | "2021-12-20 01:59:58",3.29,0.01 14 | "2021-12-20 02:59:58",3.29,0.01 15 | "2021-12-20 03:59:59",3.29,0.01 16 | "2021-12-20 04:59:59",3.29,0.01 17 | "2021-12-20 05:59:59",3.29,0.01 18 | "2021-12-20 07:00:00",3.29,0.14 19 | "2021-12-20 08:00:01",3.29,0.01 20 | "2021-12-20 09:00:01",3.3,0.02 21 | "2021-12-20 10:00:02",3.3,0.01 22 | "2021-12-20 11:00:03",3.3,0.01 23 | "2021-12-20 12:00:03",3.29,0.01 24 | "2021-12-20 13:00:03",3.29,0.01 25 | "2021-12-20 14:00:04",3.29,0.01 26 | -------------------------------------------------------------------------------- /CSV_Files/crtc_oracle_io_mbps_in_last_1_minute.csv: -------------------------------------------------------------------------------- 1 | "SAMPLE_TIME","Buffer Cache Reads","Direct Reads","Direct Writes","DBWR","LGWR","ARCH","RMAN","Recovery","Data Pump","Streams AQ","XDB","Others","Archive Manager","Smart Scan" 2 | "2021-12-23 13:57:43",0,0,0,0,0.017,0,0,0,0,0,0,0.084,0,0 3 | -------------------------------------------------------------------------------- /CSV_Files/crtc_oracle_iops_in_last_1_minute.csv: -------------------------------------------------------------------------------- 1 | "SAMPLE_TIME","Buffer Cache Reads","Direct Reads","Direct Writes","DBWR","LGWR","ARCH","RMAN","Recovery","Data Pump","Streams AQ","XDB","Others","Archive Manager","Smart Scan" 2 | "2021-12-23 13:59:44",0.301,0,0,0.084,6.399,0,0,0,0,0,0,5.664,0,0 3 | -------------------------------------------------------------------------------- /Dev Requirements/revoke_tables_of_one_user_from_another.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: revoke_tables_of_one_user_from_another.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jan 26, 2024 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.13.0.0 9 | REM 10 | REM Purpose: 11 | REM This sql script uses to revoke tables of one user from another on production system. 12 | REM 13 | 14 | -- Revoking the select privilege of all tables of one user from another, in other words, from grantee_owner directly. 15 | 16 | PROMPT ===================== 17 | PROMPT Running on SYS schema 18 | PROMPT ===================== 19 | 20 | DECLARE 21 | v_grantor_owner dba_users.username%type := upper('&grantor_owner'); 22 | v_grantee_owner dba_users.username%type := upper('&grantee_owner'); 23 | BEGIN 24 | FOR bg IN (select owner, table_name from dba_tables where owner = v_grantor_owner) 25 | LOOP 26 | EXECUTE IMMEDIATE Q'[revoke select on ]' || bg.owner || Q'[.]' || bg.table_name || Q'[ from ]' || v_grantee_owner; 27 | END LOOP; 28 | END; 29 | / 30 | -------------------------------------------------------------------------------- /EXCEL_Reports/ARP/arp.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/EXCEL_Reports/ARP/arp.xlsx -------------------------------------------------------------------------------- /EXCEL_Reports/ARP/arp_1.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","15:06:31","15:07:31","15:08:31","15:09:30","15:10:31","15:11:30","15:12:31","15:13:31","15:14:31","15:15:31","15:16:31","15:17:31","15:18:31","15:19:31","15:20:31","15:21:31","15:22:31","15:23:30","15:24:31","15:25:31","15:26:31","15:27:31","15:28:31","15:29:31","15:30:31","15:31:31","15:32:31","15:33:31","15:34:31","15:35:31","15:36:31","15:37:31","15:38:31","15:39:31","15:40:31","15:41:31","15:42:31","15:43:31","15:44:31","15:45:31","15:46:31","15:47:31","15:48:31","15:49:31","15:50:31","15:51:31","15:52:32","15:53:31","15:54:31","15:55:31","15:56:32","15:57:31","15:58:31","15:59:31","16:00:31","16:01:31","16:02:32","16:03:31","16:04:31","16:05:31" 2 | "Instance Foreground CPU",0.64,0.43,0.42,0.34,0.28,0.29,0.28,0.33,0.34,0.34,0.4,0.31,0.67,0.39,0.33,0.29,0.3,0.37,0.29,0.29,0.28,0.29,0.28,0.28,0.35,0.28,0.32,0.32,0.37,0.31,0.97,0.44,0.51,0.76,0.32,0.4,0.29,0.31,0.37,0.32,0.34,0.29,0.62,0.32,0.29,0.31,0.28,0.31,0.29,0.31,0.29,0.35,0.39,0.29,0.31,0.32,0.32,0.33,0.47,0.53 3 | "Instance Background CPU",0.18,0.12,0.06,0.06,0.06,0.06,0.11,0.06,0.06,0.05,0.06,0.06,0.06,0.05,0.06,0.06,0.05,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.05,0.07,0.06,0.06,0.06,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.07,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.05,0.14,0.07,0.06,0.06,0.05 4 | "Non-Database Host CPU",0.47,0.52,0.55,0.61,0.45,0.54,0.52,0.53,0.41,0.53,0.43,0.7,0.7,0.7,0.45,0.54,0.57,0.53,0.46,0.55,0.44,0.7,0.97,0.53,0.43,0.58,0.53,0.61,0.44,0.57,0.55,0.72,0.59,0.53,0.45,0.71,0.54,0.55,0.45,0.6,0.45,0.75,0.66,0.51,0.67,0.6,0.72,0.55,0.45,0.59,0.48,0.53,0.59,0.72,0.53,0.54,8.71,6.51,0.46,0.49 5 | "Load Average",1.84,1.16,0.95,1.09,1.33,0.91,1.17,1.24,0.98,0.56,0.81,0.98,1.26,1.19,1.04,0.68,0.66,0.61,0.5,0.68,0.49,0.88,0.66,0.57,0.75,0.46,0.52,0.9,0.86,0.64,1.44,1.15,1.05,1.39,0.81,0.91,1.02,0.74,0.74,0.62,0.9,0.88,1.02,1.2,1,0.72,1.15,1,1.09,0.93,0.91,0.76,0.65,0.98,0.98,0.71,1.8,6.82,3.08,2.05 6 | -------------------------------------------------------------------------------- /EXCEL_Reports/ARP/arp_2.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-11-19 16:00","2021-11-19 17:00","2021-11-19 17:59","2021-11-19 19:00","2021-11-19 20:00","2021-11-19 21:00","2021-11-19 22:00","2021-11-19 22:59","2021-11-20 00:00","2021-11-20 01:00","2021-11-20 02:00","2021-11-20 02:59","2021-11-20 03:59","2021-11-20 05:00","2021-11-20 06:00","2021-11-20 07:00","2021-11-20 07:59","2021-11-20 08:59","2021-11-20 10:00","2021-11-20 11:00","2021-11-20 12:00","2021-11-20 12:59","2021-11-20 13:59","2021-11-20 15:00" 2 | "Instance Foreground CPU",0.6,0.53,0.49,0.51,0.38,0.43,0.38,0.43,0.42,0.33,0.31,0.3,0.48,0.28,0.29,0.34,0.31,0.33,0.57,0.55,0.42,0.36,0.38,0.34 3 | "Instance Background CPU",0.07,0.07,0.06,0.07,0.06,0.07,0.07,0.08,0.12,0.07,0.08,0.07,0.07,0.07,0.07,0.08,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.52,0.77,0.51,0.49,0.56,0.59,0.59,0.99,1.52,0.78,0.58,0.81,0.85,2.32,1.14,1.37,1.66,0.58,0.7,0.54,0.54,0.53,0.53,0.56 5 | "Load Average",1.28,1.44,1.59,1.18,1.27,1.06,1,4.7,8.64,2.37,1.24,1.96,1.93,4.86,1.09,1.15,1.59,0.99,1.38,1.35,0.97,0.9,0.74,0.93 -------------------------------------------------------------------------------- /EXCEL_Reports/ARP/arp_4.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-11-14","2021-11-15","2021-11-16","2021-11-17","2021-11-18","2021-11-19","2021-11-20" 2 | "Instance Foreground CPU",0.4,0.49,0.47,0.5,0.53,0.43,0.38 3 | "Instance Background CPU",0.07,0.07,0.07,0.07,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.65,0.63,0.64,0.66,0.64,0.62,0.94 5 | "Load Average",1.21,1.28,1.29,1.42,1.44,1.45,2.01 -------------------------------------------------------------------------------- /EXCEL_Reports/ARP/arp_6.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-10-21","2021-10-22","2021-10-23","2021-10-24","2021-10-25","2021-10-26","2021-10-27","2021-10-28","2021-10-29","2021-10-30","2021-10-31","2021-11-01","2021-11-02","2021-11-03","2021-11-04","2021-11-05","2021-11-06","2021-11-07","2021-11-08","2021-11-09","2021-11-10","2021-11-11","2021-11-12","2021-11-13","2021-11-14","2021-11-15","2021-11-16","2021-11-17","2021-11-18","2021-11-19","2021-11-20" 2 | "Instance Foreground CPU",2.15,1.86,1.31,1.46,2.3,1.58,1.22,1.39,1.14,0.81,0.6,0.76,0.54,0.6,0.7,0.76,0.69,0.76,0.64,0.87,0.78,0.48,0.44,0.45,0.44,0.49,0.47,0.5,0.53,0.43,0.38 3 | "Instance Background CPU",0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.67,0.65,0.84,0.66,0.63,0.64,0.63,0.65,0.68,0.85,0.65,0.64,0.64,0.65,0.61,0.64,0.86,0.63,0.6,0.61,0.67,0.65,0.67,0.87,0.64,0.63,0.64,0.66,0.64,0.62,0.94 5 | "Load Average",3.68,3.24,3.26,2.69,3.58,2.73,2.38,2.53,2.77,2.11,1.46,1.72,1.43,1.5,1.57,1.86,2.59,1.79,1.59,1.85,1.78,1.3,1.58,1.57,1.24,1.28,1.29,1.42,1.44,1.45,2.01 -------------------------------------------------------------------------------- /EXCEL_Reports/ARP/arp_8.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-10-25","2021-10-26","2021-10-27","2021-10-28","2021-10-29","2021-10-30","2021-10-31","2021-11-01","2021-11-02","2021-11-03","2021-11-04","2021-11-05","2021-11-06","2021-11-07","2021-11-08","2021-11-09","2021-11-10","2021-11-11","2021-11-12","2021-11-13","2021-11-14","2021-11-15","2021-11-16" 2 | "Instance Foreground CPU",3.1,1.58,1.22,1.39,1.14,0.81,0.6,0.76,0.54,0.6,0.7,0.76,0.69,0.76,0.64,0.87,0.78,0.48,0.44,0.45,0.44,0.49,0.47 3 | "Instance Background CPU",0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.6,0.64,0.63,0.65,0.68,0.85,0.65,0.64,0.64,0.65,0.61,0.64,0.86,0.63,0.6,0.61,0.67,0.65,0.67,0.87,0.64,0.63,0.64 5 | "Load Average",4.57,2.73,2.38,2.53,2.77,2.11,1.46,1.72,1.43,1.5,1.57,1.86,2.59,1.79,1.59,1.85,1.78,1.3,1.58,1.57,1.24,1.28,1.27 -------------------------------------------------------------------------------- /EXCEL_Reports/ARP_DEMO_csv_excel/arp.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/EXCEL_Reports/ARP_DEMO_csv_excel/arp.xlsx -------------------------------------------------------------------------------- /EXCEL_Reports/ARP_DEMO_csv_excel/arp_1.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","09:59","10:00","10:01","10:02","10:03","10:04","10:05","10:06","10:07","10:08","10:09","10:10","10:11","10:12","10:13","10:14","10:15","10:16","10:17","10:18","10:19","10:20","10:21","10:22","10:23","10:24","10:25","10:26","10:27","10:28","10:29","10:30","10:31","10:32","10:33","10:34","10:35","10:36","10:37","10:38","10:39","10:40","10:41","10:42","10:43","10:44","10:45","10:46","10:47","10:48","10:49","10:50","10:51","10:52","10:53","10:54","10:55","10:56","10:57","10:58" 2 | "Instance Foreground CPU",0.45,0.39,0.3,0.74,0.66,0.58,0.66,1.2,0.78,0.41,0.59,0.75,0.27,0.42,0.73,0.46,0.38,0.37,0.37,0.33,0.74,0.52,0.56,0.57,0.56,0.62,0.56,0.56,0.71,0.3,0.46,0.42,0.34,0.27,0.35,0.5,0.29,0.38,0.46,0.47,0.45,0.45,0.46,0.65,1.04,0.42,0.46,0.51,0.44,0.41,0.69,0.5,0.4,0.5,0.43,0.51,0.35,0.34,0.42,0.45 3 | "Instance Background CPU",0.06,0.06,0.18,0.06,0.06,0.06,0.06,0.19,0.12,0.06,0.07,0.06,0.06,0.16,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.05,0.06,0.06,0.06,0.06,0.06,0.06 4 | "Non-Database Host CPU",0.44,0.67,0.48,0.89,0.52,0.58,0.37,0.46,0.5,0.52,0.45,0.63,0.45,0.56,0.51,0.66,0.42,0.52,0.8,0.69,0.52,0.51,0.46,0.87,0.71,0.77,0.67,0.83,0.75,1.3,0.77,0.75,0.57,0.61,0.56,0.51,0.43,0.61,0.45,0.57,0.59,0.53,0.43,0.53,0.51,0.53,0.43,0.64,0.48,1.05,0.46,0.52,0.44,0.83,0.46,0.53,0.45,0.63,0.45,0.56 5 | "Load Average",1.11,0.93,1,1.72,2.08,1.57,1.1,3.74,2.54,1.65,1.16,1.21,0.96,1.71,1.87,1.45,0.7,1.22,0.95,1.15,1.38,1.48,1.91,2.3,2.98,2.93,2.74,3.24,3.12,8.64,4.47,3.26,2.13,1.72,1.53,1.52,1.41,1.12,1.08,0.93,0.77,0.95,0.7,1.25,1.7,1.38,0.98,1.37,1.04,0.95,1.53,1.52,1.19,3.2,2.29,1.59,1.17,0.87,0.63,0.66 6 | -------------------------------------------------------------------------------- /EXCEL_Reports/ARP_DEMO_csv_excel/arp_2.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-11-18 14:00","2021-11-18 15:00","2021-11-18 16:00","2021-11-18 17:00","2021-11-18 18:00","2021-11-18 19:00","2021-11-18 20:00","2021-11-18 21:00","2021-11-18 21:59","2021-11-18 23:00","2021-11-19 00:00","2021-11-19 01:00","2021-11-19 02:00","2021-11-19 02:59","2021-11-19 04:00","2021-11-19 05:00","2021-11-19 06:00","2021-11-19 07:00","2021-11-19 08:00","2021-11-19 08:59","2021-11-19 10:00","2021-11-19 11:00","2021-11-19 12:00","2021-11-19 12:59" 2 | "Instance Foreground CPU",0.54,0.63,0.65,0.64,0.6,0.69,0.51,0.46,0.54,0.5,0.38,0.31,0.3,0.28,0.57,0.28,0.28,0.28,0.32,0.58,0.58,0.5,0.44,0.38 3 | "Instance Background CPU",0.07,0.07,0.06,0.07,0.06,0.06,0.06,0.06,0.06,0.07,0.09,0.07,0.08,0.07,0.06,0.07,0.07,0.09,0.06,0.06,0.06,0.07,0.06,0.07 4 | "Non-Database Host CPU",0.57,0.57,0.66,0.83,0.54,0.52,0.53,0.55,0.55,0.63,0.53,0.48,0.47,0.46,0.62,1.94,0.62,0.46,0.48,0.52,0.54,0.59,0.53,0.51 5 | "Load Average",1.5,1.31,1.65,1.52,1.35,1.31,1.06,1.35,1.21,1.54,1.07,0.78,0.73,0.73,1.35,4.96,0.97,0.89,0.73,1.33,1.65,1.76,1.1,0.92 6 | 7 | -------------------------------------------------------------------------------- /EXCEL_Reports/ARP_DEMO_csv_excel/arp_4.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-11-13","2021-11-14","2021-11-15","2021-11-16","2021-11-17","2021-11-18","2021-11-19" 2 | "Instance Foreground CPU",0.66,0.44,0.49,0.47,0.5,0.53,0.42 3 | "Instance Background CPU",0.07,0.07,0.07,0.07,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.66,0.64,0.63,0.64,0.66,0.64,0.61 5 | "Load Average",1.78,1.24,1.28,1.29,1.42,1.44,1.33 6 | 7 | -------------------------------------------------------------------------------- /EXCEL_Reports/ARP_DEMO_csv_excel/arp_6.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-10-20","2021-10-21","2021-10-22","2021-10-23","2021-10-24","2021-10-25","2021-10-26","2021-10-27","2021-10-28","2021-10-29","2021-10-30","2021-10-31","2021-11-01","2021-11-02","2021-11-03","2021-11-04","2021-11-05","2021-11-06","2021-11-07","2021-11-08","2021-11-09","2021-11-10","2021-11-11","2021-11-12","2021-11-13","2021-11-14","2021-11-15","2021-11-16","2021-11-17","2021-11-18","2021-11-19" 2 | "Instance Foreground CPU",3.12,1.81,1.86,1.31,1.46,2.3,1.58,1.22,1.39,1.14,0.81,0.6,0.76,0.54,0.6,0.7,0.76,0.69,0.76,0.64,0.87,0.78,0.48,0.44,0.45,0.44,0.49,0.47,0.5,0.53,0.42 3 | "Instance Background CPU",0.08,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.64,0.67,0.65,0.84,0.66,0.63,0.64,0.63,0.65,0.68,0.85,0.65,0.64,0.64,0.65,0.61,0.64,0.86,0.63,0.6,0.61,0.67,0.65,0.67,0.87,0.64,0.63,0.64,0.66,0.64,0.61 5 | "Load Average",5.09,3.25,3.24,3.26,2.69,3.58,2.73,2.38,2.53,2.77,2.11,1.46,1.72,1.43,1.5,1.57,1.86,2.59,1.79,1.59,1.85,1.78,1.3,1.58,1.57,1.24,1.28,1.29,1.42,1.44,1.33 6 | 7 | -------------------------------------------------------------------------------- /EXCEL_Reports/ARP_DEMO_csv_excel/arp_8.csv: -------------------------------------------------------------------------------- 1 | "METRIC_NAME","2021-10-25","2021-10-26","2021-10-27","2021-10-28","2021-10-29","2021-10-30","2021-10-31","2021-11-01","2021-11-02","2021-11-03","2021-11-04","2021-11-05","2021-11-06","2021-11-07","2021-11-08","2021-11-09","2021-11-10","2021-11-11","2021-11-12","2021-11-13","2021-11-14","2021-11-15" 2 | "Instance Foreground CPU",3.06,1.58,1.22,1.39,1.14,0.81,0.6,0.76,0.54,0.6,0.7,0.76,0.69,0.76,0.64,0.87,0.78,0.48,0.44,0.45,0.44,0.5 3 | "Instance Background CPU",0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.06,0.07,0.07,0.07,0.07,0.07,0.07 4 | "Non-Database Host CPU",0.58,0.64,0.63,0.65,0.68,0.85,0.65,0.64,0.64,0.65,0.61,0.64,0.86,0.63,0.6,0.61,0.67,0.65,0.67,0.87,0.64,0.64 5 | "Load Average",4.45,2.73,2.38,2.53,2.77,2.11,1.46,1.72,1.43,1.5,1.57,1.86,2.59,1.79,1.59,1.85,1.78,1.3,1.58,1.57,1.24,1.33 6 | 7 | -------------------------------------------------------------------------------- /SCN/datafile_scn.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: datafile_scn.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Dec 21, 2020 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 10 | REM Purpose: 11 | REM This SQL script uses to check SCN number (in the column "checkpoint_change#" via the oracle 12 | REM dynamic performance view v$datafile) of current control file. 13 | REM 14 | 15 | SET PAGESIZE 50 16 | 17 | COLUMN checkpoint_change# FORMAT 99999999999999 18 | COLUMN resetlogs_change# FORMAT 99999999999999 19 | 20 | SELECT file#, checkpoint_change# FROM v$datafile ORDER BY 1; 21 | 22 | -- Give an example for checking the SCN number of current control file of oracle database. 23 | 24 | FILE# CHECKPOINT_CHANGE# 25 | ---------- ------------------ 26 | 1 21958785029 27 | 2 21958785029 28 | 3 21958785029 29 | 4 21958785029 30 | 5 21958785029 31 | 6 21958785029 32 | 7 21958785029 33 | 8 21958785029 34 | 9 21958785029 35 | 10 21958785029 36 | 11 21958785029 37 | 12 21958785029 38 | 13 21958785029 39 | 14 21958785029 40 | 15 21958785029 41 | 16 21958785029 42 | 17 21958785029 43 | 18 21958785029 44 | 19 21958785029 45 | 20 21958785029 46 | 21 21958785029 47 | 22 21958785029 48 | 23 21958785029 49 | 24 21958785029 50 | 25 21958785029 51 | 26 21958785029 52 | 27 21958785029 53 | 28 21958785029 54 | 29 21958785029 55 | 30 21958785029 56 | 31 21958785029 57 | 32 21958785029 58 | 33 21958785029 59 | 60 | 33 rows selected. 61 | -------------------------------------------------------------------------------- /ShinData/all_prod_users.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: all_prod_users.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Mar 29, 2023 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Listing all of production/business users of oracle database. 13 | REM 14 | 15 | -- how to exclude oracle internal user? 16 | -- https://stackoverflow.com/questions/37338237/list-of-all-the-user-excluding-default-users 17 | 18 | -- https://zhuanlan.zhihu.com/p/449512111 19 | 20 | -- 10g, 11g: 21 | 22 | SELECT username 23 | FROM dba_users 24 | MINUS 25 | SELECT username 26 | FROM dba_users 27 | WHERE created < (SELECT created FROM v$database) 28 | ORDER BY username; 29 | 30 | or 31 | 32 | SELECT username 33 | FROM dba_users 34 | WHERE created > (SELECT created FROM v$database) 35 | ORDER BY username; 36 | 37 | -- 12c and later: 38 | 39 | SELECT username 40 | FROM dba_users 41 | WHERE oracle_maintained = 'N' 42 | ORDER BY username; 43 | -------------------------------------------------------------------------------- /ShinData/arch_total_size_from_everyday.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: arch_total_size_from_everyday.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 14, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the geneated archive log total size (MB) from everyday on your oracle database. 13 | REM 14 | 15 | select trunc(completion_time) as ARC_DATE, 16 | count(*), 17 | round((sum(blocks * block_size) / 1024 / 1024), 2) as ARC_MB 18 | from v$archived_log 19 | group by trunc(completion_time) 20 | order by trunc(completion_time); 21 | -------------------------------------------------------------------------------- /ShinData/ash_activity_pct_by_top10sessions.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: ash_activity_pct_by_top10sessions.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking activity percent of top 10 sessions by cpu_time, user_io_time and other_wait_time 13 | REM from v$active_session_history in recent 1 hour on oracle database. 14 | REM 15 | 16 | SELECT * FROM ( 17 | SELECT ash.activity_pct, 18 | ash.session_id, 19 | u.username, 20 | ash.program 21 | FROM (SELECT round(100 * ratio_to_report(sum(1)) OVER (), 2) AS activity_pct, 22 | sum(1) AS db_time, 23 | sum(decode(session_state, 'ON CPU', 1, 0)) AS cpu_time, 24 | sum(decode(session_state, 'WAITING', decode(wait_class, 'User I/O', 1, 0), 0)) AS user_io_time, 25 | sum(decode(session_state, 'WAITING', 1, 0)) - sum(decode(session_state, 'WAITING', decode(wait_class, 'User I/O', 1, 0), 0)) AS wait_time, 26 | session_id, 27 | session_serial#, 28 | user_id, 29 | program 30 | FROM gv$active_session_history 31 | WHERE sample_time >= sysdate - INTERVAL '1' HOUR 32 | GROUP BY session_id, session_serial#, user_id, program 33 | ORDER BY activity_pct DESC 34 | ) ash, dba_users u 35 | WHERE ash.user_id = u.user_id 36 | ) WHERE rownum <= 30; 37 | -------------------------------------------------------------------------------- /ShinData/ash_activity_pct_by_top10sqls.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: ash_activity_pct_by_top10sqls.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 02, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking activity percent of top 10 sql statements by cpu_time, user_io_time and other_wait_time 13 | REM from v$active_session_history in recent 1 hour on oracle database. 14 | REM 15 | 16 | SELECT ash.activity_pct, 17 | ash.sql_id, 18 | ash.sql_opname 19 | FROM (SELECT round(100 * ratio_to_report(sum(1)) OVER (), 2) AS activity_pct, 20 | sum(1) AS db_time, 21 | sum(decode(session_state, 'ON CPU', 1, 0)) AS cpu_time, 22 | sum(decode(session_state, 'WAITING', decode(wait_class, 'User I/O', 1, 0), 0)) AS user_io_time, 23 | sum(decode(session_state, 'WAITING', 1, 0)) - sum(decode(session_state, 'WAITING', decode(wait_class, 'User I/O', 1, 0), 0)) AS wait_time, 24 | sql_id, 25 | sql_opname 26 | FROM gv$active_session_history 27 | WHERE sample_time >= sysdate - INTERVAL '1' HOUR 28 | AND sql_id IS NOT NULL 29 | GROUP BY sql_id, sql_opname 30 | ORDER BY activity_pct DESC 31 | ) ash 32 | WHERE rownum <= 30; 33 | -------------------------------------------------------------------------------- /ShinData/ash_counts_by_wait_class.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: ash_counts_by_wait_class.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 01, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking active session history counts by wait class in recent 1 hour on oracle database. 13 | REM 14 | 15 | SELECT trunc(sample_time, 'mi') sample_time, 16 | sum(decode(session_state, 'ON CPU', 1, 0)) AS "ON CPU", 17 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Scheduler', 1, 0), 0)) AS "Scheduler", 18 | sum(decode(session_state, 'WAITING', decode(wait_class, 'User I/O', 1, 0), 0)) AS "User I/O", 19 | sum(decode(session_state, 'WAITING', decode(wait_class, 'System I/O', 1, 0), 0)) AS "System I/O", 20 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Concurrency', 1, 0), 0)) AS "Concurrency", 21 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Application', 1, 0), 0)) AS "Application", 22 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Commit', 1, 0), 0)) AS "Commit", 23 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Configuration', 1, 0), 0)) AS "Configuration", 24 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Administrative', 1, 0), 0)) AS "Administrative", 25 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Network', 1, 0), 0)) AS "Network", 26 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Queueing', 1, 0), 0)) AS "Queueing", 27 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Cluster', 1, 0), 0)) AS "Cluster", 28 | sum(decode(session_state, 'WAITING', decode(wait_class, 'Other', 1, 0), 0)) AS "Other" 29 | FROM gv$active_session_history 30 | WHERE sample_time >= sysdate - INTERVAL '1' HOUR 31 | GROUP BY trunc(sample_time, 'mi') 32 | ORDER BY trunc(sample_time, 'mi'); 33 | -------------------------------------------------------------------------------- /ShinData/backup_files_by_piece.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: backup_files_by_piece.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 20, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking backup files by rman backup piece on oracle database. 13 | REM 14 | 15 | SELECT pkey, 16 | bs_tag, 17 | fname, 18 | completion_time, 19 | bs_type, 20 | bs_device_type, 21 | bs_status, 22 | compressed 23 | FROM v$backup_files 24 | WHERE obsolete = 'NO' 25 | AND file_type = 'PIECE' 26 | ORDER BY pkey; 27 | -------------------------------------------------------------------------------- /ShinData/buffer_cache_hit_ratio.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: buffer_cache_hit_ratio.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 05, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the buffer cache hit ratio (captured interval by 1 minute) in recent 1 hour on oracle database. 13 | REM 14 | 15 | SELECT inst_id, 16 | TO_CHAR(end_time, 'hh24:mi:ss') end_time, 17 | ROUND(value,2) AS "hit_ratio(%)" 18 | FROM gv$sysmetric_history 19 | WHERE metric_name = 'Buffer Cache Hit Ratio' 20 | AND ROUND(intsize_csec/100,0) = 60 21 | ORDER BY inst_id, end_time; 22 | -------------------------------------------------------------------------------- /ShinData/buffer_pool_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: buffer_pool_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 06, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the buffer pool size via block_size of oracle database. 13 | REM 14 | 15 | select inst_id, 16 | decode(block_size, 17 | 8192, 'DEFAULT 8K buffer cache', 18 | 16384, 'DEFAULT 16K buffer cache', 19 | 32768, 'DEFAULT 32K buffer cache' 20 | ) name, 21 | current_size size_mb 22 | from gv$buffer_pool 23 | order by inst_id, 24 | size_mb desc; 25 | -------------------------------------------------------------------------------- /ShinData/cdb_pdbs.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: cdb_pdbs.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 12, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking pdb basic info by connecting to cdb on oracle database. 13 | REM Note: You need to alter the c##monitor_user's permission in order to make it be able to check all pdbs. 14 | REM 15 | 16 | ALTER USER c##monitor_user SET container_data=all CONTAINER=current; 17 | 18 | SELECT con_id, 19 | name as pdbname, 20 | dbid, 21 | open_mode, 22 | restricted, 23 | open_time, 24 | block_size, 25 | total_size 26 | FROM v$pdbs; 27 | -------------------------------------------------------------------------------- /ShinData/check_dataguard_basic_info.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_dataguard_basic_info.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 11, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | 12 | set linesize 200 13 | 14 | col open_mode for a20 15 | col database_role for a18 16 | col protection_mode for a25 17 | col switchover_status for a20 18 | col protection_level for a25 19 | 20 | select inst_id, 21 | open_mode, 22 | database_role, 23 | switchover_status, 24 | protection_mode, 25 | protection_level 26 | from gv$database 27 | order by 1; 28 | -------------------------------------------------------------------------------- /ShinData/check_redo_log_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_redo_log_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 29, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the redo log size of oracle database. 13 | REM 14 | 15 | set linesize 120 16 | set pagesize 35 17 | 18 | set trim on 19 | set trims on 20 | 21 | col group# format 999 22 | col thread# format 999 23 | col member format a70 wrap 24 | col status format a10 25 | col archived format a10 26 | col fsize format 999 heading "Size (MB)" 27 | 28 | select l.group#, 29 | l.thread#, 30 | f.member, 31 | l.archived, 32 | l.status, 33 | (bytes/1024/1024) size_mb 34 | from v$log l, v$logfile f 35 | where f.group# = l.group# 36 | order by 1,2; 37 | 38 | -- group# thread# member archived status Size (MB) 39 | -- ------ ------- ---------------------------------------- -------- ------- --------- 40 | -- 1 1 /u01/app/oracle/oradata/orcl/redo01.log YES ACTIVE 50 41 | -- 2 1 /u01/app/oracle/oradata/orcl/redo02.log NO CURRENT 50 42 | -- 3 1 /u01/app/oracle/oradata/orcl/redo03.log YES ACTIVE 50 43 | -------------------------------------------------------------------------------- /ShinData/check_session_longops.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_session_longops.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Dec 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the oracle task running for a long time and the percentage of progress completed. 13 | REM 14 | 15 | set linesize 300 16 | set pagesize 100 17 | set trimspool on 18 | 19 | col message for a40 word_wrap 20 | col perc for 990.00 21 | col mins for 9,990.00 22 | 23 | alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'; 24 | 25 | select sid, 26 | serial#, 27 | start_time, 28 | time_remaining, 29 | round(time_remaining/60) as mins, 30 | round(sofar/totalwork, 2) * 100 as perc, 31 | message 32 | from v$session_longops 33 | where time_remaining > 0 34 | order by 1, 2, 3; 35 | -------------------------------------------------------------------------------- /ShinData/check_sql_commits.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_sql_commits.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 30, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking which sql statements of oracle database has the frequent commits. 13 | REM 14 | 15 | set linesize 1000 16 | 17 | column sid for 99999 18 | column program for a20 19 | column machine for a20 20 | column logon_time for date 21 | column wait_class for a10 22 | column event for a32 23 | column sql_id for 9999 24 | column prev_sql_id for 9999 25 | column WAIT_TIME for 9999 26 | column SECONDS_IN_WAIT for 9999 27 | 28 | with ucs as 29 | (select t1.sid, 30 | t1.value, 31 | t2.name 32 | from v$sesstat t1, v$statname t2 33 | where t2.name like '%user commits%' 34 | and t1.statistic# = t2.statistic# 35 | and t1.value >= 10000 36 | order by t1.value desc 37 | ), 38 | sqlid as 39 | (select s.sid, 40 | s.program, 41 | s.event, 42 | s.logon_time, 43 | s.wait_time, 44 | s.seconds_in_wait, 45 | s.sql_id, 46 | s.prev_sql_id 47 | from v$session s, ucs u 48 | where s.sid = u.sid 49 | ) 50 | select sa.sql_id, 51 | sa.sql_text, 52 | sa.executions, 53 | sa.first_load_time, 54 | sa.last_load_time 55 | from v$sqlarea sa, sqlid si 56 | where sa.sql_id = si.sql_id; 57 | -------------------------------------------------------------------------------- /ShinData/current_running_sqls.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: current_running_sqls.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 02, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the current running sql statements of oracle database. 13 | REM 14 | 15 | SELECT s.inst_id, 16 | s.sid, 17 | s.schemaname, 18 | s.serial# AS serial, 19 | s.machine, 20 | s.program, 21 | s.sql_id, 22 | t.sql_text, 23 | s.sql_exec_start, 24 | ceil((sysdate - s.sql_exec_start) * 24 * 60 * 60) AS sql_exec_time 25 | FROM gv$session s, gv$sqlstats t 26 | WHERE not exists (select * from (SELECT username 27 | FROM dba_users 28 | WHERE created < (SELECT created FROM v$database) 29 | ) u 30 | where s.schemaname = u.username 31 | ) 32 | AND s.sql_id IS NOT NULL 33 | AND s.status = 'ACTIVE' 34 | AND s.sql_id = t.sql_id 35 | AND s.inst_id = t.inst_id; 36 | -------------------------------------------------------------------------------- /ShinData/datafile_io_responsetime.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: datafile_io_responsetime.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 13, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the datafile io response time of oracle database. 13 | REM 14 | 15 | SELECT d.inst_id, 16 | d.name, 17 | f.phyrds, 18 | f.phyblkrd, 19 | f.phywrts, 20 | f.phyblkwrt, 21 | f.readtim*10 readtime, 22 | f.writetim*10 writetime 23 | FROM gv$datafile d, gv$filestat f 24 | WHERE d.file# = f.file# 25 | AND d.inst_id = f.inst_id 26 | ORDER BY f.phyrds DESC, 27 | f.phywrts DESC; 28 | -------------------------------------------------------------------------------- /ShinData/dg_gap_and_lag.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_gap_and_lag.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the gap and lag situation on oracle data guard physical standby database. 13 | REM 14 | 15 | with al_rfs as 16 | (select thread#, 17 | max(sequence#) max_seq, 18 | registrar, 19 | applied 20 | from v$archived_log 21 | where registrar = 'RFS' 22 | group by thread#, registrar, applied 23 | ), 24 | ag as 25 | (select thread#, 26 | low_sequence#, 27 | high_sequence# 28 | from v$archive_gap 29 | ), 30 | ds as 31 | (select inst_id, 32 | name, 33 | value, 34 | unit 35 | from gv$dataguard_stats 36 | where name like '%lag' 37 | ), 38 | al_rfs_ds as 39 | (select a.thread# stby_inst_id, 40 | a.thread# thread_number, 41 | a.max_seq stby_max_seq, 42 | a.registrar stby_registrar, 43 | a.applied stby_applied_status, 44 | b.name, 45 | b.value 46 | from al_rfs a, ds b 47 | ) 48 | select ad.stby_inst_id, 49 | ad.thread_number, 50 | ad.stby_max_seq, 51 | ad.stby_registrar, 52 | ad.stby_applied_status, 53 | nvl(ag.low_sequence#, 0) no_rec_low_sequence#, 54 | nvl(ag.high_sequence#, 0) no_rec_high_sequence#, 55 | nvl(ag.high_sequence#, 0) - nvl(ag.low_sequence#, 0) gap_nums, 56 | ad.name lag_type, 57 | ad.value lag_time 58 | from al_rfs_ds ad, ag 59 | where ad.thread_number = ag.thread#(+) 60 | order by ad.stby_inst_id, lag_type desc; 61 | -------------------------------------------------------------------------------- /ShinData/dg_gap_status.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_gap_status.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 24, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the gap status on oracle data guard primary database. 13 | REM 14 | 15 | set linesize 200 16 | 17 | col db_unique_name for a15 18 | col dest_name for a20 19 | col gap_status for a18 20 | 21 | WITH primary AS ( 22 | SELECT thread#, MAX(sequence#) maxsequence 23 | FROM v$archived_log 24 | WHERE archived = 'YES' 25 | AND resetlogs_change# = (SELECT d.resetlogs_change# FROM v$database d) 26 | GROUP BY thread# 27 | ORDER BY thread#), 28 | standby AS ( 29 | SELECT thread#, MAX(sequence#) maxsequence 30 | FROM v$archived_log 31 | WHERE applied = 'YES' 32 | AND resetlogs_change# = (SELECT d.resetlogs_change# FROM v$database d) 33 | GROUP BY thread# 34 | ORDER BY thread#), 35 | no_applied_seq AS ( 36 | SELECT primary.thread#, 37 | primary.maxsequence pry_arch_logseq, 38 | NVL(standby.maxsequence, 0) stby_apply_logseq, 39 | primary.maxsequence - NVL(standby.maxsequence, 0) no_applied_log 40 | FROM primary, standby 41 | WHERE primary.thread# = standby.thread#(+) 42 | ), 43 | gap_info AS ( 44 | SELECT inst_id, 45 | db_unique_name, 46 | dest_id, 47 | dest_name, 48 | status, 49 | gap_status 50 | FROM gv$archive_dest_status 51 | WHERE status = 'VALID' 52 | AND type = 'PHYSICAL') 53 | SELECT gi.inst_id, 54 | gi.db_unique_name, 55 | gi.dest_name, 56 | gi.status, 57 | gi.gap_status trans_gap, 58 | nas.pry_arch_logseq primary_seq, 59 | nas.stby_apply_logseq standby_seq, 60 | nas.no_applied_log applied_gap 61 | FROM no_applied_seq nas, gap_info gi 62 | WHERE nas.thread# = gi.inst_id 63 | ORDER BY gi.inst_id; 64 | -------------------------------------------------------------------------------- /ShinData/dg_messages.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_messages.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the messages on oracle data guard primary and physical standby database. 13 | REM 14 | 15 | select inst_id, 16 | timestamp, 17 | message 18 | from gv$dataguard_status 19 | order by inst_id, 20 | timestamp desc; 21 | -------------------------------------------------------------------------------- /ShinData/dg_mrp.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_mrp.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking "MRP_process_status" on oracle data guard physical standby database. 13 | REM 14 | 15 | set linesize 200 16 | set pagesize 30 17 | 18 | col key for a20 19 | col value for a15 20 | 21 | select 'MRP_process_status' key, 22 | (select status from gv$managed_standby where process like 'MRP%') value 23 | from dual; 24 | 25 | KEY VALUE 26 | -------------------- ------------------------------ 27 | MRP_process_status APPLYING_LOG 28 | 29 | or 30 | 31 | KEY VALUE 32 | -------------------- --------------- 33 | MRP_process_status WAIT_FOR_GAP 34 | 35 | or 36 | 37 | KEY VALUE 38 | -------------------- ------------------------------ 39 | MRP_process_status 40 | -------------------------------------------------------------------------------- /ShinData/dg_param_configuration.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_param_configuration.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the parameter configuration on oracle data guard primary and physical standby database. 13 | REM 14 | 15 | set linesize 200 16 | set pagesize 20 17 | col key for a25 18 | col value for a90 19 | select inst_id, 20 | name, 21 | value 22 | from gv$parameter 23 | where name = 'log_archive_config' 24 | union all 25 | select inst_id, 26 | name, 27 | value 28 | from gv$parameter 29 | where name like '%log_archive_dest_%' 30 | and name not like '%log_archive_dest_state%' 31 | and value is not null; 32 | 33 | -- or 34 | 35 | set linesize 200 36 | set pagesize 20 37 | col name for a25 38 | col value for a90 39 | with dg_par as 40 | (select name, value from v$parameter where name in ('log_archive_config', 'fal_server', 'fal_client', 'standby_file_management', 'db_file_name_convert', 'log_file_name_convert')), 41 | ladN as 42 | (select name, value from v$parameter where (name like 'log_archive_dest__' or name like 'log_archive_dest___') and value is not null), 43 | ladsN as 44 | (select name, value from v$parameter where name like 'log_archive_dest_state_%' and substr(name, 24) in (select substr(ladN.name, 18) from ladN)) 45 | select * from dg_par 46 | union all 47 | select * from ladN 48 | union all 49 | select * from ladsN 50 | order by 1; 51 | -------------------------------------------------------------------------------- /ShinData/dg_process_status.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_process_status.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the process status on oracle data guard primary and physical standby database. 13 | REM 14 | 15 | select inst_id, 16 | process, 17 | sequence#, 18 | status, 19 | delay_mins 20 | from gv$managed_standby 21 | order by inst_id, 22 | process; 23 | -------------------------------------------------------------------------------- /ShinData/dg_rec_apply_max_seq.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_rec_apply_max_seq.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking received and applied max log sequence of physical standby on oracle data guard primary database. 13 | REM 14 | 15 | with al_pry as 16 | (select thread#, 17 | max(sequence#) max_seq 18 | from v$archived_log 19 | group by thread# 20 | ), 21 | ads as 22 | (select dest_id, 23 | db_unique_name 24 | from v$archive_dest_status 25 | where type = 'PHYSICAL' and db_unique_name = lower('&&stby_db_uname') 26 | ), 27 | al_stby_ar as 28 | (select thread#, 29 | max(sequence#) max_seq 30 | from v$archived_log 31 | where dest_id in (select dest_id from v$archive_dest where target = 'STANDBY' and db_unique_name = lower('&&stby_db_uname')) 32 | and archived = 'YES' 33 | group by thread# 34 | ), 35 | al_stby_ap as 36 | (select thread#, 37 | max(sequence#) max_seq 38 | from v$archived_log 39 | where dest_id in (select dest_id from v$archive_dest where target = 'STANDBY' and db_unique_name = lower('&&stby_db_uname')) 40 | and applied = 'YES' 41 | group by thread# 42 | ) 43 | select p.thread# pry_inst_id, 44 | p.max_seq pry_max_seq, 45 | ads.db_unique_name stby_db_uname, 46 | ar.max_seq stby_rec_max_seq, 47 | ap.max_seq stby_app_max_seq 48 | from al_pry p, ads, al_stby_ar ar, al_stby_ap ap 49 | where p.thread# = ar.thread# 50 | and ar.thread# = ap.thread#(+) 51 | order by p.thread#; 52 | -------------------------------------------------------------------------------- /ShinData/dg_redo_apply_rate.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: dg_redo_apply_rate.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Dec 10, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM The SQL script uses to check redo apply rate on oracle data guard physical standby database. 13 | REM 14 | 15 | set linesize 200 16 | col start_time format a20 17 | col type format a16 18 | col item format a20 19 | col sofar format 99999 20 | col units format a7 21 | 22 | SELECT start_time, 23 | type, 24 | item, 25 | sofar, 26 | units 27 | FROM v$recovery_progress 28 | WHERE LOWER(item) LIKE '%apply%' 29 | AND units = 'KB/sec' 30 | ORDER BY start_time desc, item; 31 | -------------------------------------------------------------------------------- /ShinData/is(a)dg_unqname.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: is(a)dg_unqname.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking "IsDG", "IsADG", "DG Primary Uname" and "DG Physical standby Uname" on oracle data guard primary database. 13 | REM 14 | 15 | set linesize 200 16 | set pagesize 20 17 | col key for a25 18 | col value for a25 19 | 20 | with dgpry as 21 | (select 'DG Primary Uname' key, 22 | value 23 | from v$parameter where name = 'db_unique_name' 24 | ), 25 | dgstby as 26 | (select 'DG Physical standby Uname' key, 27 | db_unique_name value 28 | from v$archive_dest 29 | where target = 'STANDBY' 30 | ), 31 | listagg_dgstby as 32 | (select key, 33 | listagg(value, ',') within group(order by value) value 34 | from dgstby 35 | group by key 36 | ), 37 | isdg as 38 | (select 'IsDG' key, 39 | (case when (select value from listagg_dgstby) is not null then 'yes' 40 | when (select value from listagg_dgstby) is null then 'no' 41 | end 42 | ) value 43 | from dual 44 | ), 45 | isadg as 46 | (select distinct 'IsADG' key, 47 | decode(database_mode, 'MOUNTED-STANDBY', 'no', 'OPEN_READ-ONLY', 'yes') value 48 | from v$archive_dest_status 49 | where type = 'PHYSICAL' 50 | and lower(db_unique_name) in (select lower(db_unique_name) from v$archive_dest where target = 'STANDBY') 51 | ) 52 | select * from isdg 53 | union all 54 | select * from isadg 55 | union all 56 | select * from dgpry 57 | union all 58 | select * from listagg_dgstby; 59 | 60 | KEY VALUE 61 | ------------------------- ------------------------- 62 | IsDG yes 63 | IsADG no 64 | DG Primary Uname yydsdb 65 | DG Physical standby Uname yydsdbdg07 66 | -------------------------------------------------------------------------------- /ShinData/isadg.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: isadg.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 18, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking "IsADG" on oracle data guard physical standby database. 13 | REM 14 | 15 | set linesize 200 16 | set pagesize 30 17 | col key for a5 18 | col value for a5 19 | 20 | select 'IsADG' key, 21 | decode(open_mode, 'MOUNTED', 'no', 'READ ONLY', 'yes') value 22 | from v$database; 23 | 24 | KEY VALUE 25 | ----- ----- 26 | IsADG no 27 | -------------------------------------------------------------------------------- /ShinData/kill_sessions_base_on_sqlid.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: kill_sessions_base_on_sqlid.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 15, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM The SQL script uses to immediately kill sessions from the same sql_id of oracle database. 13 | REM You know, sql_id 'a8fdq2kj0rmz7' comes from a specific sql. 14 | REM 15 | 16 | declare 17 | v_sid v$session.sid%type; 18 | v_serial# v$session.serial#%type; 19 | cursor cur_session is select sid, serial# from v$session where sql_id = 'a8fdq2kj0rmz7'; 20 | begin 21 | open cur_session; 22 | loop 23 | fetch cur_session into v_sid,v_serial#; 24 | execute immediate 'alter system kill session '''||v_sid||','||v_serial#||''' immediate'; 25 | exit when cur_session%notfound; 26 | dbms_output.put_line('cursor date have been fetched ending'); 27 | end loop; 28 | close cur_session; 29 | end; 30 | / 31 | -------------------------------------------------------------------------------- /ShinData/kill_sessions_by_row_lock.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: kill_sessions_by_row_lock.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Generating kill session statements of row lock on oracle database. 13 | REM 14 | 15 | select 'alter system kill session ''' || s.sid ||',' || s.serial# || ''';' kill_session 16 | from v$process p, v$session s, v$locked_object l, dba_objects o 17 | where p.addr = s.paddr 18 | and s.sid = l.session_id 19 | and l.object_id = o.object_id; 20 | 21 | -- alter system kill session '1153,45130'; 22 | -- alter system kill session '401,48708'; 23 | -- alter system kill session '1169,10379'; 24 | -------------------------------------------------------------------------------- /ShinData/lock_waitevent.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: lock_waitevent.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jun 21, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking lock related wait event situation in recent 1 hour on oracle database. 13 | REM 14 | 15 | SELECT inst_id, 16 | TRUNC(sample_time, 'mi') sample_time, 17 | event, 18 | COUNT(*) AS wait_count 19 | FROM gv$active_session_history 20 | WHERE event IN ('enq: TX - row lock contention', 'row cache lock', 'library cache lock', 'enq: TM - contention', 'library cache pin') 21 | AND session_type = 'FOREGROUND' 22 | AND sample_time BETWEEN sysdate - INTERVAL '1' HOUR AND sysdate 23 | GROUP BY inst_id, 24 | TRUNC(sample_time, 'mi'), 25 | event 26 | ORDER BY inst_id, 27 | sample_time, 28 | event; 29 | -------------------------------------------------------------------------------- /ShinData/log_buffer_space_avg_wait_time.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: log_buffer_space_avg_wait_time.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 29, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Finding out average wait time (ms) of wait event 'log buffer space' 13 | REM in recent 1 hour from view gv$active_session_history of oracle database. 14 | REM 15 | 16 | set linesize 200 17 | set pagesize 100 18 | 19 | column sample_time format a19 20 | column event format a30 21 | 22 | select to_char(sample_time,'yyyy-mm-dd hh24:mi:ss') sample_time, 23 | inst_id, 24 | event, 25 | sum(time_waited)/1000 TOTAL_WAIT_TIME, 26 | count(*) WAITS, 27 | avg(time_waited)/1000 AVG_TIME_WAITED 28 | from gv$active_session_history 29 | where sample_time >= SYSDATE - INTERVAL '60' minute 30 | and event = 'log buffer space' 31 | group by to_char(sample_time,'yyyy-mm-dd hh24:mi:ss'), 32 | inst_id, 33 | event 34 | order by 1,2; 35 | -------------------------------------------------------------------------------- /ShinData/log_file_avg_wait_time.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: log_file_avg_wait_time.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 27, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Finding out average wait time (ms) of wait event 'log file sync' and 'log file parallel write' 13 | REM in recent 1 hour from view gv$active_session_history of oracle database. 14 | REM 15 | 16 | set linesize 200 17 | set pagesize 100 18 | 19 | column sample_time format a19 20 | column event format a30 21 | 22 | select to_char(sample_time,'yyyy-mm-dd hh24:mi:ss') sample_time, 23 | inst_id, 24 | event, 25 | sum(time_waited)/1000 TOTAL_WAIT_TIME, 26 | count(*) WAITS, 27 | avg(time_waited)/1000 AVG_TIME_WAITED 28 | from gv$active_session_history 29 | where sample_time >= SYSDATE - INTERVAL '60' minute 30 | and event in ('log file sync', 'log file parallel write') 31 | group by to_char(sample_time,'yyyy-mm-dd hh24:mi:ss'), 32 | inst_id, 33 | event 34 | order by 1,2; 35 | 36 | -- SAMPLE_TIME INST_ID EVENT TOTAL_WAIT_TIME WAITS AVG_TIME_WAITED 37 | -- -------------------- ---------- ------------------------------ --------------- ---------- --------------- 38 | -- 2022-10-26 08:39:52 1 log file sync 0 1 0 39 | -- 2022-10-26 08:46:36 1 log file sync 0 1 0 40 | -- 2022-10-26 09:06:13 1 log file sync 5.233 1 5.233 41 | -------------------------------------------------------------------------------- /ShinData/max_connections_from_sqlid.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: max_connections_from_sqlid.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 29, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Finding out which sql_id occupied the max connections from view v$session of oracle database. 13 | REM 14 | 15 | select * from ( 16 | select username, 17 | machine, 18 | sql_id, 19 | count(*) 20 | from v$session 21 | group by username, 22 | machine, 23 | sql_id 24 | order by count(*) desc 25 | ) where rownum <= 20; 26 | -------------------------------------------------------------------------------- /ShinData/oracle_built-in_username.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: oracle_built-in_username.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 01, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the built-in username of oracle database. 13 | REM 14 | 15 | SSELECT DISTINCT name 16 | FROM (SELECT cid, cname, schema# 17 | FROM registry$ 18 | UNION ALL 19 | SELECT a.cid, cname, b.schema# 20 | FROM registry$ a, registry$schemas b 21 | WHERE a.cid = b.cid 22 | ) c, user$ d 23 | WHERE c.schema# = d.user#; 24 | 25 | or 26 | 27 | SELECT username 28 | FROM dba_users 29 | WHERE created < (SELECT created FROM v$database); 30 | -------------------------------------------------------------------------------- /ShinData/params_all.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_all.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 01, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking all of the parameters of oracle database. 13 | REM 14 | 15 | select name, 16 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 17 | value, 18 | description 19 | from v$parameter 20 | order by name; 21 | -------------------------------------------------------------------------------- /ShinData/params_basic.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_basic.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 02, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the basic parameters (not recommending to modify) of oracle database. 13 | REM 14 | 15 | select name, 16 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 17 | ismodified, 18 | value, 19 | description 20 | from v$parameter where isbasic = 'TRUE' 21 | order by name; 22 | -------------------------------------------------------------------------------- /ShinData/params_default.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_default.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 05, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the default parameters of oracle database. 13 | REM 14 | 15 | -- 11.2, only having value. 16 | -- https://docs.oracle.com/cd/E11882_01/server.112/e40402/dynviews_2087.htm#REFRN30176 17 | 18 | -- from 12.1, having default_value, value is reserved. 19 | -- https://docs.oracle.com/database/121/REFRN/GUID-C86F3AB0-1191-447F-8EDF-4727D8693754.htm#REFRN30176 20 | 21 | select name, 22 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 23 | value, 24 | description 25 | from v$parameter where isdefault = 'TRUE' 26 | order by name; 27 | -------------------------------------------------------------------------------- /ShinData/params_dynamic.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_dynamic.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 04, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the dynamic parameters of oracle database. 13 | REM 14 | 15 | -- Those parameters taking effect on system level: 16 | 17 | select name, 18 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 19 | value, 20 | description 21 | from v$parameter where issys_modifiable = 'IMMEDIATE' 22 | order by name; 23 | 24 | -- Those parameters taking effect on session level: 25 | 26 | select name, 27 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 28 | value, 29 | description 30 | from v$parameter where isses_modifiable = 'TRUE' 31 | order by name; 32 | -------------------------------------------------------------------------------- /ShinData/params_not_default.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_not_default.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 08, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the current value (not default by modified) of parameters of oracle database. 13 | REM 14 | 15 | -- on 10g, 11g: 16 | 17 | select name, 18 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 19 | value, -- here 20 | description 21 | from v$parameter where isdefault = 'FALSE' 22 | order by name; 23 | 24 | -- from 12g: 25 | 26 | select name, 27 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 28 | value current_value, -- here 29 | default_value, -- here 30 | description 31 | from v$parameter where isdefault = 'FALSE' 32 | order by name; 33 | -------------------------------------------------------------------------------- /ShinData/params_pdb.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_pdb.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 09, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the oracle database parameter value that is able to be modified on pdb level. 13 | REM 14 | 15 | 12c: 16 | 17 | select name, 18 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 19 | value, 20 | description 21 | from v$parameter where ispdb_modifiable = 'TRUE' 22 | order by name; 23 | -------------------------------------------------------------------------------- /ShinData/params_static.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: params_static.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the static parameters of oracle database. 13 | REM 14 | 15 | -- ISMODIFIED = 'MODIFIED' --> isses_modifiable = 'FALSE' 16 | -- ISMODIFIED = 'SYSTEM_MOD' --> issys_modifiable = 'FALSE' 17 | -- isses_modifiable = 'FALSE' or issys_modifiable = 'FALSE' 18 | 19 | select name, 20 | decode(type, 1, 'Boolean', 2, 'String', 3, 'Integer', 4, 'Parameter file', 5, 'Reserved', 6, 'Big integer') type, 21 | value, 22 | description 23 | from v$parameter where ismodified = 'FALSE' 24 | order by name; 25 | -------------------------------------------------------------------------------- /ShinData/pga_used_rate.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: pga_used_rate.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 04, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the pga used rate of oracle database. 13 | REM 14 | 15 | select pt.inst_id, 16 | 'PGA' name, 17 | round(pt.total, 2) total, 18 | round(pu.used, 2) used, 19 | round(pu.used/pt.total*100, 2) pctused 20 | from (select inst_id, 21 | value/1024/1024 total 22 | from gv$pgastat where name = 'aggregate PGA target parameter' 23 | order by inst_id 24 | ) pt, 25 | (select inst_id, 26 | value/1024/1024 used 27 | from gv$pgastat where name = 'total PGA allocated' 28 | order by inst_id 29 | ) pu 30 | where pt.inst_id = pu.inst_id; 31 | -------------------------------------------------------------------------------- /ShinData/pga_used_rate_hist.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: pga_used_rate_hist.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jun 26, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the pga used rate from history of oracle database. 13 | REM 14 | 15 | with pga_total as ( 16 | select sn.instance_number, 17 | sn.snap_id, 18 | to_char(cast(sn.end_interval_time as date), 'yyyy-mm-dd hh24:mi:ss') snap_date_time, 19 | pgs.value/1024/1024 total 20 | from dba_hist_pgastat pgs, dba_hist_snapshot sn 21 | where pgs.instance_number = sn.instance_number 22 | and pgs.snap_id = sn.snap_id 23 | and pgs.name = 'aggregate PGA target parameter' 24 | ), 25 | pga_used as ( 26 | select sn.instance_number, 27 | sn.snap_id, 28 | to_char(cast(sn.end_interval_time as date), 'yyyy-mm-dd hh24:mi:ss') snap_date_time, 29 | pgs.value/1024/1024 used 30 | from dba_hist_pgastat pgs, dba_hist_snapshot sn 31 | where pgs.instance_number = sn.instance_number 32 | and pgs.snap_id = sn.snap_id 33 | and pgs.name = 'total PGA allocated' 34 | ) 35 | select pt.instance_number, 36 | pt.snap_id, 37 | pt.snap_date_time, 38 | 'PGA' name, 39 | round(pt.total, 2) total, 40 | round(pu.used, 2) used, 41 | round(pu.used/pt.total*100, 2) pctused 42 | from pga_total pt, pga_used pu 43 | where pt.instance_number = pu.instance_number 44 | and pt.snap_id = pu.snap_id 45 | order by pt.instance_number, 46 | pt.snap_id, 47 | pt.snap_date_time; 48 | -------------------------------------------------------------------------------- /ShinData/rman_async_io.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: rman_async_io.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: DEC 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the async io situation during the period of rman backup on your oracle database. 13 | REM 14 | 15 | SELECT device_type device, 16 | type, 17 | filename, 18 | to_char(open_time, 'yyyymmdd hh24:mi:ss') open, 19 | to_char(close_time, 'yyyymmdd hh24:mi:ss') close, 20 | maxopenfiles, 21 | elapsed_time elapse, 22 | bytes, 23 | io_count, 24 | short_waits, 25 | long_waits, 26 | effective_bytes_per_second e_bytes 27 | FROM v$backup_async_io 28 | WHERE close_time > SYSDATE - 1 29 | AND type = 'AGGREGATE' 30 | ORDER BY close_time DESC; 31 | -------------------------------------------------------------------------------- /ShinData/rman_backup_job_details.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: rman_backup_job_details.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: DEC 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the rman backup job details on your oracle database. 13 | REM 14 | 15 | select input_type, 16 | status, 17 | to_char(start_time,'yyyy-mm-dd hh24:mi:ss') start_time, 18 | to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') end_time, 19 | time_taken_display, 20 | input_bytes_display, 21 | output_bytes_display, 22 | input_bytes_per_sec_display, 23 | output_bytes_per_sec_display 24 | from v$rman_backup_job_details 25 | order by 3 desc; 26 | 27 | set linesize 400 28 | set pagesize 300 29 | col TIME_TAKEN_DISPLAY for a10 30 | col INPUG_SIZE for a10 31 | col OUTPUG_SIZE for a10 32 | col "output/s" for a10 33 | col status for a10 34 | col OUT_P for a5 35 | select start_time, 36 | time_taken_display, 37 | status, 38 | input_type, 39 | output_device_type OUT_P, 40 | input_bytes_display INPUG_SIZE, 41 | output_bytes_display OUTPUG_SIZE, 42 | output_bytes_per_sec_display as "output/s" 43 | from v$rman_backup_job_details 44 | order by start_time desc; 45 | -------------------------------------------------------------------------------- /ShinData/row_lock_contention.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: row_lock_contention.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking oracle database has been produced row lock in recent 1 hour. 13 | REM 14 | 15 | SELECT event, 16 | wait_class, 17 | session_state, 18 | blocking_session, 19 | blocking_session_serial#, 20 | count(*) 21 | FROM v$active_session_history 22 | WHERE sample_time BETWEEN sysdate - interval '60' minute AND sysdate 23 | AND event = 'enq: TX - row lock contention' 24 | GROUP BY event, 25 | wait_class, 26 | session_state, 27 | blocking_session, 28 | blocking_session_serial# 29 | ORDER BY count(*) DESC, event; 30 | -------------------------------------------------------------------------------- /ShinData/scheduler_jobs.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: scheduler_jobs.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Dec 30, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking all of the jobs situation with scheduler using the view dba_scheduler_jobs of oracle database. 13 | REM 14 | 15 | SELECT JOB_NAME, 16 | OWNER, 17 | to_char(NEXT_RUN_DATE, 'yyyy-MM-dd HH:mi:ss') as NEXT_RUN_DATE, 18 | to_char(LAST_START_DATE, 'yyyy-MM-dd HH:mi:ss') as LAST_START_DATE, 19 | STATE, 20 | ENABLED, 21 | JOB_CLASS, 22 | RUN_COUNT, 23 | SCHEDULE_OWNER, 24 | SCHEDULE_NAME, 25 | DECODE(BITAND(FLAGS, 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 2 + 1), 512, 'PLSQL_EXPR', 1024, 'NAMED', 26 | 1024 + 1, 'NON_EXIST', 2048, 'CALENDAR_STRING', 4096, 'WINDOW', 4096 + 2, 'WINDOW_GROUP', 8192, 27 | 'ONCE', 16384, 'NOW', '') AS SCHEDULE_TYPE 28 | FROM DBA_SCHEDULER_JOBS 29 | WHERE JOB_SUBNAME IS NULL; 30 | -------------------------------------------------------------------------------- /ShinData/sessions_and_objects_by_row_lock.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sessions_and_objects_by_row_lock.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Finding out sessions and objects that caused row lock in recent 1 hour on oracle database. 13 | REM 14 | 15 | select * from ( 16 | select to_char(h.sample_time,'yyyy-mm-dd hh24:mi:ss') sample_time, 17 | h.inst_id, 18 | h.session_id, 19 | h.session_serial#, 20 | h.machine, 21 | h.program, 22 | h.current_obj#, 23 | o.object_name, 24 | o.object_type, 25 | h.blocking_session, 26 | h.blocking_session_serial#, 27 | h.blocking_inst_id 28 | from gv$active_session_history h, dba_objects o 29 | where h.current_obj# = o.object_id 30 | and h.sample_time between sysdate - INTERVAL '60' minute and sysdate 31 | and h.event = 'enq: TX - row lock contention' 32 | order by 1 desc, 2 33 | ) where rownum <= 30; 34 | -------------------------------------------------------------------------------- /ShinData/sessions_blocking_chains.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sessions_blocking_chains.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking which sessions (including all blockers and waiters) caused blocking chains on oracle database. 13 | REM 14 | 15 | select inst_id, 16 | sid, 17 | serial, 18 | event, 19 | status, 20 | tree, 21 | tree_level 22 | from (select a.inst_id, 23 | a.sid, 24 | a.serial# as serial, 25 | a.sql_id, 26 | a.event, 27 | a.status, 28 | connect_by_isleaf as isleaf, 29 | sys_connect_by_path(a.sid||','||a.serial#||'@'||a.inst_id, ' <- ') tree, 30 | level as tree_level 31 | from gv$session a 32 | start with a.blocking_session is not null 33 | connect by (a.sid||'@'||a.inst_id) = prior (a.blocking_session||'@'||a.blocking_instance) 34 | ) t 35 | where sql_id is null 36 | order by tree_level asc; 37 | 38 | -- 1 1153 45130 SQL*Net message from client INACTIVE <- 401,48708@1 <- 1153,45130@1 2 39 | -- 1 1153 45130 SQL*Net message from client INACTIVE <- 1169,10379@1 <- 1153,45130@1 2 40 | -------------------------------------------------------------------------------- /ShinData/sessions_by_row_lock.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sessions_by_row_lock.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking which sessions (including all blockers and waiters) caused row lock on oracle database. 13 | REM If you run the OS command "netstat -anp | grep 'spid'" you are able to find out the ip address of the connect session. 14 | REM 15 | 16 | select p.spid, 17 | s.sid, 18 | s.serial#, 19 | l.oracle_username, 20 | s.machine, 21 | s.program, 22 | o.object_name 23 | from v$process p, v$session s, v$locked_object l, dba_objects o 24 | where p.addr = s.paddr 25 | and s.sid = l.session_id 26 | and l.object_id = o.object_id; 27 | -------------------------------------------------------------------------------- /ShinData/sga_used_rate.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sga_used_rate.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 04, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the sga used rate of oracle database. 13 | REM 14 | 15 | select st.inst_id, 16 | 'SGA' name, 17 | round(st.total, 2) total, 18 | round(st.total-sf.free, 2) used, 19 | round((st.total-sf.free)/st.total*100, 2) pctused 20 | from (select inst_id, 21 | sum(value)/1024/1024 total from gv$sga 22 | group by inst_id 23 | order by inst_id 24 | ) st, 25 | (select inst_id, 26 | sum(bytes)/1024/1024 free from gv$sgastat where name='free memory' 27 | group by inst_id 28 | order by inst_id 29 | ) sf 30 | where st.inst_id = sf.inst_id; 31 | -------------------------------------------------------------------------------- /ShinData/sga_used_rate_hist.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sga_used_rate_hist.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jun 26, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the sga used rate from history of oracle database. 13 | REM 14 | 15 | with sga_total as ( 16 | select sn.instance_number, 17 | sn.snap_id, 18 | to_char(cast(sn.end_interval_time as date), 'yyyy-mm-dd hh24:mi:ss') snap_date_time, 19 | sum(sg.value)/1024/1024 total 20 | from dba_hist_sga sg, dba_hist_snapshot sn 21 | where sg.instance_number = sn.instance_number 22 | and sg.snap_id = sn.snap_id 23 | group by sn.instance_number, 24 | sn.snap_id, 25 | to_char(cast(sn.end_interval_time as date), 'yyyy-mm-dd hh24:mi:ss') 26 | ), 27 | sga_free as ( 28 | select sn.instance_number, 29 | sn.snap_id, 30 | to_char(cast(sn.end_interval_time as date), 'yyyy-mm-dd hh24:mi:ss') snap_date_time, 31 | sum(sgs.bytes)/1024/1024 free 32 | from dba_hist_sgastat sgs, dba_hist_snapshot sn 33 | where sgs.instance_number = sn.instance_number 34 | and sgs.snap_id = sn.snap_id 35 | and sgs.name = 'free memory' 36 | group by sn.instance_number, 37 | sn.snap_id, 38 | to_char(cast(sn.end_interval_time as date), 'yyyy-mm-dd hh24:mi:ss') 39 | ) 40 | select st.instance_number, 41 | st.snap_id, 42 | st.snap_date_time, 43 | 'SGA' name, 44 | round(st.total, 2) total, 45 | round(st.total-sf.free, 2) used, 46 | round((st.total-sf.free)/st.total * 100, 2) pctused 47 | from sga_total st, sga_free sf 48 | where st.instance_number = sf.instance_number 49 | and st.snap_id = sf.snap_id 50 | order by st.instance_number, 51 | st.snap_id, 52 | st.snap_date_time; 53 | -------------------------------------------------------------------------------- /ShinData/sql_by_hist_row_lock.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sql_by_hist_row_lock.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking which sql statements caused history row lock in recent 1 hour on oracle database. 13 | REM 14 | 15 | select distinct h.inst_id, 16 | h.sql_id, 17 | substr(s.sql_text, 0, 1000) as sql_text 18 | from gv$active_session_history h, v$sqlstats s 19 | where h.sql_id = s.sql_id 20 | and h.sample_time between sysdate - INTERVAL '60' minute and sysdate 21 | and h.event = 'enq: TX - row lock contention' 22 | order by 1, 2; 23 | -------------------------------------------------------------------------------- /ShinData/sql_by_row_lock.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sql_by_row_lock.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 03, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking which sql statements (including all blockers and waiters) caused row lock on oracle database. 13 | REM 14 | 15 | -- Row Lock by Waiters: 16 | 17 | SELECT distinct s.SQL_ID, 18 | substr(t.SQL_TEXT,0,1000) as sql_text 19 | FROM gv$session s, gv$lock l, gv$LOCKED_OBJECT lo, dba_objects do, v$sqlstats t 20 | WHERE s.blocking_session IS NOT NULL 21 | AND s.BLOCKING_INSTANCE = l.inst_id 22 | AND s.blocking_session = l.sid 23 | AND t.SQL_ID = s.SQL_ID 24 | AND l.block > 0 25 | AND s.sid = lo.session_id 26 | AND lo.object_id = do.object_id; 27 | 28 | -- Row Lock by Blockers: 29 | 30 | SELECT distinct s.SQL_ID, 31 | substr(t.SQL_TEXT,0,1000) as sql_text 32 | FROM gv$session s, gv$lock l, gv$LOCKED_OBJECT lo, dba_objects do, v$sqlstats t 33 | WHERE s.blocking_session IS NULL 34 | AND s.BLOCKING_INSTANCE = l.inst_id 35 | AND s.blocking_session = l.sid 36 | AND t.SQL_ID = s.SQL_ID 37 | AND l.block > 0 38 | AND s.sid = lo.session_id 39 | AND lo.object_id = do.object_id; 40 | -------------------------------------------------------------------------------- /ShinData/sql_tuning_advisor_report.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: sql_tuning_advisor_report.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 25, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM The SQL script uses to generate and check Oracle SQL Tuning Advisor Report. 13 | REM You know, sql_id '4d8svnv5rvtws' comes from a specific sql. 14 | REM 15 | 16 | SET SERVEROUTPUT ON 17 | 18 | DECLARE 19 | my_task_name VARCHAR2(30); 20 | BEGIN 21 | my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_id => '4d8svnv5rvtws', 22 | scope => 'COMPREHENSIVE', 23 | time_limit => 3600, 24 | task_name => 'sql_tuning_4d8svnv5rvtws', 25 | description => 'SQL TUNE ADVISOR REPORT'); 26 | DBMS_SQLTUNE.EXECUTE_TUNING_TASK(task_name => 'sql_tuning_4d8svnv5rvtws'); 27 | END; 28 | / 29 | 30 | SET LONG 100000000 31 | SET LONGCHUNKSIZE 1000 32 | SET LINESIZE 300 33 | 34 | SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('sql_tuning_4d8svnv5rvtws') FROM DUAL; 35 | -------------------------------------------------------------------------------- /ShinData/table_fragment.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: table_fragment.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 12, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the table fragment situation of oracle database. 13 | REM 14 | 15 | SELECT owner, 16 | table_name, 17 | tablespace_name, 18 | partitioned, 19 | num_rows, 20 | round((blocks * 8) / 1024, 2) AS hwmmb, 21 | round((num_rows * avg_row_len / 1024) / 1024, 2) AS actualusedmb, 22 | round((blocks * 10 / 100) / 1024 * 8, 2) AS pctfreemb, 23 | round((blocks * 8 - (num_rows * avg_row_len / 1024) - blocks * 8 * 10 / 100) / 1024, 2) AS wastemb 24 | FROM dba_tables 25 | WHERE temporary = 'N' 26 | AND round((blocks * 8 - (num_rows * avg_row_len / 1024) - blocks * 8 * 10 / 100), 2) > 10240 27 | AND num_rows > 100000 28 | AND NOT EXISTS (SELECT * FROM (SELECT username 29 | FROM dba_users 30 | WHERE created < (SELECT created FROM v$database) 31 | ) u 32 | WHERE dba_tables.owner = u.username 33 | ); 34 | -------------------------------------------------------------------------------- /ShinData/table_stale_statistics.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: table_stale_statistics.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 15, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking which tables have been stale statistics on oracle database. 13 | REM 14 | 15 | SELECT OWNER, 16 | TABLE_NAME, 17 | PARTITION_NAME, 18 | NUM_ROWS, 19 | BLOCKS, 20 | CHAIN_CNT, 21 | SAMPLE_SIZE, 22 | LAST_ANALYZED, 23 | STALE_STATS 24 | FROM DBA_TAB_STATISTICS 25 | WHERE STALE_STATS = 'YES' 26 | AND NOT EXISTS (SELECT * FROM (SELECT username 27 | FROM dba_users 28 | WHERE created < (SELECT created FROM v$database) 29 | ) u 30 | WHERE DBA_TAB_STATISTICS.OWNER = u.USERNAME 31 | ); 32 | -------------------------------------------------------------------------------- /ShinData/tablespace_fragment.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: tablespace_fragment.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 11, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the fragment situation of a specific tablespace (whose used rate >= 75%) on oracle database. 13 | REM 14 | 15 | SELECT a.tablespace_name, 16 | ROUND(SQRT(MAX(a.blocks)/SUM(a.blocks))*(100/SQRT(SQRT(COUNT(a.blocks)))), 2) FSFI 17 | FROM dba_free_space a, dba_tablespaces b 18 | WHERE a.tablespace_name = b.tablespace_name 19 | AND b.contents = 'PERMANENT' 20 | AND a.tablespace_name IN (SELECT a.tablespace_name 21 | FROM dba_tablespaces a 22 | LEFT JOIN (SELECT tablespace_name, SUM(bytes) used_size 23 | FROM DBA_SEGMENTS 24 | WHERE segment_name NOT LIKE 'BIN$%' 25 | GROUP BY tablespace_name 26 | ) b ON a.tablespace_name = b.tablespace_name 27 | LEFT JOIN (SELECT tablespace_name, 28 | sum(case autoextensible when 'YES' then maxbytes else bytes end) AS sum_maxspace 29 | FROM dba_data_files 30 | GROUP BY tablespace_name 31 | ) c ON a.tablespace_name = c.tablespace_name 32 | WHERE a.contents = 'PERMANENT' 33 | AND round(nvl(b.used_size, 0)/c.sum_maxspace*100, 2) >= 75 34 | ) 35 | GROUP BY a.tablespace_name 36 | ORDER BY 2; 37 | -------------------------------------------------------------------------------- /ShinData/top10_hot_tables.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_hot_tables.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 08, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 hot tables that have been most frequently inserted, updated and deleted 13 | REM from dba_tab_modifications of oracle database. 14 | REM 15 | 16 | SELECT * FROM ( 17 | SELECT b.owner, 18 | b.table_name, 19 | b.segment_name, 20 | b.tablespace_name, 21 | h.inserts + h.updates + h.deletes AS h_sum, 22 | h.inserts, 23 | h.updates, 24 | h.deletes 25 | FROM ( 26 | SELECT t.owner, 27 | t.table_name, 28 | t.tablespace_name, 29 | t.num_rows, 30 | nvl(t.cluster_name, t.table_name) AS segment_name, 31 | t.partitioned, 32 | t.monitoring 33 | FROM dba_tables t 34 | WHERE NOT EXISTS (SELECT * FROM (SELECT username 35 | FROM dba_users 36 | WHERE created < (SELECT created FROM v$database) 37 | ) u 38 | WHERE t.owner = u.username 39 | ) 40 | ) b, 41 | ( 42 | SELECT table_name, 43 | SUM(inserts) AS inserts, 44 | SUM(updates) AS updates, 45 | SUM(deletes) AS deletes 46 | FROM dba_tab_modifications 47 | GROUP BY table_name 48 | ) h 49 | WHERE b.table_name = h.table_name 50 | ORDER BY h_sum DESC 51 | ) WHERE ROWNUM <= 10; 52 | -------------------------------------------------------------------------------- /ShinData/top10_index_partitions_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_index_partitions_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 02, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 index partitions that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | size_gb, 21 | rownum rn 22 | from (select owner, 23 | segment_name, 24 | round(sum(bytes/1024/1024/1024), 4) as size_gb 25 | from dba_segments 26 | where segment_type = 'INDEX PARTITION' 27 | and not exists (select * from (SELECT username 28 | FROM dba_users 29 | WHERE created < (SELECT created FROM v$database) 30 | ) u 31 | where dba_segments.owner = u.username 32 | ) 33 | group by owner, 34 | segment_name 35 | order by 3 desc, 1 36 | ) 37 | ) 38 | where rn <= 10; 39 | -------------------------------------------------------------------------------- /ShinData/top10_index_subpartitions_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_index_subpartitions_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 02, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 index subpartitions that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | size_gb, 21 | rownum rn 22 | from (select owner, 23 | segment_name, 24 | round(sum(bytes/1024/1024/1024), 4) as size_gb 25 | from dba_segments 26 | where segment_type = 'INDEX SUBPARTITION' 27 | and not exists (select * from (SELECT username 28 | FROM dba_users 29 | WHERE created < (SELECT created FROM v$database) 30 | ) u 31 | where dba_segments.owner = u.username 32 | ) 33 | group by owner, 34 | segment_name 35 | order by 3 desc, 1 36 | ) 37 | ) 38 | where rn <= 10; 39 | -------------------------------------------------------------------------------- /ShinData/top10_indexes_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_indexes_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 02, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 indexes that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name 17 | ,size_gb 18 | from (select owner, 19 | segment_name, 20 | round(bytes/1024/1024/1024, 4) as size_gb, 21 | rownum rn 22 | from dba_segments 23 | where segment_type = 'INDEX' 24 | and not exists (select * from (SELECT username 25 | FROM dba_users 26 | WHERE created < (SELECT created FROM v$database) 27 | ) u 28 | where dba_segments.owner = u.username 29 | ) 30 | order by 3 desc, 1 31 | ) 32 | where rn <= 10; 33 | -------------------------------------------------------------------------------- /ShinData/top10_lob_partitions_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_lob_partitions_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 05, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 lob partitions that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | size_gb, 21 | rownum rn 22 | from (select owner, 23 | segment_name, 24 | round(sum(bytes/1024/1024/1024), 2) as size_gb 25 | from dba_segments 26 | where segment_type = 'LOB PARTITION' 27 | and not exists (select * from (SELECT username 28 | FROM dba_users 29 | WHERE created < (SELECT created FROM v$database) 30 | ) u 31 | where dba_segments.owner = u.username 32 | ) 33 | group by owner,segment_name 34 | order by 3 desc, 1 35 | ) 36 | ) 37 | where rn <= 10; 38 | -------------------------------------------------------------------------------- /ShinData/top10_lobsegments_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_lobsegments_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 05, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 lobsegments that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | round(bytes/1024/1024/1024, 4) as size_gb, 21 | rownum rn 22 | from dba_segments 23 | where segment_type = 'LOBSEGMENT' 24 | and not exists (select * from (SELECT username 25 | FROM dba_users 26 | WHERE created < (SELECT created FROM v$database) 27 | ) u 28 | where dba_segments.owner = u.username 29 | ) 30 | order by 3 desc, 1 31 | ) 32 | where rn <= 10; 33 | -------------------------------------------------------------------------------- /ShinData/top10_segment_occupied_tablespace.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_segment_occupied_tablespace.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 11, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking top 10 segment names that occupied by a specific tablespace (whose used rate >= 75%) on oracle database. 13 | REM 14 | 15 | SELECT * FROM 16 | (SELECT owner, 17 | segment_name, 18 | segment_type, 19 | bytes/1024/1024 AS used_mb 20 | FROM dba_segments 21 | WHERE tablespace_name IN (SELECT a.tablespace_name 22 | FROM dba_tablespaces a 23 | LEFT JOIN (SELECT tablespace_name, SUM(bytes) used_size 24 | FROM DBA_SEGMENTS 25 | WHERE segment_name NOT LIKE 'BIN$%' 26 | GROUP BY tablespace_name 27 | ) b ON a.tablespace_name = b.tablespace_name 28 | LEFT JOIN (SELECT tablespace_name, 29 | sum(case autoextensible when 'YES' then maxbytes else bytes end) AS sum_maxspace 30 | FROM dba_data_files 31 | GROUP BY tablespace_name 32 | ) c ON a.tablespace_name = c.tablespace_name 33 | WHERE a.contents = 'PERMANENT' 34 | AND round(nvl(b.used_size, 0)/c.sum_maxspace*100, 2) >= 75 35 | ) 36 | ORDER BY used_mb DESC 37 | ) 38 | WHERE rownum <= 10; 39 | -------------------------------------------------------------------------------- /ShinData/top10_table_partitions_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_table_partitions_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 01, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 table partitions that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | size_gb, 21 | rownum rn 22 | from (select owner, 23 | segment_name, 24 | round(sum(bytes/1024/1024/1024), 4) as size_gb 25 | from dba_segments 26 | where segment_type = 'TABLE PARTITION' 27 | and not exists (select * from (SELECT username 28 | FROM dba_users 29 | WHERE created < (SELECT created FROM v$database) 30 | ) u 31 | where dba_segments.owner = u.username 32 | ) 33 | group by owner, 34 | segment_name 35 | order by 3 desc, 1 36 | ) 37 | ) 38 | where rn <= 10; 39 | -------------------------------------------------------------------------------- /ShinData/top10_table_subpartitions_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_table_subpartitions_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 01, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 table subpartitions that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | size_gb, 21 | rownum rn 22 | from (select owner, 23 | segment_name, 24 | round(sum(bytes/1024/1024/1024), 4) as size_gb 25 | from dba_segments 26 | where segment_type = 'TABLE SUBPARTITION' 27 | and not exists (select * from (SELECT username 28 | FROM dba_users 29 | WHERE created < (SELECT created FROM v$database) 30 | ) u 31 | where dba_segments.owner = u.username 32 | ) 33 | group by owner, 34 | segment_name 35 | order by 3 desc, 1 36 | ) 37 | ) 38 | where rn <= 10; 39 | -------------------------------------------------------------------------------- /ShinData/top10_tables_occupied_by_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top10_tables_occupied_by_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Sep 01, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the top 10 tables that occupied by size (gb) from dba_segments of oracle database. 13 | REM 14 | 15 | select owner, 16 | segment_name, 17 | size_gb 18 | from (select owner, 19 | segment_name, 20 | round(bytes/1024/1024/1024, 4) as size_gb, 21 | rownum rn 22 | from dba_segments 23 | where segment_type = 'TABLE' 24 | and not exists (select * from (SELECT username 25 | FROM dba_users 26 | WHERE created < (SELECT created FROM v$database) 27 | ) u 28 | where dba_segments.owner = u.username 29 | ) 30 | order by 3 desc, 1 31 | ) 32 | where rn <= 10; 33 | -------------------------------------------------------------------------------- /ShinData/total_parse_count_per_sec.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: total_parse_count_per_sec.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Aug 10, 2022 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM Checking the total parse count per second (captured by interval 1 minute) in recent 1 hour on oracle database. 13 | REM 14 | 15 | SET LINESIZE 200 16 | SET PAGESIZE 300 17 | 18 | COLUMN sample_time FORMAT a11 19 | COLUMN metric_name FORMAT a25 20 | COLUMN value FORMAT 999,999.99 21 | 22 | SELECT inst_id 23 | , TO_CHAR(end_time, 'hh24:mi:ss') sample_time 24 | , DECODE(metric_name, 'Total Parse Count Per Sec', 'SQL Parses') metric_name 25 | , ROUND(value, 2) value 26 | FROM gv$sysmetric_history 27 | WHERE metric_name = 'Total Parse Count Per Sec' 28 | AND group_id = 2 29 | AND end_time >= SYSDATE - INTERVAL '60' MINUTE 30 | ORDER BY inst_id, sample_time; 31 | -------------------------------------------------------------------------------- /Tips/ASM清理磁盘头信息.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/ASM清理磁盘头信息.txt -------------------------------------------------------------------------------- /Tips/Oracle-RMAN恢复数据库操作步骤.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/Oracle-RMAN恢复数据库操作步骤.txt -------------------------------------------------------------------------------- /Tips/OracleDG备库定时删除已应用的归档日志.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/OracleDG备库定时删除已应用的归档日志.txt -------------------------------------------------------------------------------- /Tips/Oracle查看Data Guard Apply速度脚本.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/Oracle查看Data Guard Apply速度脚本.txt -------------------------------------------------------------------------------- /Tips/Oracle查看完整的sql_fulltext内容.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/Oracle查看完整的sql_fulltext内容.txt -------------------------------------------------------------------------------- /Tips/Oracle用sqlprompt修改sqlplus的连接提示符.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/Oracle用sqlprompt修改sqlplus的连接提示符.txt -------------------------------------------------------------------------------- /Tips/使用授权用户查看Oracle服务器的物理IP地址.txt: -------------------------------------------------------------------------------- 1 | -- 授予ACL权限, 需要在目标库的管理员sys用户下执行: 2 | 3 | -- 12cR1以前: 4 | 5 | begin 6 | dbms_network_acl_admin.create_acl ( 7 | acl => 'UTL_INADDR.xml', 8 | description => 'utl_inaddr', 9 | principal => 'DMPMON', -- DMP监控用户名为大写 10 | is_grant => TRUE, 11 | privilege => 'resolve' 12 | ); 13 | commit; 14 | end; 15 | / 16 | 17 | begin 18 | dbms_network_acl_admin.assign_acl( 19 | acl => 'UTL_INADDR.xml', 20 | host => 'yyds01' -- 主机名 21 | ); 22 | commit; 23 | end; 24 | / 25 | 26 | begin 27 | dbms_network_acl_admin.assign_acl( 28 | acl => 'UTL_INADDR.xml', 29 | host => 'yyds02' -- 主机名 30 | ); 31 | commit; 32 | end; 33 | / 34 | 35 | -- 12cR1以后: 36 | 37 | BEGIN 38 | DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( 39 | host => 'yyds01', -- 主机名 40 | ace => xs$ace_type( 41 | privilege_list => xs$name_list('resolve'), 42 | principal_name => 'c##dmpmon', -- DMP监控用户名 43 | principal_type => xs_acl.ptype_db 44 | ) 45 | ); 46 | END; 47 | / 48 | 49 | BEGIN 50 | DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( 51 | host => 'yyds02', -- 主机名 52 | ace => xs$ace_type( 53 | privilege_list => xs$name_list('resolve'), 54 | principal_name => 'c##dmpmon', -- DMP监控用户名 55 | principal_type => xs_acl.ptype_db 56 | ) 57 | ); 58 | END; 59 | / 60 | 61 | -- Oracle基础-ACL权限 62 | -- https://blog.csdn.net/jioujiou520/article/details/114338999 63 | 64 | 相关查询 65 | 查询ACL权限分配 66 | select * from dba_network_acl_privileges; 67 | 68 | 查询ACL权限明细 69 | select * from dba_network_acls; 70 | -------------------------------------------------------------------------------- /Tips/批量杀掉Oracle连接会话.txt: -------------------------------------------------------------------------------- 1 | select Q'[alter system kill ']' || sid || ', ' || serial# || Q'[' immediate;]' from v$session where sql_id = 'a8fdq2kj0rmz7'; 2 | 3 | -- 批量kill杀死某些会话session的PL/SQL 4 | -- https://blog.csdn.net/weixin_30713705/article/details/116384673 5 | 6 | declare 7 | v_sid v$session.sid%type; --定义如下两个type类型,用于接收cursor 8 | v_serial# v$session.serial#%type; 9 | cursor cur_session is select sid, serial# from v$session where sql_id = 'a8fdq2kj0rmz7'; --#定义cursor 10 | begin 11 | open cur_session; --打开cusor 12 | loop --打开游标马上开始循环,因为cursor是一条条取数据的 13 | fetch cur_session into v_sid,v_serial#; --把游标的数据放入上面定义的type变量中 14 | --根据以上的type变量及游标生成批量杀session的动态sql脚本,并执行 15 | execute immediate 'alter system kill session '''||v_sid||','||v_serial#||''' immediate'; 16 | exit when cur_session%notfound; --要加个异常处理,不然永远是死循环 17 | dbms_output.put_line('cursor date have been fetched ending'); 18 | end loop; --loop也有成双匹配出现 19 | close cur_session; --游标处理完后,关闭游标 20 | end; 21 | / 22 | -------------------------------------------------------------------------------- /Tips/查看DG主备库的角色_打开模式_保护模式等.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看DG主备库的角色_打开模式_保护模式等.txt -------------------------------------------------------------------------------- /Tips/查看Oracle中Redo日志组和StandbyRedo日志组的信息.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle中Redo日志组和StandbyRedo日志组的信息.txt -------------------------------------------------------------------------------- /Tips/查看Oracle中SGA各组件的内存动态分配情况.txt: -------------------------------------------------------------------------------- 1 | col component for a35 2 | set pagesize 30 3 | 4 | SELECT component, 5 | current_size/1024/1024/1024 current_size_gb 6 | FROM v$sga_dynamic_components 7 | ORDER BY 1; 8 | 9 | 13:51:47 SYS@yydsdb/yyds01> col component for a35 10 | 13:51:48 SYS@yydsdb/yyds01> set pagesize 30 11 | 13:51:48 SYS@yydsdb/yyds01> SELECT component, current_size/1024/1024/1024 current_size_gb FROM V$SGA_DYNAMIC_COMPONENTS order by 1; 12 | 13 | COMPONENT CURRENT_SIZE_GB 14 | ----------------------------------- --------------- 15 | ASM Buffer Cache 0 16 | DEFAULT 16K buffer cache 0 17 | DEFAULT 2K buffer cache 0 18 | DEFAULT 32K buffer cache 0 19 | DEFAULT 4K buffer cache 0 20 | DEFAULT 8K buffer cache 0 21 | DEFAULT buffer cache 6 <<== 22 | Data Transfer Cache 0 23 | In Memory RO Extension Area 0 24 | In Memory RW Extension Area 0 25 | In-Memory Area 0 26 | KEEP buffer cache 0 27 | RECYCLE buffer cache 0 28 | Shared IO Pool .125 29 | java pool 0 30 | large pool .03125 31 | memoptimize buffer cache 0 32 | shared pool 3.75 <<== 33 | streams pool .0625 34 | unified pga pool 0 35 | 36 | 20 rows selected. -------------------------------------------------------------------------------- /Tips/查看Oracle中修改过的隐藏参数.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle中修改过的隐藏参数.txt -------------------------------------------------------------------------------- /Tips/查看Oracle中占用临时表空间的session或SQL.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle中占用临时表空间的session或SQL.txt -------------------------------------------------------------------------------- /Tips/查看Oracle中多租户(CDB,PDB)架构.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle中多租户(CDB,PDB)架构.txt -------------------------------------------------------------------------------- /Tips/查看Oracle中表空间SYSTEM和SYSAUX的top10占用对象大小.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle中表空间SYSTEM和SYSAUX的top10占用对象大小.txt -------------------------------------------------------------------------------- /Tips/查看Oracle标准审计和清理审计表aud$数据的策略.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle标准审计和清理审计表aud$数据的策略.txt -------------------------------------------------------------------------------- /Tips/查看Oracle的service名_数据库名_实例名_pdb名.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle的service名_数据库名_实例名_pdb名.txt -------------------------------------------------------------------------------- /Tips/查看Oracle的所有用户(排除系统内置).txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle的所有用户(排除系统内置).txt -------------------------------------------------------------------------------- /Tips/查看Oracle长时间运行的任务及完成进度.txt: -------------------------------------------------------------------------------- 1 | set pages 999 2 | set trimspool on 3 | set lines 256 4 | col message for a40 word_wrap 5 | col perc for 990.00 6 | col mins for 9,990.00 7 | alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS'; 8 | 9 | select sid, 10 | serial#, 11 | start_time, 12 | time_remaining, 13 | round(time_remaining/60) as mins, 14 | round(sofar/totalwork, 2) * 100 as perc, 15 | message 16 | from v$session_longops 17 | where time_remaining > 0 18 | order by 1, 2, 3 19 | / -------------------------------------------------------------------------------- /Tips/查看Oracle非系统内置用户的权限(包括系统权限,角色权限和对象权限).txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Oracle非系统内置用户的权限(包括系统权限,角色权限和对象权限).txt -------------------------------------------------------------------------------- /Tips/查看RMAN备份任务的作业.txt: -------------------------------------------------------------------------------- 1 | select input_type, 2 | status, 3 | to_char(start_time,'yyyy-mm-dd hh24:mi:ss') start_time, 4 | to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') end_time, 5 | time_taken_display, 6 | input_bytes_display, 7 | output_bytes_display, 8 | input_bytes_per_sec_display, 9 | output_bytes_per_sec_display 10 | from v$rman_backup_job_details 11 | order by 3 desc; -------------------------------------------------------------------------------- /Tips/查看RMAN备份的异步IO.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看RMAN备份的异步IO.txt -------------------------------------------------------------------------------- /Tips/查看Redo Log文件的大小及每天的归档日志量.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看Redo Log文件的大小及每天的归档日志量.txt -------------------------------------------------------------------------------- /Tips/查看SQL的执行计划.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/查看SQL的执行计划.txt -------------------------------------------------------------------------------- /Tips/查看SQL的调优建议报告.txt: -------------------------------------------------------------------------------- 1 | SET SERVEROUTPUT ON 2 | 3 | DECLARE 4 | my_task_name VARCHAR2(30); 5 | BEGIN 6 | my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_id => '4d8svnv5rvtws', 7 | scope => 'COMPREHENSIVE', 8 | time_limit => 3600, 9 | task_name => 'sql_tuning_4d8svnv5rvtws', 10 | description => 'SQL TUNE ADVISOR REPORT'); 11 | DBMS_SQLTUNE.EXECUTE_TUNING_TASK(task_name => 'sql_tuning_4d8svnv5rvtws'); 12 | END; 13 | / 14 | 15 | SET LONG 100000000 16 | SET LONGCHUNKSIZE 1000 17 | SET LINESIZE 300 18 | SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('sql_tuning_4d8svnv5rvtws') FROM DUAL; -------------------------------------------------------------------------------- /Tips/终止Oracle中正在运行的RMAN备份任务.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/终止Oracle中正在运行的RMAN备份任务.txt -------------------------------------------------------------------------------- /Tips/调整Oracle的undo表空间大小.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guestart/Oracle-SQL-Scripts/c1f8c74ff00b02e166afa49bc35b344609ba206b/Tips/调整Oracle的undo表空间大小.txt -------------------------------------------------------------------------------- /acquiring_pool_sql/buffer_gets_rank_top_5_sql_on_sqlstats.sql: -------------------------------------------------------------------------------- 1 | ==================================================================== 2 | -- Script: buffer_gets_rank_top_5_sql_on_sqlstats.sql 3 | -- Author: Quanwen Zhao 4 | -- Updated: May 17, 2019 5 | -- Ranking Top 5 SQL for buffer_gets (High CPU) on v$sqlstats 6 | -- Number of buffer gets for all cursors with this SQL text and plan 7 | -- Trying not to check v$sql, as you can see Connor's this blog post 8 | -- https://connor-mcdonald.com/2019/03/04/less-slamming-vsql/ 9 | ==================================================================== 10 | 11 | SET LINESIZE 32767 12 | SET PAGESIZE 50000 13 | 14 | COLUMN sql_id FORMAT a13 15 | COLUMN sql_text FORMAT a60 16 | COLUMN buffer_gets FORMAT 999,999,999,999,999 17 | 18 | SELECT * 19 | FROM (SELECT sql_id 20 | , sql_text 21 | , buffer_gets 22 | , DENSE_RANK() OVER (ORDER BY buffer_gets DESC) AS buffer_gets_rank 23 | FROM v$sqlstats 24 | WHERE buffer_gets > 1000000 25 | ) 26 | WHERE buffer_gets_rank <= 5 27 | / 28 | 29 | SET LINESIZE 80 30 | SET PAGESIZE 14 31 | -------------------------------------------------------------------------------- /acquiring_pool_sql/disk_reads_rank_top_5_sql_on_sqlstats.sql: -------------------------------------------------------------------------------- 1 | ==================================================================== 2 | -- Script: disk_reads_rank_top_5_sql_on_sqlstats.sql 3 | -- Author: Quanwen Zhao 4 | -- Updated: May 17, 2019 5 | -- Modified: Oct 30, 2022 (modified v$sql to v$sqlstats) 6 | -- Ranking Top 5 SQL for disk_reads (High I/O) on v$sqlstats 7 | -- Number of disk reads for all cursors with this SQL text and plan 8 | -- Trying not to check v$sql, as you can see Connor's this blog post 9 | -- https://connor-mcdonald.com/2019/03/04/less-slamming-vsql/ 10 | ==================================================================== 11 | 12 | SET LINESIZE 32767 13 | SET PAGESIZE 50000 14 | 15 | COLUMN sql_id FORMAT a13 16 | COLUMN sql_text FORMAT a70 17 | COLUMN disk_reads FORMAT 999,999,999,999,999 18 | 19 | SELECT * 20 | FROM (SELECT sql_id 21 | , sql_text 22 | , disk_reads 23 | , DENSE_RANK() OVER (ORDER BY disk_reads DESC) AS disk_reads_rank 24 | FROM v$sqlstats 25 | WHERE disk_reads > 100000 26 | ) 27 | WHERE disk_reads_rank <= 5 28 | / 29 | 30 | SET LINESIZE 80 31 | SET PAGESIZE 14 32 | -------------------------------------------------------------------------------- /acquiring_pool_sql/poor_parsing_applications_rank_top_5_sql_on_sqlstats.sql: -------------------------------------------------------------------------------- 1 | ============================================================================================================== 2 | -- Script: poor_parsing_applications_rank_top_5_sql_on_sqlstats.sql 3 | -- Author: Quanwen Zhao 4 | -- Updated: May 17, 2019 5 | -- Modified: Oct 30, 2022 (modified v$sql to v$sqlstats) 6 | -- Ranking Top 5 SQL for poor parsing applications (parse_calls/executions) on v$sqlstats 7 | -- parse_calls, Number of parse calls for all cursors with this SQL text and plan 8 | -- executions, Number of executions that took place on this object since it was brought into the library cache 9 | -- Trying not to check v$sql, as you can see Connor's this blog post 10 | -- https://connor-mcdonald.com/2019/03/04/less-slamming-vsql/ 11 | ============================================================================================================== 12 | 13 | SET LINESIZE 32767 14 | SET PAGESIZE 50000 15 | 16 | COLUMN sql_id FORMAT a13 17 | COLUMN sql_text FORMAT a70 18 | COLUMN parse_calls/executions FORMAT 999,999,999,999,999 HEADING 'parse_calls|executions' 19 | COLUMN parse_app_rank FORMAT 999 HEADING 'parse_app|rank' 20 | 21 | SELECT * 22 | FROM (SELECT sql_id 23 | , sql_text 24 | , parse_calls/executions 25 | , DENSE_RANK() OVER (ORDER BY DECODE(executions, 0, 0, parse_calls / executions) DESC) AS parse_app_rank 26 | FROM v$sqlstats 27 | WHERE DECODE(executions, 0, 0, parse_calls / executions) > 1 28 | ) 29 | WHERE parse_app_rank <= 5 30 | / 31 | 32 | SET LINESIZE 80 33 | SET PAGESIZE 14 34 | -------------------------------------------------------------------------------- /acquiring_pool_sql/shared_memory_rank_top_5_sql_on_sqlstats.sql: -------------------------------------------------------------------------------- 1 | =============================================================================================== 2 | -- Script: shared_memory_rank_top_5_sql_on_sqlstats.sql 3 | -- Author: Quanwen Zhao 4 | -- Updated: May 17, 2019 5 | -- Ranking Top 5 SQL for shared memory (Memory hogs) on v$sqlstats 6 | -- Total shared memory (in bytes) currently occupied by all cursors with this SQL text and plan 7 | -- Trying not to check v$sql, as you can see Connor's this blog post 8 | -- https://connor-mcdonald.com/2019/03/04/less-slamming-vsql/ 9 | =============================================================================================== 10 | 11 | SET LINESIZE 32767 12 | SET PAGESIZE 50000 13 | 14 | COLUMN sql_id FORMAT a13 15 | COLUMN sql_text FORMAT a60 16 | COLUMN sharable_mem FORMAT 999,999,999,999,999 17 | 18 | SELECT * 19 | FROM (SELECT sql_id 20 | , sql_text 21 | , sharable_mem 22 | , DENSE_RANK() OVER (ORDER BY sharable_mem DESC) AS sharable_mem_rank 23 | FROM v$sqlstats 24 | WHERE sharable_mem > 10000000 25 | ) 26 | WHERE sharable_mem_rank <= 5 27 | / 28 | 29 | SET LINESIZE 80 30 | SET PAGESIZE 14 31 | -------------------------------------------------------------------------------- /adg/check_dg_phystdby_log_apply.sql: -------------------------------------------------------------------------------- 1 | -- My standby database ARCHIVE LOG LIST shows 0 but standby sync run successful without issues, 2 | -- So do not use ARCHIVE LOG LIST on standby side. 3 | 4 | -- Use following query on primary / standby to make sure it sync up to date. 5 | 6 | -- Primary: 7 | 8 | SELECT thread# 9 | , max(sequence#) AS "Last Primary Seq Generated" 10 | FROM v$archived_log val 11 | , v$database vdb 12 | WHERE val.resetlogs_change# = vdb.resetlogs_change# 13 | GROUP BY thread# 14 | ORDER BY 1 15 | / 16 | 17 | -- PhyStdby: 18 | 19 | SELECT thread# 20 | , max(sequence#) AS "Last Standby Seq Received" 21 | FROM v$archived_log val 22 | , v$database vdb 23 | WHERE val.resetlogs_change# = vdb.resetlogs_change# 24 | GROUP BY thread# 25 | ORDER BY 1 26 | / 27 | 28 | SELECT thread# 29 | , max(sequence#) AS "Last Standby Seq Applied" 30 | FROM v$archived_log val 31 | , v$database vdb 32 | WHERE val.resetlogs_change# = vdb.resetlogs_change# 33 | AND val.applied IN ('YES','IN-MEMORY') 34 | GROUP BY thread# 35 | ORDER BY 1 36 | / 37 | -------------------------------------------------------------------------------- /capacity_planning/checking_table_growth.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: checking_table_growth.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 20, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 9 | REM Purpose: 10 | REM This SQL script uses to check the growth of table. 11 | REM 12 | 13 | SET LINESIZE 300 14 | SET PAGESIZE 300 15 | 16 | ALTER SESSION SET nls_timestamp_format = 'yyyy-mm-dd hh24:mi:ss'; 17 | 18 | COLUMN snap_interval FORMAT a20 19 | COLUMN retention FORMAT a20 20 | 21 | SELECT * FROM dba_hist_wr_control; 22 | 23 | COLUMN MIN(end_interval_time) FORMAT a30 24 | COLUMN MAX(end_interval_time) FORMAT a30 25 | 26 | SELECT MIN(end_interval_time), MAX(end_interval_time) FROM dba_hist_snapshot; 27 | 28 | COLUMN table_name FORMAT a35 29 | COLUMN snap_date_and_time FORMAT a25 30 | COLUMN used_total_mb FORMAT 999,999,999.9999 31 | COLUMN used_delta_mb FORMAT 999,999,999.9999 32 | 33 | SELECT dhsso.object_name AS table_name, 34 | TO_CHAR(dhs.end_interval_time, 'yyyy-mm-dd hh24:mi:ss') AS snap_date_and_time, 35 | dhss.space_used_total / POWER(2, 20) AS used_total_mb, 36 | dhss.space_used_delta / POWER(2, 20) AS used_delta_mb 37 | FROM dba_hist_seg_stat dhss, 38 | dba_hist_seg_stat_obj dhsso, 39 | dba_hist_snapshot dhs 40 | WHERE dhss.snap_id = dhs.snap_id 41 | AND dhss.dbid= dhs.dbid 42 | AND dhss.instance_number = dhs.instance_number 43 | AND dhss.ts#= dhsso.ts# 44 | AND dhss.obj#=dhsso.obj# 45 | AND dhss.dataobj# = dhsso.dataobj# 46 | AND dhsso.owner = UPPER('&owner_name') 47 | AND dhsso.object_type LIKE 'TABLE%' 48 | AND dhsso.object_name = UPPER('&table_name') 49 | ORDER BY table_name, snap_date_and_time 50 | ; 51 | -------------------------------------------------------------------------------- /capacity_planning/checking_table_used_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: checking_table_used_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 24, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 9 | REM Purpose: 10 | REM The SQL script focuses on checking the used size and other situations 11 | REM (such as, num_rows, blocks, avg_row_len and so on) of table. Typically 12 | REM the table's size exceeds 1024 MB we think that which will become a big 13 | REM table. 14 | REM 15 | 16 | SET LINESIZE 150 17 | SET PAGESIZE 300 18 | 19 | SET TIMING ON 20 | 21 | COLUMN owner FORMAT a30 22 | COLUMN table_name FORMAT a30 23 | 24 | WITH 25 | ds AS (SELECT owner 26 | , segment_name 27 | , SUM(bytes)/POWER(2, 20) AS used_mb 28 | FROM dba_segments 29 | WHERE owner = UPPER('&&owner_name') 30 | AND segment_type = 'TABLE' 31 | GROUP BY owner 32 | , segment_name 33 | HAVING SUM(bytes)/POWER(2, 20) > 1024 34 | ORDER BY segment_name 35 | ), 36 | dt AS (SELECT owner 37 | , table_name 38 | , num_rows 39 | , blocks 40 | -- , empty_blocks 41 | -- , avg_space 42 | , avg_row_len 43 | FROM dba_tables 44 | WHERE owner = UPPER('&owner_name') 45 | ORDER BY table_name 46 | ) 47 | SELECT dt.owner 48 | , dt.table_name 49 | , ds.used_mb 50 | , dt.num_rows 51 | , dt.blocks 52 | -- , dt.empty_blocks 53 | -- , dt.avg_space 54 | , dt.avg_row_len 55 | FROM ds, dt 56 | WHERE ds.owner = dt.owner 57 | AND ds.segment_name = dt.table_name 58 | ORDER BY ds.used_mb DESC 59 | , dt.num_rows DESC 60 | , dt.table_name 61 | ; 62 | -------------------------------------------------------------------------------- /capacity_planning/checking_tablespace_growth.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: checking_tablespace_growth.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 20, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 9 | REM Purpose: 10 | REM This SQL script uses to check the growth of tablespace. 11 | REM 12 | 13 | SET LINESIZE 300 14 | SET PAGESIZE 300 15 | 16 | ALTER SESSION SET nls_timestamp_format = 'yyyy-mm-dd hh24:mi:ss'; 17 | 18 | COLUMN snap_interval FORMAT a20 19 | COLUMN retention FORMAT a20 20 | 21 | SELECT * FROM dba_hist_wr_control; 22 | 23 | COLUMN MIN(end_interval_time) FORMAT a30 24 | COLUMN MAX(end_interval_time) FORMAT a30 25 | 26 | SELECT MIN(end_interval_time), MAX(end_interval_time) FROM dba_hist_snapshot; 27 | 28 | COLUMN tablespace_name FORMAT a35 29 | COLUMN snap_date_and_time FORMAT a25 30 | COLUMN total_gb FORMAT 999,999,999.9999 31 | COLUMN used_gb FORMAT 999,999,999.9999 32 | 33 | SELECT dt.tablespace_name, 34 | TO_CHAR(dhs.end_interval_time, 'yyyy-mm-dd hh24:mi:ss') AS snap_date_and_time, 35 | SUM(dhtsu.tablespace_size * dt.block_size) / POWER(2, 30) AS total_gb, 36 | SUM(dhtsu.tablespace_usedsize * dt.block_size) / POWER(2, 30) AS used_gb 37 | FROM dba_hist_tbspc_space_usage dhtsu, 38 | dba_hist_snapshot dhs, 39 | v$tablespace vts, 40 | dba_tablespaces dt 41 | WHERE dhtsu.snap_id = dhs.snap_id 42 | AND dhtsu.dbid = dhs.dbid 43 | AND dhtsu.tablespace_id = vts.ts# 44 | AND vts.name = dt.tablespace_name 45 | -- AND SUBSTR(to_char(end_interval_time, 'yyyy-mm-dd hh24:mi:ss'),12,5)='00:00' 46 | GROUP BY dt.tablespace_name, dhs.end_interval_time 47 | ORDER BY tablespace_name, snap_date_and_time 48 | ; 49 | -------------------------------------------------------------------------------- /grant/bth_grt_sel.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: bth_grt_sel.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jun 30, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script uses to batch generate "grant (only) select privilege on specific user (prod)'s all 8 | REM of tables to a new user (qwz)", and then execute SPOOL sql file 'gen_bth_grt_sel.sql' to achieve the 9 | REM function of 'batch grant select'. 10 | REM 11 | 12 | DROP USER qwz; 13 | CREATE USER qwz IDENTIFIED BY qwz; 14 | GRANT connect, resource TO qwz; 15 | 16 | SET long 10000 17 | SET linesize 300 18 | SET pagesize 0 19 | 20 | SET echo OFF 21 | SET feedback OFF 22 | SET heading OFF 23 | SET termout OFF 24 | SET verify OFF 25 | SET trimout ON 26 | SET trimspool ON 27 | 28 | SPOOL gen_bth_grt_sel.sql 29 | SELECT 'GRANT SELECT ON ' 30 | || owner 31 | || '.' 32 | || table_name 33 | || ' TO qwz;' 34 | FROM dba_tables 35 | WHERE owner = 'PROD' 36 | ORDER BY table_name 37 | / 38 | SPOOL off 39 | 40 | -- Inserting new line on Jul 05, 2019. 41 | -- Next directly running the previous batch generated SQL statement of "grant select". 42 | @gen_bth_grt_sel.sql; 43 | -------------------------------------------------------------------------------- /plsql/brst2_scheduler.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: brst2_scheduler.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 23, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script file usually creates a user-defined job 'BRST2_JOB' on schema SZD_BBS_V2. 8 | REM The primary intention is it could regularly/periodically execute my procedure 'brgs_role_syn_tab_2' on schema SZD_BBS_V2. 9 | REM 10 | 11 | PROMPT ================================ 12 | PROMPT Executing on "SZD_BBS_V2" schema 13 | PROMPT ================================ 14 | 15 | CONN /@szd_bbs_v2; 16 | 17 | -- repeat_interval => 'FREQ=HOURLY; INTERVAL=5;', 18 | 19 | CREATE OR REPLACE PROCEDURE brst2_scheduler -- brst2 is the first letter abbreviation of my procedure name "brgs_role_syn_tab_2" 20 | IS 21 | BEGIN 22 | DBMS_SCHEDULER.create_job ( 23 | job_name => 'BRST2_JOB', 24 | job_type => 'STORED_PROCEDURE', 25 | -- job_action => 'brgs_role_syn_tab_2;', using this parameter, return ORA-27452: brgs_role_syn_tab_2; is an invalid name for a database object. 26 | job_action => 'brgs_role_syn_tab_2', -- when eliminating semi-colon that is at the end of value, it's okay 27 | -- start_date => '23-JUL-2019 05:00:00 PM China/Beijing', using this parameter, return ORA-01882: timezone region not found 28 | -- start_date => TO_DATE('2019-07-23 05:00:00', 'yyyy-mm-dd hh24:mi:ss'), using this parameter, it's okay 29 | -- start_date => SYSDATE, using this parameter, it's okay 30 | start_date => SYSTIMESTAMP, -- using this parameter, it's okay 31 | repeat_interval => 'FREQ=DAILY; BYHOUR=4;', 32 | end_date => NULL, 33 | auto_drop => false, 34 | enabled => true, 35 | job_class => 'DEFAULT_JOB_CLASS', 36 | comments => 'Batch grant select and create public synonym'); 37 | END; 38 | / 39 | -------------------------------------------------------------------------------- /plsql/brst3_scheduler.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: brst3_scheduler.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 30, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script file usually creates a user-defined job 'BRST3_JOB' on schema SZD_BBS_V2. 8 | REM The primary intention is it could regularly/periodically execute my procedure 'rgy_refresh_mview_uts' on schema SZD_BBS_V2. 9 | REM 10 | 11 | PROMPT ================================ 12 | PROMPT Executing on "SZD_BBS_V2" schema 13 | PROMPT ================================ 14 | 15 | CONN /@szd_bbs_v2; 16 | 17 | -- repeat_interval => 'FREQ=HOURLY; INTERVAL=5;', 18 | 19 | CREATE OR REPLACE PROCEDURE brst3_scheduler -- brst3 is the first letter abbreviation of my procedure name "brgs_role_syn_tab_3" 20 | IS 21 | BEGIN 22 | DBMS_SCHEDULER.create_job ( 23 | job_name => 'BRST3_JOB', 24 | job_type => 'STORED_PROCEDURE', 25 | job_action => 'rgy_refresh_mview_uts', 26 | start_date => SYSDATE, -- using this parameter, it's okay 27 | repeat_interval => 'FREQ=DAILY; BYHOUR=4;', 28 | end_date => NULL, 29 | auto_drop => false, 30 | enabled => true, 31 | job_class => 'DEFAULT_JOB_CLASS', 32 | comments => 'Batch grant select and create public synonym'); 33 | END; 34 | / 35 | -------------------------------------------------------------------------------- /plsql/brst_scheduler.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: brst_scheduler.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 23, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script file usually creates a user-defined job 'BRST_JOB' on schema SZD_BBS_V2. 8 | REM The primary intention is it could regularly/periodically execute my procedure 'brgs_role_syn_tab' on schema SZD_BBS_V2. 9 | REM 10 | 11 | PROMPT ================================ 12 | PROMPT Executing on "SZD_BBS_V2" schema 13 | PROMPT ================================ 14 | 15 | CONN /@szd_bbs_v2; 16 | 17 | -- For instance, repeat_interval => 'FREQ=DAILY; BYHOUR=4;', 18 | 19 | CREATE OR REPLACE PROCEDURE brst_scheduler -- brst is the first letter abbreviation of my procedure name "brgs_role_syn_tab" 20 | IS 21 | BEGIN 22 | DBMS_SCHEDULER.create_job ( 23 | job_name => 'BRST_JOB', 24 | job_type => 'STORED_PROCEDURE', 25 | -- job_action => 'brgs_role_syn_tab;', using this parameter, return ORA-27452: brgs_role_syn_tab; is an invalid name for a database object. 26 | job_action => 'brgs_role_syn_tab', -- when eliminating semi-colon that is at the end of value, it's okay 27 | -- start_date => '23-JUL-2019 10:00:00 AM China/Beijing', using this parameter, return ORA-01882: timezone region not found 28 | -- start_date => TO_DATE('2019-07-23 10:00:00', 'yyyy-mm-dd hh24:mi:ss'), using this parameter, it's okay 29 | -- start_date => SYSDATE, using this parameter, it's okay 30 | start_date => SYSTIMESTAMP, -- using this parameter, it's okay 31 | repeat_interval => 'FREQ=HOURLY; INTERVAL=5;', 32 | end_date => NULL, 33 | auto_drop => false, 34 | enabled => true, 35 | job_class => 'DEFAULT_JOB_CLASS', 36 | comments => 'Batch grant select and create public synonym'); 37 | END; 38 | / 39 | -------------------------------------------------------------------------------- /plsql/grant/bth_grt_sel_2.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: bth_grt_sel_2.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jun 30, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script file (the 2nd version of 'bth_grt_sel.sql' you can see 8 | REM here - https://github.com/guestart/Oracle-SQL-Scripts/blob/master/grant/bth_grt_sel.sql) also uses to 9 | REM batch grant (only) select privilege on specific user (prod)'s all of tables to a new user (qwz), this 10 | REM time I use a relatively simple PL/SQL code snippet to achieve the same intention. 11 | REM 12 | 13 | SET serveroutput ON 14 | SET linesize 300 15 | 16 | DROP USER qwz; 17 | CREATE USER qwz IDENTIFIED BY qwz; 18 | GRANT connect, resource TO qwz; 19 | 20 | BEGIN 21 | DBMS_OUTPUT.enable(1000000); 22 | FOR r IN ( 23 | SELECT 'GRANT SELECT ON ' || t.OWNER || '.' || t.TABLE_NAME || ' TO qwz' x_sql 24 | FROM SYS.dba_tables t 25 | WHERE OWNER = 'PROD' 26 | ORDER BY t.table_name 27 | ) 28 | LOOP 29 | BEGIN 30 | EXECUTE IMMEDIATE r.x_sql; 31 | EXCEPTION 32 | WHEN OTHERS THEN 33 | DBMS_OUTPUT.put_line(SUBSTR(r.x_sql, 1, 255)); 34 | DBMS_OUTPUT.put_line(SQLCODE || ':' || SQLERRM); 35 | END; 36 | END LOOP; 37 | END; 38 | / 39 | -------------------------------------------------------------------------------- /plsql/revoke/bth_rvk_sel_2.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: bth_rvk_sel_2.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: JuL 02, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script file (the 2nd version of 'bth_rvk_sel.sql' you can see 8 | REM here - https://github.com/guestart/Oracle-SQL-Scripts/blob/master/revoke/bth_rvk_sel.sql) also uses to 9 | REM batch revoke (only) select privilege on specific user (prod)'s all of tables from a new user (qwz) to whom 10 | REM if (once) being granted, this time I use a relatively simple PL/SQL code snippet to achieve the same intention. 11 | REM 12 | 13 | SET serveroutput ON 14 | SET linesize 300 15 | 16 | -- DROP USER qwz; 17 | -- CREATE USER qwz IDENTIFIED BY qwz; 18 | -- GRANT connect, resource TO qwz; 19 | 20 | BEGIN 21 | DBMS_OUTPUT.enable(1000000); 22 | FOR r IN ( 23 | SELECT 'REVOKE SELECT ON ' || t.OWNER || '.' || t.TABLE_NAME || ' FROM qwz' x_sql 24 | FROM SYS.dba_tables t 25 | WHERE OWNER = 'PROD' 26 | ORDER BY t.table_name 27 | ) 28 | LOOP 29 | BEGIN 30 | EXECUTE IMMEDIATE r.x_sql; 31 | EXCEPTION 32 | WHEN OTHERS THEN 33 | DBMS_OUTPUT.put_line(SUBSTR(r.x_sql, 1, 255)); 34 | DBMS_OUTPUT.put_line(SQLCODE || ':' || SQLERRM); 35 | END; 36 | END LOOP; 37 | END; 38 | / 39 | -------------------------------------------------------------------------------- /plsql/rgy_refresh_mview_uts.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: rgy_refresh_mview_uts.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 30, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script uses to regularly refresh MView "u_tables" created by procedure "brgs_role_syn_tab_3" 8 | REM from the SQL script "brgs_role_syn_tab_3.sql". 9 | REM 10 | 11 | PROMPT ================================ 12 | PROMPT Executing on "SZD_BBS_V2" schema 13 | PROMPT ================================ 14 | 15 | CONN /@szd_bbs_v2; 16 | 17 | CREATE OR REPLACE PROCEDURE rgy_refresh_mview_uts 18 | IS 19 | BEGIN 20 | DBMS_MVIEW.refresh('u_tables', 'c'); 21 | DBMS_OUTPUT.enable(1000000); 22 | FOR r IN ( 23 | SELECT 'GRANT SELECT ON ' || t.table_name || ' TO bbs' x_sql, 24 | 'CREATE OR REPLACE PUBLIC SYNONYM ' || t.table_name || ' FOR ' || t.table_name y_sql 25 | FROM user_tables t 26 | ORDER BY t.table_name 27 | ) 28 | LOOP 29 | BEGIN 30 | EXECUTE IMMEDIATE r.x_sql; 31 | EXECUTE IMMEDIATE r.y_sql; 32 | EXCEPTION 33 | WHEN OTHERS THEN 34 | DBMS_OUTPUT.put_line(SUBSTR(r.x_sql, 1, 255)); 35 | DBMS_OUTPUT.put_line(SUBSTR(r.y_sql, 1, 255)); 36 | DBMS_OUTPUT.put_line(SQLCODE || ':' || SQLERRM); 37 | END; 38 | END LOOP; 39 | END; 40 | / 41 | -------------------------------------------------------------------------------- /plsql/switch_redo_log_for_recycle.sql: -------------------------------------------------------------------------------- 1 | -- +----------------------------------------------------------------------------+ 2 | -- | Quanwen Zhao | 3 | -- | guestart@163.com | 4 | -- | quanwenzhao.wordpress.com | 5 | -- |----------------------------------------------------------------------------| 6 | -- | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 7 | -- |----------------------------------------------------------------------------| 8 | -- | DATABASE : Oracle | 9 | -- | FILE : switch_redo_log_for_recycle.sql | 10 | -- | CLASS : Administration | 11 | -- | PURPOSE : Switch all of online redo log for a recycle on oracle database. | 12 | -- | NOTE : As with any code, ensure to test this script in a development | 13 | -- | environment before attempting to run it in production. | 14 | -- +----------------------------------------------------------------------------+ 15 | 16 | SET ECHO OFF 17 | SET FEEDBACK OFF 18 | SET HEADING ON 19 | SET LINESIZE 300 20 | SET PAGESIZE 300 21 | SET TERMOUT ON 22 | SET TIMING OFF 23 | SET TRIMOUT ON 24 | SET TRIMSPOOL ON 25 | SET VERIFY OFF 26 | 27 | SET SERVEROUTPUT ON; 28 | 29 | DECLARE 30 | nums NUMBER; 31 | str_exec_sql VARCHAR2(512); 32 | BEGIN 33 | SELECT COUNT(group#) INTO nums FROM v$log; 34 | str_exec_sql := 'alter system archive log current'; 35 | FOR num IN 1 .. nums 36 | LOOP 37 | EXECUTE IMMEDIATE str_exec_sql; 38 | END LOOP; 39 | END; 40 | / 41 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_clc.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_clc.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Current Logons Count" and metric_unit "Logons" from the 13 | REM oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the CLC with each interval one minute during the period of recent one hour in 16 | REM the view "v$sysmetric_history" and there saves the CLC with the interval recent one hour 17 | REM in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a25 25 | COLUMN recent_clc FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) recent_clc 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Current Logons Count' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) recent_clc 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Current Logons Count' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_cocc.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_cocc.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Current Open Cursors Count" and metric_unit "Cursors" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Current Open Cursors Count" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Current Open Cursors Count" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a28 24 | COLUMN metric_unit FORMAT a12 25 | COLUMN cocc FORMAT 999,999,999 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) cocc 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Current Open Cursors Count' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) cocc 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Current Open Cursors Count' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_col.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_col.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Current OS Load" and metric_unit "Number Of Processes" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Current OS Load" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Current OS Load" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a15 24 | COLUMN metric_unit FORMAT a20 25 | COLUMN current_os_load FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) current_os_load 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Current OS Load' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) current_os_load 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Current OS Load' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_cpu_load.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_cpu_load.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Database Time Per Sec" and metric_unit "CentiSeconds Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Database Time Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Database Time Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a25 25 | COLUMN recent_cpu_load FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value/1e2/(SELECT value FROM v$osstat WHERE stat_name = 'NUM_CPUS'), 2) recent_cpu_load 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Database Time Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average/1e2/(SELECT value FROM v$osstat WHERE stat_name = 'NUM_CPUS'), 2) recent_cpu_load 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Database Time Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_cpu_usage.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_cpu_usage.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Host CPU Utilization (%)" and metric_unit "% Busy/(Idle+Busy)" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Host CPU Utilization (%)" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Host CPU Utilization (%)" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a20 25 | COLUMN recent_cpu_usage FORMAT a16 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) || '%' recent_cpu_usage 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Host CPU Utilization (%)' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) || '%' recent_cpu_usage 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Host CPU Utilization (%)' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_dbcps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_dbcps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "DB Block Changes Per Sec" and metric_unit "Blocks Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "DB Block Changes Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "DB Block Changes Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN dbcps FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) dbcps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'DB Block Changes Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) dbcps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'DB Block Changes Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_dbcpt.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_dbcpt.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "DB Block Changes Per Txn" and metric_unit "Blocks Per Txn" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "DB Block Changes Per Txn" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "DB Block Changes Per Txn" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN dbcpt FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) dbcpt 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'DB Block Changes Per Txn' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) dbcpt 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'DB Block Changes Per Txn' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_dbcpu_time_ratio.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_dbcpu_time_ratio.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Database CPU Time Ratio" and metric_unit "% Cpu/DB_Time" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Database CPU Time Ratio" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Database CPU Time Ratio" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a15 25 | COLUMN recent_dctr FORMAT a11 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) || '%' recent_dctr 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Database CPU Time Ratio' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) || '%' recent_dctr 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Database CPU Time Ratio' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_dbgps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_dbgps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "DB Block Gets Per Sec" and metric_unit "Blocks Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "DB Block Gets Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "DB Block Gets Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN dbgps FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) dbgps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'DB Block Gets Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) dbgps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'DB Block Gets Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_dbgpt.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_dbgpt.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "DB Block Gets Per Txn" and metric_unit "Blocks Per Txn" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "DB Block Gets Per Txn" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "DB Block Gets Per Txn" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN dbgpt FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) dbgpt 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'DB Block Gets Per Txn' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) dbgpt 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'DB Block Gets Per Txn' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_dbwait_time_ratio.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_dbwait_time_ratio.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Database Wait Time Ratio" and metric_unit "% Wait/DB_Time" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Database Wait Time Ratio" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Database Wait Time Ratio" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a15 25 | COLUMN recent_dwtr FORMAT a11 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) || '%' recent_dwtr 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Database Wait Time Ratio' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) || '%' recent_dwtr 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Database Wait Time Ratio' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_eps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_eps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Executions Per Sec" and metric_unit "Executes Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Executions Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Executions Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a20 24 | COLUMN metric_unit FORMAT a20 25 | COLUMN eps FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) eps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Executions Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) eps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Executions Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_ept.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_ept.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Executions Per Txn" and metric_unit "Executes Per Txn" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Executions Per Txn" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Executions Per Txn" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a20 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN ept FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) ept 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Executions Per Txn' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) ept 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Executions Per Txn' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_lps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_lps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Logons Per Sec" and metric_unit "Logons Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Logons Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Logons Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a15 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN recent_lps FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) recent_lps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Logons Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) recent_lps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Logons Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_lrps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_lrps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Logical Reads Per Sec" and metric_unit "Reads Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Logical Reads Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Logical Reads Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a22 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN lrps FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) lrps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Logical Reads Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) lrps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Logical Reads Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_network_mbps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_network_mbps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Network Traffic Volume Per Sec" and metric_unit "Bytes Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Network Traffic Volume Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Network Traffic Volume Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a30 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN recent_network_mbps FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value/POWER(2, 20), 2) recent_network_mbps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Network Traffic Volume Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average/POWER(2, 20), 2) recent_network_mbps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Network Traffic Volume Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_prps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_prps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Physical Reads Per Sec" and metric_unit "Reads Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Physical Reads Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Physical Reads Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN prps FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) prps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Physical Reads Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) prps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Physical Reads Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_redo_gen_mbps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_redo_gen_mbps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Redo Generated Per Sec" and metric_unit "Bytes Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Redo Generated Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Redo Generated Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN recent_redo_gen_mbps FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value/POWER(2, 20), 2) recent_redo_gen_mbps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Redo Generated Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average/POWER(2, 20), 2) recent_redo_gen_mbps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Redo Generated Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_rtpt.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_rtpt.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Response Time Per Txn" and metric_unit "CentiSeconds Per Txn" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Response Time Per Txn" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Response Time Per Txn" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a22 25 | COLUMN rtpt_ms FORMAT a20 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value*1e1, 2) || ' ms' rtpt_ms 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Response Time Per Txn' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average*1e1, 2) || ' ms' rtpt_ms 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Response Time Per Txn' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_rwps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_rwps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Redo Writes Per Sec" and metric_unit "Writes Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Redo Writes Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Redo Writes Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a20 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN recent_rwps FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) recent_rwps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Redo Writes Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) recent_rwps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Redo Writes Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_session_count.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_session_count.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "Session Count" and metric_unit "Sessions" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "Session Count" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "Session Count" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a15 24 | COLUMN metric_unit FORMAT a12 25 | COLUMN session_count FORMAT 999,999,999 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) session_count 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'Session Count' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) session_count 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'Session Count' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_ssrt.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_ssrt.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "SQL Service Response Time" and metric_unit "CentiSeconds Per Call" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "SQL Service Response Time" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "SQL Service Response Time" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a30 24 | COLUMN metric_unit FORMAT a25 25 | COLUMN ssrt_ms FORMAT a20 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value*1e1, 2) || ' ms' ssrt_ms 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'SQL Service Response Time' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average*1e1, 2) || ' ms' ssrt_ms 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'SQL Service Response Time' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_tps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_tps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 01, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "User Transaction Per Sec" and metric_unit "Transactions Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "User Transaction Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "User Transaction Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a25 24 | COLUMN metric_unit FORMAT a25 25 | COLUMN recent_tps FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) recent_tps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'User Transaction Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) recent_tps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'User Transaction Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_ucps.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_ucps.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "User Calls Per Sec" and metric_unit "Calls Per Second" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "User Calls Per Sec" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "User Calls Per Sec" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a20 24 | COLUMN metric_unit FORMAT a18 25 | COLUMN ucps FORMAT 999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) ucps 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'User Calls Per Sec' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) ucps 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'User Calls Per Sec' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /recent_metrics/acquire_recent_ucpt.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: acquire_recent_ucpt.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 11, 2021 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.3.0.0 9 | REM 21.3.0.0 10 | REM 11 | REM Purpose: 12 | REM In general we can get metric_name "User Calls Per Txn" and metric_unit "Calls Per Txn" 13 | REM from the oracle dynamic performance view "v$sysmetric_history" and "v$sysmetric_summary". 14 | REM 15 | REM There saves the "User Calls Per Txn" with each interval one minute during the period of recent 16 | REM one hour in the view "v$sysmetric_history" and there saves the "User Calls Per Txn" with the 17 | REM interval recent one hour in the view "v$sysmetric_summary". 18 | REM 19 | 20 | SET LINESIZE 200 21 | SET PAGESIZE 200 22 | 23 | COLUMN metric_name FORMAT a20 24 | COLUMN metric_unit FORMAT a15 25 | COLUMN ucpt FORMAT 999,999,999.99 26 | 27 | ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; 28 | 29 | SELECT begin_time 30 | , end_time 31 | , metric_name 32 | , metric_unit 33 | , ROUND(value, 2) ucpt 34 | FROM v$sysmetric_history 35 | WHERE metric_name = 'User Calls Per Txn' 36 | ORDER BY begin_time 37 | ; 38 | 39 | or 40 | 41 | SELECT begin_time 42 | , end_time 43 | , metric_name 44 | , metric_unit 45 | , ROUND(average, 2) ucpt 46 | FROM v$sysmetric_summary 47 | WHERE metric_name = 'User Calls Per Txn' 48 | ORDER BY begin_time 49 | ; 50 | -------------------------------------------------------------------------------- /revoke/bth_rvk_sel.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: bth_rvk_sel.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 02, 2019 5 | REM 6 | REM Purpose: 7 | REM This SQL script uses to batch generate "revoke (only) select privilege on specific user (prod)'s all of tables from 8 | REM a new user (qwz)" to whom if (once) being granted, and then execute SPOOL sql file 'gen_bth_rvk_sel.sql' to 9 | REM achieve the function of 'batch revoke select'. 10 | REM 11 | 12 | -- DROP USER qwz; 13 | -- CREATE USER qwz IDENTIFIED BY qwz; 14 | -- GRANT connect, resource TO qwz; 15 | 16 | SET long 10000 17 | SET linesize 300 18 | SET pagesize 0 19 | 20 | SET echo OFF 21 | SET feedback OFF 22 | SET heading OFF 23 | SET termout OFF 24 | SET verify OFF 25 | SET trimout ON 26 | SET trimspool ON 27 | 28 | SPOOL gen_bth_rvk_sel.sql 29 | SELECT 'REVOKE SELECT ON ' 30 | || owner 31 | || '.' 32 | || table_name 33 | || ' FROM qwz;' 34 | FROM dba_tables 35 | WHERE owner = 'PROD' 36 | ORDER BY table_name 37 | / 38 | SPOOL off 39 | 40 | -- Inserting new line on Jul 05, 2019. 41 | -- Next directly running the previous batch generated SQL statement of "revoke select". 42 | @gen_bth_rvk_sel.sql; 43 | -------------------------------------------------------------------------------- /routine_inspection/all_prod_user.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: all_prod_user.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 11, 2019 5 | REM 6 | REM Purpose: 7 | REM This sql script lists all of production users by dba_users (excluding sys related users). 8 | REM 9 | 10 | SET LINESIZE 200 11 | SET PAGESIZE 200 12 | COLUMN username FORMAT a23 13 | COLUMN account_status FORMAT a14 14 | 15 | SELECT username 16 | , account_status 17 | FROM dba_users 18 | WHERE username NOT IN 19 | ( 20 | 'ANONYMOUS' 21 | , 'APEX_030200' 22 | , 'APEX_PUBLIC_USER' 23 | , 'APPQOSSYS' 24 | , 'CTXSYS' 25 | , 'DBSNMP' 26 | , 'DIP' 27 | , 'EXFSYS' 28 | , 'FLOWS_FILES' 29 | , 'MDDATA' 30 | , 'MDSYS' 31 | , 'MGMT_VIEW' 32 | , 'OLAPSYS' 33 | , 'ORACLE_OCM' 34 | , 'ORDDATA' 35 | , 'ORDPLUGINS' 36 | , 'ORDSYS' 37 | , 'OUTLN' 38 | , 'OWBSYS' 39 | , 'OWBSYS_AUDIT' 40 | , 'SCOTT' 41 | , 'SI_INFORMTN_SCHEMA' 42 | , 'SPATIAL_CSW_ADMIN_USR' 43 | , 'SPATIAL_WFS_ADMIN_USR' 44 | , 'SQLTXADMIN' 45 | , 'SQLTXPLAIN' 46 | , 'SYS' 47 | , 'SYSMAN' 48 | , 'SYSTEM' 49 | , 'WMSYS' 50 | , 'XDB' 51 | , 'XS$NULL' 52 | ) 53 | ORDER BY 1 DESC 54 | / 55 | -------------------------------------------------------------------------------- /routine_inspection/check_non_default_parameter.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_non_default_parameter.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 24, 2020 5 | REM 6 | REM Purpose: 7 | REM This SQL script usually uses to check whether there are some non-default parameters on oracle database. 8 | REM Reference here - https://docs.oracle.com/cd/E11882_01/server.112/e40402/statviews_4017.htm#REFRN23427 9 | REM and here - https://docs.oracle.com/cd/E11882_01/server.112/e40402/dynviews_2087.htm#REFRN30176 10 | REM 11 | 12 | SET LINESIZE 200 13 | SET PAGESIZE 200 14 | 15 | COLUMN parameter_name FORMAT a45 16 | COLUMN value FORMAT a15 17 | 18 | SELECT DISTINCT parameter_name 19 | , value 20 | FROM dba_hist_parameter 21 | WHERE isdefault = 'FALSE' 22 | AND ismodified IN ('MODIFIED', 'SYSTEM_MOD') 23 | ; 24 | 25 | -- or 26 | 27 | SET LINESIZE 200 28 | SET PAGESIZE 200 29 | 30 | COLUMN name FORMAT a45 31 | COLUMN value FORMAT a15 32 | 33 | SELECT name 34 | , value 35 | FROM v$parameter 36 | WHERE isdefault = 'FALSE' 37 | AND ismodified IN ('MODIFIED', 'SYSTEM_MOD') 38 | ; 39 | -------------------------------------------------------------------------------- /routine_inspection/check_sequence_ddl_and_used.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_sequence_ddl_and_used.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: JAN 23, 2024 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.13.0.0 9 | REM 10 | REM Purpose: 11 | REM This sql script uses to check the define/used situation for the specific sequence of the specific production user by dba_sequences. 12 | REM 13 | 14 | -- checking the define situation of the sequences. 15 | 16 | set long 999999999 17 | set pagesize 0 18 | set heading off 19 | set feedback off 20 | execute dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'STORAGE', false); 21 | select dbms_metadata.get_ddl('SEQUENCE', upper('&seq_name'), upper('&owner')) from dual; 22 | 23 | -- checking the used situation of the sequences currently. 24 | 25 | set linesize 400 26 | set pagesize 400 27 | col sequence_name for a35 28 | col min_value for 999,999,999,999,999 29 | col max_value for 999,999,999,999,999 30 | col cycle_flag for a10 31 | col order_flag for a10 32 | select sequence_name, 33 | min_value, 34 | max_value, 35 | last_number, 36 | round(last_number/max_value, 2) used_perc, 37 | increment_by, 38 | cycle_flag, 39 | order_flag, 40 | cache_size 41 | from dba_sequences 42 | where sequence_owner = upper('&seq_owner') 43 | and sequence_name = upper('&seq_name'); 44 | -------------------------------------------------------------------------------- /routine_inspection/check_table_blocks_and_rows.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_table_blocks_and_rows.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Feb 19, 2024 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.13.0.0 9 | REM 10 | REM Purpose: 11 | REM This sql script uses to check all of tables' blocks and rows of the specific oracle production user. 12 | REM 13 | 14 | set linesize 400 15 | set pagesize 400 16 | col table_name for a30 17 | 18 | select table_name, blocks, empty_blocks, num_rows 19 | from dba_tables where owner = upper('&owner_name') 20 | order by 2 desc, 4 desc; 21 | -------------------------------------------------------------------------------- /routine_inspection/check_table_dml.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_table_dml.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: JAN 23, 2024 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.13.0.0 9 | REM 10 | REM Purpose: 11 | REM This sql script uses to check the dml situation for the specific table of the specific production user by dba_tab_modifications. 12 | REM 13 | 14 | SET LINESIZE 400 15 | SET PAGESIZE 200 16 | COLUMN table_name FORMAT a35 17 | 18 | SELECT table_name, 19 | inserts, 20 | updates, 21 | deletes, 22 | timestamp 23 | FROM dba_tab_modifications 24 | WHERE table_owner = upper('&table_owner') 25 | AND table_name = upper('&table_name') 26 | ORDER BY 1; 27 | -------------------------------------------------------------------------------- /routine_inspection/check_tbs_fragmentation_ratio.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_tbs_fragmentation_ratio.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Feb 19, 2024 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 19.13.0.0 9 | REM 10 | REM Purpose: 11 | REM This sql script uses to check all of the production tablespaces' fragmentation ratio of oracle database. 12 | REM 13 | 14 | set linesize 400 15 | set pagesize 400 16 | col tablespace_name for a30 17 | 18 | select a.tablespace_name, 19 | sqrt(max(a.blocks)/sum(a.blocks))*(100/sqrt(sqrt(count(a.blocks)))) FSFI 20 | from dba_free_space a, dba_tablespaces b 21 | where a.tablespace_name = b.tablespace_name 22 | and b.contents not in ('TEMPORARY','UNDO') 23 | group by a.tablespace_name 24 | order by 2; 25 | -------------------------------------------------------------------------------- /routine_inspection/check_total_size_oracle_db.sql: -------------------------------------------------------------------------------- 1 | -- Check total sizes of oracle database 2 | 3 | SELECT 4 | (SELECT SUM(bytes)/POWER(2, 30) AS data_size FROM dba_data_files) 5 | + 6 | (SELECT NVL(SUM(bytes), 0)/POWER(2, 30) AS temp_size FROM dba_temp_files) 7 | + 8 | (SELECT SUM(bytes)/POWER(2, 30) AS redo_size FROM sys.v$log) 9 | + 10 | (SELECT SUM(BLOCK_SIZE * FILE_SIZE_BLKS)/POWER(2, 30) AS controlfile_size FROM v$controlfile) AS "Size in GB" 11 | FROM 12 | dual 13 | / 14 | -------------------------------------------------------------------------------- /routine_inspection/connect_machine_via_sql_id.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: connect_machine_via_sql_id.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Feb 12, 2020 5 | REM 6 | REM Purpose: 7 | REM This sql script usually uses to check the machine name connecting to Oracle Database Server 8 | REM via inputting a specific value of SQL_ID. 9 | REM 10 | 11 | SET VERIFY OFF 12 | 13 | SET LINESIZE 150 14 | SET PAGESIZE 300 15 | 16 | COLUMN username FORMAT a18 17 | COLUMN machine FORMAT a15 18 | COLUMN client_info FORMAT a15 19 | 20 | SELECT b.username 21 | , b.machine 22 | , b.client_info 23 | FROM v$sql a 24 | , v$session b 25 | WHERE a.hash_value = b.sql_hash_value 26 | AND a.sql_id = '&sql_id' 27 | / 28 | -------------------------------------------------------------------------------- /routine_inspection/ctl_file_path_in_rman_backupsets.sql: -------------------------------------------------------------------------------- 1 | -- +----------------------------------------------------------------------------+ 2 | -- | Quanwen Zhao | 3 | -- | guestart@163.com | 4 | -- | quanwenzhao.wordpress.com | 5 | -- |----------------------------------------------------------------------------| 6 | -- | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 7 | -- |----------------------------------------------------------------------------| 8 | -- | DATABASE : Oracle | 9 | -- | FILE : ctl_file_path_in_rman_backupsets.sql | 10 | -- | CLASS : Administration | 11 | -- | PURPOSE : Query all of control file's locaiton in rman backupsets. | 12 | -- | NOTE : As with any code, ensure to test this script in a development | 13 | -- | environment before attempting to run it in production. | 14 | -- +----------------------------------------------------------------------------+ 15 | 16 | SET ECHO OFF 17 | SET FEEDBACK OFF 18 | SET HEADING ON 19 | SET LINESIZE 300 20 | SET PAGESIZE 300 21 | SET TERMOUT ON 22 | SET TIMING OFF 23 | SET TRIMOUT ON 24 | SET TRIMSPOOL ON 25 | SET VERIFY OFF 26 | 27 | COLUMN handle FORMAT a80 HEADING "Control File's Path In Rman Backupsets" 28 | 29 | SELECT 30 | distinct p.handle 31 | FROM v$backup_piece_details p 32 | , v$backup_set_details s 33 | WHERE p.bs_key = s.bs_key 34 | AND s.device_type = 'DISK' 35 | AND s.controlfile_included = 'YES' 36 | ORDER BY 1 DESC 37 | / 38 | -------------------------------------------------------------------------------- /routine_inspection/db_buffer_cache_hit_ratio.sql: -------------------------------------------------------------------------------- 1 | -- +----------------------------------------------------------------+ 2 | -- | | 3 | -- | File Name : ~/db_buffer_cache_hit_ratio.sql | 4 | -- | | 5 | -- | Author : Quanwen Zhao | 6 | -- | | 7 | -- | Description : Display cache hit ratio for the oracle database | 8 | -- | | 9 | -- | Comments : The minimum figure of 89% is often quoted, but | 10 | -- | | 11 | -- | depending on the type of system this may not | 12 | -- | | 13 | -- | be possible. | 14 | -- | | 15 | -- | Requirements : Access to the v$sysstat views. | 16 | -- | | 17 | -- | Call Synatix : @db_buffer_cache_hit_ratio | 18 | -- | | 19 | -- | Last Modified: 03/08/2016 (dd/mm/yyyy) | 20 | -- | | 21 | -- +----------------------------------------------------------------+ 22 | 23 | PROMPT 24 | PROMPT Hit ratio should exceed 89% 25 | 26 | COLUMN hit_ratio FORMAT a10 27 | 28 | SELECT Round((1 - Sum(Decode(name,'physical reads',value,0)) / 29 | (Sum(Decode(name,'db block gets',value,0)) + 30 | Sum(Decode(name,'consistent gets',value,0))) ),4) *100 31 | || '%' hit_ratio 32 | FROM v$sysstat 33 | / 34 | -------------------------------------------------------------------------------- /routine_inspection/get_dyn_perf_view_def.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: get_dyn_perf_view_def.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 06, 2019 5 | REM 6 | REM Notice: 7 | REM SQL> desc v$fixed_view_definition 8 | REM Name Null? Type 9 | REM ----------------------------------------- -------- ---------------------------- 10 | REM VIEW_NAME VARCHAR2(30) 11 | REM VIEW_DEFINITION VARCHAR2(4000) 12 | REM 13 | REM Purpose: 14 | REM This SQL script usually uses to get the definition of dynamic performance view on Oracle Database. 15 | REM 16 | 17 | SET VERIFY OFF 18 | SET PAGESIZE 400 19 | 20 | PROMPT ===================== 21 | PROMPT running on SYS schema 22 | PROMPT ===================== 23 | 24 | SELECT view_definition 25 | FROM v$fixed_view_definition 26 | WHERE view_name = UPPER ('&view_name') 27 | / 28 | 29 | -- A simple demo here which I give. 30 | -- 31 | -- SQL> SELECT view_definition 32 | -- 2 FROM v$fixed_view_definition 33 | -- 3 WHERE view_name = UPPER ('&view_name') 34 | -- 4 / 35 | -- Enter value for view_name: gv$temp_space_header 36 | -- 37 | -- VIEW_DEFINITION 38 | -- -------------------------------------------------------------------------------- 39 | -- select /*+ ordered use_nl(hc) */ hc.inst_id, ts.name, hc.ktfthctfno, (hc.ktfthcs 40 | -- z - hc.ktfthcfree)*ts.blocksize, (hc.ktfthcsz - hc.ktfthcfree), hc.ktfthcfree*ts 41 | -- .blocksize, hc.ktfthcfree, hc.ktfthcfno from ts$ ts, x$ktfthc hc where ts.conten 42 | -- ts$ = 1 and ts.bitmapped <> 0 and ts.online$ = 1 and ts.ts# = hc.ktfthctsn and h 43 | -- c.ktfthccval = 0 44 | -------------------------------------------------------------------------------- /routine_inspection/get_dyn_perf_view_def_2.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: get_dyn_perf_view_def_2.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 06, 2019 5 | REM 6 | REM Notice: 7 | REM SQL> desc v$fixed_view_definition 8 | REM Name Null? Type 9 | REM ----------------------------------------- -------- ---------------------------- 10 | REM VIEW_NAME VARCHAR2(30) 11 | REM VIEW_DEFINITION VARCHAR2(4000) 12 | REM 13 | REM Purpose: 14 | REM The 2nd version of SQL script "get_dyn_perf_view_def.sql" - using "accept" of SQL*Plus command on Oracle Database. 15 | REM 16 | 17 | SET VERIFY OFF 18 | SET PAGESIZE 400 19 | 20 | PROMPT ===================== 21 | PROMPT running on SYS schema 22 | PROMPT ===================== 23 | 24 | ACCEPT view_name char PROMPT 'Please input a value of VIEW_NAME: '; 25 | 26 | SELECT view_definition 27 | FROM v$fixed_view_definition 28 | WHERE view_name = UPPER ('&view_name') 29 | / 30 | 31 | -- A simple demo here which I give. 32 | -- 33 | -- SQL> @get_dyn_perf_view_def_2.sql 34 | -- ===================== 35 | -- running on SYS schema 36 | -- ===================== 37 | -- Please input a value of VIEW_NAME: gv$temp_space_header 38 | -- 39 | -- VIEW_DEFINITION 40 | -- -------------------------------------------------------------------------------- 41 | -- select /*+ ordered use_nl(hc) */ hc.inst_id, ts.name, hc.ktfthctfno, (hc.ktfthcs 42 | -- z - hc.ktfthcfree)*ts.blocksize, (hc.ktfthcsz - hc.ktfthcfree), hc.ktfthcfree*ts 43 | -- .blocksize, hc.ktfthcfree, hc.ktfthcfno from ts$ ts, x$ktfthc hc where ts.conten 44 | -- ts$ = 1 and ts.bitmapped <> 0 and ts.online$ = 1 and ts.ts# = hc.ktfthctsn and h 45 | -- c.ktfthccval = 0 46 | -------------------------------------------------------------------------------- /routine_inspection/get_dyn_perf_view_def_3.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: get_dyn_perf_view_def_3.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 07, 2019 5 | REM 6 | REM Notice: 7 | REM SQL> desc v$fixed_view_definition 8 | REM Name Null? Type 9 | REM ----------------------------------------- -------- ---------------------------- 10 | REM VIEW_NAME VARCHAR2(30) 11 | REM VIEW_DEFINITION VARCHAR2(4000) 12 | REM 13 | REM Purpose: 14 | REM The 3rd version of SQL script "get_dyn_perf_view_def.sql" - calling SQL Script "get_dyn_perf_view_def_3.sql" 15 | REM meanwhile passing in argument on Oracle Database. 16 | REM 17 | 18 | SET VERIFY OFF 19 | SET PAGESIZE 400 20 | 21 | PROMPT ===================== 22 | PROMPT running on SYS schema 23 | PROMPT ===================== 24 | 25 | SELECT view_definition 26 | FROM v$fixed_view_definition 27 | WHERE view_name = UPPER ('&1') 28 | / 29 | 30 | -- A simple demo here which I give. 31 | -- 32 | -- SQL> @get_dyn_perf_view_def_3.sql gv$temp_space_header 33 | -- ===================== 34 | -- running on SYS schema 35 | -- ===================== 36 | -- 37 | -- VIEW_DEFINITION 38 | -- -------------------------------------------------------------------------------- 39 | -- select FILE# , CREATION_CHANGE# , CREATION_TIME , TS# , RFILE# , STATUS , ENABL 40 | -- ED , BYTES, BLOCKS, CREATE_BYTES , BLOCK_SIZE , NAME from GV$TEMPFILE where inst 41 | -- _id = USERENV('Instance') 42 | -------------------------------------------------------------------------------- /routine_inspection/listagg_redo_log_group_members_2.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: listagg_redo_log_group_members_2.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jun 04, 2023 5 | REM 6 | REM Last tested: 7 | REM 11.2.0.4 8 | REM 12.2.0.1 9 | REM 19.3.0.0 10 | REM 11 | REM Purpose: 12 | REM The SQL script file describes how to listagg oracle redo log members (if it is Oracle Data Guard, also including standby redo log members) in each redo log group using ', ' 13 | REM in order to make them locate on the same line. 14 | REM 15 | 16 | set linesize 200 17 | set pagesize 100 18 | column member format a95 19 | with llf as ( 20 | select l.thread#, 21 | l.group#, 22 | decode(lf.type, 'ONLINE', 'Redo Log') type, 23 | listagg(lf.member, ', ') within group (order by lf.member) as member, 24 | l.bytes/1024/1024 size_mb, 25 | l.status 26 | from v$log l, v$logfile lf 27 | where l.group# = lf.group# 28 | group by l.thread#, 29 | l.group#, 30 | decode(lf.type, 'ONLINE', 'Redo Log'), 31 | l.bytes, 32 | l.status 33 | order by 1, 2 34 | ), 35 | sllf as ( 36 | select sl.thread#, 37 | sl.group#, 38 | decode(lf.type, 'STANDBY', 'Standby Redo Log') type, 39 | listagg(lf.member, ', ') within group (order by lf.member) as member, 40 | sl.bytes/1024/1024 size_mb, 41 | sl.status 42 | from v$standby_log sl, v$logfile lf 43 | where sl.group# = lf.group# 44 | group by sl.thread#, 45 | sl.group#, 46 | decode(lf.type, 'STANDBY', 'Standby Redo Log'), 47 | sl.bytes, 48 | sl.status 49 | order by 1, 2 50 | ) 51 | select * from llf 52 | union all 53 | select * from sllf; 54 | -------------------------------------------------------------------------------- /routine_inspection/per_machine_act_conn_num_aggr_by_user.sql: -------------------------------------------------------------------------------- 1 | -- Adding the first following 6 lines code to sys user's trigger directory. 2 | 3 | CREATE OR REPLACE TRIGGER on_logon_trigger 4 | AFTER LOGON ON DATABASE 5 | BEGIN 6 | DBMS_APPLICATION_INFO.SET_CLIENT_INFO(SYS_CONTEXT('userenv', 'ip_address')); 7 | END; 8 | / 9 | 10 | REM 11 | REM Script: per_machine_act_conn_num_aggr_by_user.sql 12 | REM Author: Quanwen Zhao 13 | REM Dated: May 11, 2019 14 | REM Updated: May 15, 2019 15 | REM Updated: Jun 22, 2020 16 | Eliminating the WHERE clause of "username" and "status", only retaining the WHERE clause of "program", 17 | otherwise, being not able to find the important info connecting to Oracle Database by App Server. 18 | REM 19 | REM Purpose: 20 | REM This sql script shows per machine's active connect numbers after aggregating by username on v$session, 21 | REM meanwhile/furthermore shows column client_info, that's to say, client's ip address. 22 | REM 23 | SET LINESIZE 200 24 | SET PAGESIZE 200 25 | COLUMN username FORMAT a25 26 | COLUMN machine FORMAT a20 27 | COLUMN client_info FORMAT a15 28 | COLUMN program FORMAT a16 29 | COLUMN status FORMAT a8 30 | SELECT username 31 | , machine 32 | , client_info 33 | , program 34 | , status 35 | , count(*) 36 | FROM v$session 37 | -- WHERE username IS NOT NULL 38 | -- AND status = 'ACTIVE' 39 | WHERE program = 'JDBC Thin Client' 40 | GROUP BY username 41 | , machine 42 | , client_info 43 | , program 44 | , status 45 | ORDER BY count(*) DESC 46 | , status 47 | / 48 | -------------------------------------------------------------------------------- /routine_inspection/spfile_path_in_rman_backupsets.sql: -------------------------------------------------------------------------------- 1 | -- +----------------------------------------------------------------------------+ 2 | -- | Quanwen Zhao | 3 | -- | guestart@163.com | 4 | -- | quanwenzhao.wordpress.com | 5 | -- |----------------------------------------------------------------------------| 6 | -- | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. | 7 | -- |----------------------------------------------------------------------------| 8 | -- | DATABASE : Oracle | 9 | -- | FILE : spfile_path_in_rman_backupsets.sql | 10 | -- | CLASS : Administration | 11 | -- | PURPOSE : Query all of spfile's locaiton in rman backupsets. | 12 | -- | NOTE : As with any code, ensure to test this script in a development | 13 | -- | environment before attempting to run it in production. | 14 | -- +----------------------------------------------------------------------------+ 15 | 16 | SET ECHO OFF 17 | SET FEEDBACK OFF 18 | SET HEADING ON 19 | SET LINESIZE 300 20 | SET PAGESIZE 300 21 | SET TERMOUT ON 22 | SET TIMING OFF 23 | SET TRIMOUT ON 24 | SET TRIMSPOOL ON 25 | SET VERIFY OFF 26 | 27 | COLUMN handle FORMAT a80 HEADING "Spfile's Path In Rman Backupsets" 28 | 29 | SELECT 30 | distinct p.handle 31 | FROM v$backup_piece_details p 32 | , v$backup_spfile sp 33 | , v$backup_spfile_details s 34 | WHERE p.bs_key = s.bs_key 35 | AND p.status = 'A' 36 | AND p.device_type = 'DISK' 37 | ORDER BY 1 DESC 38 | / 39 | -------------------------------------------------------------------------------- /routine_inspection/tablespace_per_used_size_and_rollup.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: tablespace_per_used_size_and_rollup.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 30, 2019 5 | REM Updated: Nov 01, 2019 6 | REM Replacing "SUM(bytes_cached)/1024/1024 AS used" with "SUM(bytes_used)/1024/1024 AS used" 7 | REM on table "v$temp_extent_pool". 8 | REM 9 | REM Purpose: 10 | REM This SQL script usually uses to check the used size of per tablespace (and all) using "rollup" clause on Oracle Database. 11 | REM 12 | 13 | SET LINESIZE 10000 14 | SET PAGESIZE 10000 15 | 16 | COLUMN ts_name FORMAT a25 17 | COLUMN used_mb FORMAT 999,999,999.99 18 | 19 | WITH tu AS (SELECT tablespace_name 20 | , bytes 21 | FROM dba_segments 22 | UNION ALL 23 | SELECT tablespace_name 24 | -- , bytes_cached AS bytes 25 | , bytes_used AS bytes 26 | FROM v$temp_extent_pool 27 | ) 28 | SELECT tu.tablespace_name AS ts_name 29 | , SUM(tu.bytes)/1024/1024 AS used_mb 30 | FROM tu 31 | GROUP BY rollup(tu.tablespace_name) 32 | ORDER BY 1 33 | / 34 | 35 | -- A demo of looking likes the following output result. 36 | 37 | TS_NAME USED_MB 38 | ------------------------- --------------- 39 | SYSAUX 55,893.19 40 | SYSTEM 794.38 41 | WWW_XXXXXXXXXXX 512,485.75 42 | WWW_XXXXXXXXXXX_TEMP 32,766.00 43 | WWW_YYYYYYYYYYY 10.00 44 | TEMP 32,439.00 45 | UNDOTBS1 4,976.31 46 | USERS 2,625.13 47 | 641,989.75 <<== All of tablespaces' total used sizes 48 | 49 | 9 rows selected. 50 | -------------------------------------------------------------------------------- /routine_inspection/tablespace_used_size_1.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: tablespace_used_size_1.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 30, 2019 5 | REM Updated: Nov 01, 2019 6 | REM Replacing "SUM(bytes_cached)/1024/1024 AS used" with "SUM(bytes_used)/1024/1024 AS used" 7 | REM on table "v$temp_extent_pool". 8 | REM 9 | REM Purpose: 10 | REM This SQL script usually uses to check the used size of tablespace on Oracle Database. 11 | REM 12 | 13 | SET LINESIZE 10000 14 | SET PAGESIZE 10000 15 | 16 | COLUMN ts_name FORMAT a25 17 | COLUMN used_mb FORMAT 999,999,999.99 18 | 19 | WITH a AS (SELECT tablespace_name 20 | , SUM(bytes)/1024/1024 AS total 21 | FROM dba_data_files 22 | GROUP BY tablespace_name 23 | ), 24 | b AS (SELECT tablespace_name 25 | , SUM(bytes)/1024/1024 AS free 26 | FROM dba_free_space 27 | GROUP BY tablespace_name 28 | ), 29 | -- c AS (SELECT tablespace_name 30 | -- , SUM(bytes)/1024/1024 AS total 31 | -- FROM dba_temp_files 32 | -- GROUP BY tablespace_name 33 | -- ), 34 | d AS (SELECT tablespace_name 35 | -- , SUM(bytes_cached)/1024/1024 AS used 36 | , SUM(bytes_used)/1024/1024 AS used 37 | FROM v$temp_extent_pool 38 | GROUP BY tablespace_name 39 | ) 40 | SELECT a.tablespace_name AS ts_name 41 | , a.total - b.free AS "USED_MB" 42 | FROM a, b 43 | WHERE a.tablespace_name = b.tablespace_name 44 | UNION ALL 45 | SELECT d.tablespace_name AS ts_name 46 | -- c.tablespace_name AS ts_name 47 | , d.used AS "USED_MB" 48 | -- FROM c, d 49 | FROM d 50 | -- WHERE c.tablespace_name = d.tablespace_name 51 | ORDER BY 1 52 | / 53 | -------------------------------------------------------------------------------- /routine_inspection/tablespace_used_size_2.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: tablespace_used_size_2.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Oct 30, 2019 5 | REM Updated: Nov 01, 2019 6 | REM Replacing "SUM(bytes_cached)/1024/1024 AS used" with "SUM(bytes_used)/1024/1024 AS used" 7 | REM on table "v$temp_extent_pool". 8 | REM 9 | REM Purpose: 10 | REM This SQL script usually uses to check the used size of tablespace on Oracle Database. 11 | REM 12 | 13 | SET LINESIZE 10000 14 | SET PAGESIZE 10000 15 | 16 | COLUMN ts_name FORMAT a25 17 | COLUMN used_mb FORMAT 999,999,999.99 18 | 19 | SELECT tablespace_name AS ts_name 20 | , sum(bytes)/1024/1024 AS used_mb 21 | FROM dba_segments 22 | GROUP BY tablespace_name 23 | UNION ALL 24 | SELECT tablespace_name AS ts_name 25 | -- , SUM(bytes_cached)/1024/1024 AS used_mb 26 | , SUM(bytes_used)/1024/1024 AS used 27 | FROM v$temp_extent_pool 28 | GROUP BY tablespace_name 29 | ORDER BY 1 30 | / 31 | -------------------------------------------------------------------------------- /routine_inspection/temporary_tablespace_used_size.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: temporary_tablespace_used_size.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Nov 15, 2019 5 | REM Updated: Nov 18, 2019 6 | REM Modifying View "tbk" (writing within "WITH ... AS ...") to be neithor "grouping by tablespace" nor "SUM(blocks)". 7 | REM 8 | REM Purpose: 9 | REM This SQL script usually uses to check the used size of all of TEMPORARY tablespaces on Oracle Database. 10 | REM 11 | REM Last tested: 12 | REM 11.2.0.4 13 | REM 14 | 15 | SET LINESIZE 200 16 | SET PAGESIZE 200 17 | 18 | COLUMN tablespace FORMAT a25 19 | COLUMN used_mb FORMAT 999,999,999,999 20 | 21 | WITH tbk AS ( SELECT tablespace 22 | -- , SUM(blocks) AS bn 23 | , blocks 24 | FROM v$tempseg_usage 25 | -- GROUP BY tablespace 26 | ORDER BY 1 27 | ), 28 | tbs AS ( SELECT t.ts# 29 | , t.blocksize 30 | , tf.block_size 31 | FROM ts$ t, v$tempfile tf 32 | WHERE t.ts# = tf.ts# 33 | ORDER BY 1 34 | ), 35 | tn AS ( SELECT ts# 36 | , name 37 | FROM v$tablespace 38 | ORDER BY 1 39 | ) 40 | SELECT tbk.tablespace 41 | , tbs.block_size 42 | -- , SUM(tbk.bn) AS blocks 43 | , (SUM(tbk.blocks) * tbs.block_size)/POWER(2,20) AS used_mb 44 | FROM tbk, tn, tbs 45 | WHERE tbk.tablespace = tn.name 46 | AND tn.ts# = tbs.ts# 47 | GROUP BY tbk.tablespace 48 | , tbs.block_size 49 | ORDER BY 1 50 | / 51 | 52 | -- TABLESPACE BLOCK_SIZE BLOCKS USED_MB 53 | -- ------------------------- ---------- ----------- ---------------- 54 | -- WWW_XXXXXXXXXXX_TEMP 8192 2304 18 55 | -- TEMP 8192 128 1 56 | -- 57 | -- 2 rows selected. 58 | -------------------------------------------------------------------------------- /routine_inspection/top_10_segment_on_sysaux_tbs.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top_10_segment_on_sysaux_tbs.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 11, 2019 5 | REM 6 | REM Purpose: 7 | REM This sql script shows top 10 segment objects on sysaux tablespace. 8 | REM 9 | 10 | SET LINESIZE 300 11 | COLUMN segment_name FORMAT a35 12 | COLUMN segment_type FORMAT a20 13 | COLUMN owner FORMAT a8 14 | 15 | SELECT * FROM 16 | (SELECT segment_name 17 | , bytes/1024/1024 AS mb 18 | , segment_type 19 | , owner 20 | FROM dba_segments 21 | WHERE tablespace_name = 'SYSAUX' 22 | ORDER BY bytes DESC 23 | ) 24 | WHERE rownum < 10 25 | / 26 | -------------------------------------------------------------------------------- /routine_inspection/top_10_segment_on_system_tbs.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top_10_segment_on_system_tbs.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 11, 2019 5 | REM 6 | REM Purpose: 7 | REM This sql script shows top 10 segment objects on system tablespace. 8 | REM 9 | 10 | SET LINESIZE 300 11 | COLUMN segment_name FORMAT a25 12 | COLUMN segment_type FORMAT a10 13 | COLUMN owner FORMAT a8 14 | 15 | SELECT * FROM 16 | (SELECT segment_name 17 | , bytes/1024/1024 AS mb 18 | , segment_type 19 | , owner 20 | FROM dba_segments 21 | WHERE tablespace_name = 'SYSTEM' 22 | ORDER BY bytes DESC 23 | ) 24 | WHERE rownum < 10 25 | / 26 | -------------------------------------------------------------------------------- /routine_inspection/top_10_segments_on_specific_tbs.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: top_10_segments_on_specific_tbs.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jan 30, 2024 5 | REM 6 | REM Purpose: 7 | REM This sql script shows top 10 segment objects on specific tablespace. 8 | REM 9 | 10 | set linesize 400 11 | set pagesize 100 12 | col segment_name for a35 13 | 14 | select * from ( 15 | select segment_name, 16 | segment_type, 17 | round(sum(bytes)/1024/1024/1024, 2) size_gb 18 | from dba_segments 19 | where tablespace_name = upper('&ts_name') 20 | group by segment_name, segment_type 21 | order by 3 desc 22 | ) where rownum <= 10; 23 | -------------------------------------------------------------------------------- /routine_inspection/ts_used_size_with_lob_in_recyclebin.sql: -------------------------------------------------------------------------------- 1 | SELECT t.tablespace_name, 2 | nvl(s.used_bytes,0)/power(2,20) AS used_size_mb, 3 | f.sum_bytes/power(2,20) AS sum_size_mb, 4 | round(decode(f.sum_bytes,0,0,nvl(s.used_bytes,0)/f.sum_bytes*100),2) AS used_rate, 5 | f.autoext, 6 | f.status, 7 | t.bigfile 8 | FROM dba_tablespaces t 9 | LEFT JOIN (SELECT tablespace_name, 10 | SUM(bytes) used_bytes 11 | FROM dba_segments 12 | WHERE segment_name NOT LIKE 'BIN$%' 13 | GROUP BY tablespace_name 14 | ) s 15 | ON t.tablespace_name = s.tablespace_name 16 | INNER JOIN (SELECT tablespace_name, 17 | min(online_status) AS status, 18 | DECODE(SUM(DECODE(autoextensible,'NO',0,1)),0,'NO','YES') AS autoext, 19 | sum(case autoextensible when 'YES' then maxbytes else bytes end) AS sum_bytes 20 | FROM dba_data_files 21 | GROUP BY tablespace_name 22 | ) f 23 | ON t.tablespace_name = f.tablespace_name 24 | ORDER BY 1; 25 | -------------------------------------------------------------------------------- /routine_inspection/ts_used_size_without_lob_in_recyclebin.sql: -------------------------------------------------------------------------------- 1 | SELECT t.tablespace_name, 2 | nvl(sr.used_bytes,0)/power(2,20) AS used_size_mb, 3 | f.sum_bytes/power(2,20) AS sum_size_mb, 4 | round(decode(f.sum_bytes,0,0,nvl(sr.used_bytes,0)/f.sum_bytes*100),2) AS used_rate, 5 | f.autoext, 6 | f.status, 7 | t.bigfile 8 | FROM dba_tablespaces t 9 | LEFT JOIN (WITH ds_not_bin AS 10 | (SELECT tablespace_name, 11 | SUM(bytes) used_bytes 12 | FROM dba_segments 13 | WHERE segment_name NOT LIKE 'BIN$%' 14 | GROUP BY tablespace_name 15 | ), 16 | ds_rec_lob AS 17 | (SELECT ts_name, 18 | SUM(space*8192) used_bytes 19 | FROM dba_recyclebin 20 | WHERE type LIKE 'LOB%' 21 | GROUP BY ts_name 22 | ) 23 | SELECT dnb.tablespace_name, 24 | dnb.used_bytes - nvl(drl.used_bytes,0) used_bytes 25 | FROM ds_not_bin dnb 26 | LEFT JOIN ds_rec_lob drl 27 | ON dnb.tablespace_name = drl.ts_name 28 | ) sr 29 | ON t.tablespace_name = sr.tablespace_name 30 | INNER JOIN (SELECT tablespace_name, 31 | min(online_status) AS status, 32 | DECODE(SUM(DECODE(autoextensible,'NO',0,1)),0,'NO','YES') AS autoext, 33 | sum(case autoextensible when 'YES' then maxbytes else bytes end) AS sum_bytes 34 | FROM dba_data_files 35 | GROUP BY tablespace_name 36 | ) f 37 | ON t.tablespace_name = f.tablespace_name 38 | ORDER BY 1; 39 | -------------------------------------------------------------------------------- /sql_tuning/check_data_dictionary_tables_and_views.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_data_dictionary_tables_and_views.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 19, 2018 5 | REM 6 | REM Last tested 7 | REM 11.2.0.4 8 | REM Purpose: 9 | REM This sql script usually checks the Oracle data dictionary tables and views. 10 | REM 11 | 12 | SET LINESIZE 200 13 | SET PAGESIZE 200 14 | 15 | COLUMN table_name FORMAT a30 16 | COLUMN comments FORMAT a65 17 | 18 | SELECT * FROM dict WHERE table_name LIKE 'DBA_HIST_SQL%' 19 | / 20 | 21 | SELECT * FROM dict WHERE table_name LIKE 'V%SQL%' 22 | / 23 | 24 | SET LINESIZE 80 25 | SET PAGESIZE 14 26 | -------------------------------------------------------------------------------- /sql_tuning/check_sql_execution_plan_table.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_sql_execution_plan_table.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 19, 2018 5 | REM 6 | REM Last tested 7 | REM 11.2.0.4 8 | REM Purpose: 9 | REM This sql script usually checks the SQL statement's execution plan. 10 | REM 11 | SET LINESIZE 200 12 | SET PAGESIZE 200 13 | SET VERIFY OFF 14 | SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR('&sql_id',NULL,'ALLSTATS ALL')); 15 | SET VERIFY ON 16 | SET LINESIZE 80 17 | SET PAGESIZE 14 18 | -------------------------------------------------------------------------------- /sql_tuning/check_sql_multiple_execution_plans.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_sql_multiple_execution_plans.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 19, 2018 5 | REM 6 | REM Last tested 7 | REM 11.2.0.4 8 | REM Purpose: 9 | REM This sql script usually checks whether there have multiple execution plans for the sql specified. 10 | REM 11 | 12 | SET LINESIZE 200 13 | SET PAGESIZE 200 14 | 15 | SET VERIFY OFF 16 | 17 | COLUMN sample_time FORMAT a25 18 | COLUMN sql_id FORMAT a13 19 | 20 | SELECT h.sample_time 21 | , h.sql_id 22 | , s.hash_value 23 | , h.sql_plan_hash_value 24 | -- FROM v$active_session_history h, v$sql s 25 | FROM dba_hist_active_sess_history h, v$sql s 26 | WHERE h.sql_id = s.sql_id 27 | AND h.sample_time BETWEEN to_date('&start_time', 'yyyy-mm-dd hh24:mi:ss') 28 | AND to_date('&end_time', 'yyyy-mm-dd hh24:mi:ss') 29 | AND h.sql_id = '&sql_id' 30 | ORDER BY h.sample_time desc 31 | , h.sql_plan_hash_value 32 | / 33 | 34 | SET VERIFY ON 35 | 36 | SET LINESIZE 80 37 | SET PAGESIZE 14 38 | -------------------------------------------------------------------------------- /sql_tuning/check_sql_multiple_execution_plans_2.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: check_sql_multiple_execution_plans_2.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 19, 2018 5 | REM 6 | REM Last tested 7 | REM 11.2.0.4 8 | REM Purpose: 9 | REM This sql script usually checks whether there have multiple execution plans for the sql specified. 10 | REM 11 | 12 | SET LINESIZE 200 13 | SET PAGESIZE 200 14 | 15 | SET VERIFY OFF 16 | 17 | COLUMN sample_time FORMAT a25 18 | COLUMN sql_id FORMAT a13 19 | 20 | SELECT h.sql_id 21 | , s.hash_value 22 | , h.sql_plan_hash_value 23 | , count(*) AS total_num 24 | FROM dba_hist_active_sess_history h, v$sql s 25 | -- FROM v$active_session_history h, v$sql s 26 | WHERE h.sql_id = s.sql_id 27 | AND h.sample_time BETWEEN to_date('&start_time', 'yyyy-mm-dd hh24:mi:ss') 28 | AND to_date('&end_time', 'yyyy-mm-dd hh24:mi:ss') 29 | AND h.sql_id = '&sql_id' 30 | GROUP BY h.sql_plan_hash_value 31 | , h.sql_id 32 | , s.hash_value 33 | ORDER BY total_num desc 34 | , h.sql_plan_hash_value 35 | / 36 | 37 | SET VERIFY ON 38 | 39 | SET LINESIZE 80 40 | SET PAGESIZE 14 41 | -------------------------------------------------------------------------------- /sql_tuning/user_index_columns.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: user_index_columns.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Mar 29, 2020 5 | REM 6 | REM Last tested: 7 | REM 19.3.0.0 8 | REM 9 | REM Purpose: 10 | REM This sql script checks the related index columns info by inputting a table name 11 | REM when using SQL*Plus to connect to a user on Oracle Database. 12 | REM 13 | 14 | SET VERIFY OFF 15 | 16 | SET LINESIZE 300 17 | SET PAGESIZE 150 18 | 19 | COLUMN index_name FORMAT a30 20 | COLUMN column_name FORMAT a30 21 | COLUMN descend FORMAT a7 22 | 23 | SELECT index_name 24 | , column_name 25 | , descend 26 | FROM user_ind_columns 27 | WHERE table_name = UPPER('&tabname') 28 | ORDER BY index_name 29 | , column_name 30 | ; 31 | -------------------------------------------------------------------------------- /sql_tuning/user_index_expressions.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: user_index_expressions.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Mar 29, 2020 5 | REM 6 | REM Last tested: 7 | REM 19.3.0.0 8 | REM 9 | REM Purpose: 10 | REM This sql script checks the related index expressions on several columns 11 | REM by inputting a table name when using SQL*Plus to connect to a user on Oracle Database. 12 | REM 13 | 14 | SET VERIFY OFF 15 | 16 | SET LINESIZE 300 17 | SET PAGESIZE 150 18 | 19 | COLUMN index_name FORMAT a30 20 | COLUMN column_expression FORMAT a35 21 | 22 | SELECT index_name 23 | , column_expression 24 | FROM user_ind_expressions 25 | WHERE table_name = UPPER('&tabname') 26 | ORDER BY index_name 27 | ; 28 | -------------------------------------------------------------------------------- /sql_tuning/user_indexes.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: user_indexes.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Mar 29, 2020 5 | REM 6 | REM Last tested: 7 | REM 19.3.0.0 8 | REM 9 | REM Purpose: 10 | REM This sql script checks the related indexes info by inputting a table name 11 | REM when using SQL*Plus to connect to a user on Oracle Database. 12 | REM 13 | 14 | SET VERIFY OFF 15 | 16 | SET LINESIZE 300 17 | SET PAGESIZE 150 18 | 19 | ALTER SESSION SET nls_date_format = 'YYYY-MM-DD'; 20 | 21 | COLUMN index_name FORMAT a30 22 | COLUMN index_type FORMAT a30 23 | COLUMN visibility FORMAT a10 24 | COLUMN last_analyzed FORMAT a13 25 | 26 | SELECT index_name 27 | , index_type 28 | , blevel 29 | , leaf_blocks 30 | , clustering_factor 31 | , status 32 | , visibility 33 | , num_rows 34 | , last_analyzed 35 | FROM user_indexes 36 | WHERE table_name = UPPER('&tabname') 37 | ORDER BY index_name 38 | , clustering_factor 39 | ; 40 | -------------------------------------------------------------------------------- /statistics_info/table_column_statistics.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: table_column_statistics.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: Jul 10, 2018 5 | REM 6 | REM Last tested 7 | REM 11.2.0.4 8 | REM Purpose: 9 | REM This sql script usually checks the statistics of column of table. 10 | REM 11 | 12 | SET LINESIZE 200 13 | SET PAGESIZE 100 14 | 15 | SET VERIFY OFF 16 | 17 | COLUMN column_name FORMAT a15 18 | 19 | SELECT column_name 20 | , num_distinct 21 | , density 22 | , num_nulls 23 | , num_buckets 24 | , last_analyzed 25 | , sample_size 26 | , global_stats 27 | , histogram 28 | FROM dba_tab_col_statistics 29 | WHERE owner = UPPER('&OWNER') 30 | AND table_name = UPPER('&TABLE_NAME') 31 | AND column_name = UPPER('&COLUMN_NAME') 32 | ORDER BY 2 DESC 33 | / 34 | 35 | SET VERIFY ON 36 | 37 | SET LINESIZE 80 38 | SET PAGESIZE 14 39 | -------------------------------------------------------------------------------- /statistics_info/table_mods_on_proc_user.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: table_mods_on_proc_user.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 14, 2018 5 | REM 6 | REM Purpose: 7 | REM This sql script usually views information of modifications for username and tablename (or only username) 8 | REM which need to input manually as the parameter of substitution variable on SQL*Plus. These modifications 9 | REM columns include "table_name", "inserts", "updates", "deletes", "timestamp", "truncated" and "drop_segments". 10 | REM 11 | 12 | SET VERIFY OFF 13 | SET FEEDBACK OFF 14 | 15 | SET LINESIZE 300 16 | SET PAGESIZE 300 17 | 18 | COLUMN table_owner FORMAT a20 19 | COLUMN table_name FORMAT a25 20 | COLUMN truncated FORMAT a5 21 | 22 | SELECT table_owner 23 | , table_name 24 | , inserts 25 | , updates 26 | , deletes 27 | , timestamp 28 | , truncated 29 | , drop_segments 30 | FROM dba_tab_modifications 31 | WHERE table_owner = UPPER('&username') 32 | AND ( table_name = UPPER('&tablename') 33 | AND table_name NOT LIKE 'BIN$%' 34 | ) 35 | ORDER BY timestamp DESC 36 | , table_owner 37 | , table_name 38 | ; 39 | 40 | PROMPT 41 | 42 | SELECT table_owner 43 | , table_name 44 | , inserts 45 | , updates 46 | , deletes 47 | , timestamp 48 | , truncated 49 | , drop_segments 50 | FROM dba_tab_modifications 51 | WHERE table_owner = UPPER('&username') 52 | AND table_name NOT LIKE 'BIN$%' 53 | ORDER BY timestamp DESC 54 | , table_name 55 | ; 56 | 57 | PROMPT 58 | 59 | SET VERIFY ON 60 | SET FEEDBACK ON 61 | -------------------------------------------------------------------------------- /statistics_info/table_stats_on_proc_user.sql: -------------------------------------------------------------------------------- 1 | REM 2 | REM Script: table_stats_on_proc_user.sql 3 | REM Author: Quanwen Zhao 4 | REM Dated: May 14, 2018 5 | REM 6 | REM Purpose: 7 | REM This sql script usually views information of stats for username and tablename (or only username) 8 | REM which need to input manually as the parameter of substitution variable on SQL*Plus. These stats 9 | REM columns include "table_name", "num_rows", "blocks", "sample_size", "last_analyzed" and "stale_stats". 10 | REM 11 | 12 | SET VERIFY OFF 13 | SET FEEDBACK OFF 14 | 15 | SET LINESIZE 300 16 | SET PAGESIZE 300 17 | 18 | COLUMN owner FORMAT a20 19 | COLUMN table_name FORMAT a35 20 | COLUMN stale_stats FORMAT a11 21 | 22 | SELECT owner 23 | , table_name 24 | , num_rows 25 | , blocks 26 | , sample_size 27 | , last_analyzed 28 | , stale_stats 29 | FROM dba_tab_statistics 30 | WHERE owner = UPPER('&username') 31 | AND ( table_name = UPPER('&tablename') 32 | AND table_name NOT LIKE 'BIN$%' 33 | ) 34 | ORDER BY stale_stats DESC 35 | , last_analyzed DESC 36 | , table_name 37 | ; 38 | 39 | PROMPT 40 | 41 | SELECT owner 42 | , table_name 43 | , num_rows 44 | , blocks 45 | , sample_size 46 | , last_analyzed 47 | , stale_stats 48 | FROM dba_tab_statistics 49 | WHERE owner = UPPER('&username') 50 | AND table_name NOT LIKE 'BIN$%' 51 | ORDER BY stale_stats DESC 52 | , last_analyzed DESC 53 | , table_name 54 | ; 55 | 56 | PROMPT 57 | 58 | SET VERIFY ON 59 | SET FEEDBACK ON 60 | --------------------------------------------------------------------------------