Skip to content

Instantly share code, notes, and snippets.

@davidhooey
davidhooey / oracle_segment_advisor_for_individual_segments.sql
Last active January 26, 2016 21:23
Oracle Segment Advisor for Individual Segments
--
-- Segment Advisor for Individual Segments
--
-- 1. Replace all occurances of [OWNER] with the owner of the segments.
-- 2. Replace [TABLE_NAME] or [INDEX_NAME] with the segment to be analyzed.
set echo off
set feedback off
set verify off
@davidhooey
davidhooey / oracle_segment_advisor_for_all_segments_in_schema.sql
Created September 24, 2013 20:11
Oracle Segment Advisor for All Segments in Schema
--
-- Segment Advisor for All Segments in Schema
--
-- 1. Grant the ADVISOR and SELECT ANY DICTIONARY roles to the schema owner.
-- 2. Execute the script as the schema owner.
-- 3. Revoke the ADVISOR and SELECT ANY DICTIONARY roles from the schema owner.
set echo off
set feedback off
@davidhooey
davidhooey / oracle_logon_trigger_to_enable_sql_trace.sql
Created September 26, 2013 13:39
Oracle Logon Trigger To Enable SQL Trace
create or replace trigger [SCHEMA_NAME]_startsqltracing after logon on [SCHEMA_NAME].schema
begin
execute immediate 'alter session set timed_statistics=true';
execute immediate 'alter session set max_dump_file_size=unlimited';
execute immediate 'alter session set events ''10046 trace name context forever, level 12''';
end;
/
create or replace trigger [SCHEMA_NAME]_endsqltracing before logoff on [SCHEMA_NAME].schema
@davidhooey
davidhooey / oracle_segment_shrink.sql
Last active December 25, 2015 05:19
Oracle Segment Shrink
-- ROW MOVEMENT is required to move rows.
-- SHRINK SPACE COMPACT moves the rows without resetting the high water mark.
-- SHRINK SPACE moves the rows and resets the high water mark which temporarily locks the table.
-- May need to rebuild the indexes after a shrink.
alter table [tableName] enable row movement;
alter table [tableName] shrink space compact;
alter table [tableName] shrink space;
alter index [indexName] shrink space compact;
@davidhooey
davidhooey / oracle_statistics_generating_and_seleting.sql
Created October 10, 2013 18:48
Oracle Statistics Generating And Deleting
NOTE:
Oracle9i: estimate_percent defaults to NULL which is COMPUTE
Oracle10g: estimate_percent defaults to to_estimate_percent_type (get_param('ESTIMATE_PERCENT'))
-- ********************************
-- * Generating Schema Statistics *
-- ********************************
execute dbms_stats.gather_schema_stats(ownname=>'SCHEMAOWNER',estimate_percent=>NULL,cascade=>TRUE,degree=>dbms_stats.default_degree)
execute dbms_stats.gather_schema_stats(ownname=>'SCHEMAOWNER',estimate_percent=>NULL,cascade=>TRUE,degree=>dbms_stats.default_degree,method_opt=>'FOR ALL INDEXED COLUMNS SIZE AUTO')
execute dbms_stats.gather_schema_stats(ownname=>'SCHEMAOWNER',estimate_percent=>NULL,cascade=>TRUE,degree=>dbms_stats.default_degree,method_opt=>'FOR ALL INDEXED COLUMNS SIZE 1') -- No Histograms
@davidhooey
davidhooey / oracle_oltp_table_compression.sql
Created October 10, 2013 18:55
Oracle OLTP Table Compression
alter table [tableName] compress for oltp;
alter table [tableName] move;
@davidhooey
davidhooey / oracle_byte_to_char_length_semantics.sql
Created October 25, 2013 14:42
Oracle Byte to Char Length Semantics
select
'alter table ' || table_name || ' modify ( ' || column_name || ' varchar(' || char_length || ' char) );'
from
user_tab_columns
where
data_type = 'VARCHAR2'
and
char_used = 'B'
order by
table_name,
@davidhooey
davidhooey / oracle_holding_and_waiting_sessions.sql
Created October 25, 2013 16:36
Oracle Holding And Waiting Session
select
holders.*,
' IS BLOCKING ' is_blocking,
waiters.*
from
(
select
dw.holding_session,
hs.username,
do.object_name,
@davidhooey
davidhooey / Vagrantfile_Rails_Development
Last active November 12, 2020 16:38
Vagrant Rails Development
# -*- mode: ruby -*-
# vi: set ft=ruby :
# -----------------------------------------------------------------------------
# Rails Development Vagrantfile
# -----------------------------------------------------------------------------
#
# Server Info:
#
# Ubuntu 12.04 32-bit
@davidhooey
davidhooey / .tmux.conf
Last active December 2, 2016 19:24
tmux Configuration
set -g prefix C-a
set -sg escape-time 1
set -sg base-index 1
setw -g pane-base-index 1
setw -g mode-keys vi
set -g mouse on
bind r source-file ~/.tmux.conf \; display "Reloaded!"