Skip to content

Instantly share code, notes, and snippets.

@davidhooey
davidhooey / oracle_stmt_utils.rb
Created March 26, 2014 13:56
Oracle utilities for stmt_to_sqlid, stmt_to_hash and sqlid_to_hash.
require 'digest'
module OracleStmtUtils
def stmt_to_sqlid(stmt)
d1, d2, msb, lsb = Digest::MD5.digest(stmt + "\x00").unpack('IIII')
sqln = msb * (2 ** 32) + lsb
stop = Math.log(sqln, Math::E) / Math.log(32, Math::E) + 1
sqlid = String.new
alphabet = '0123456789abcdfghjkmnpqrstuvwxyz'
# Mac OS X Lion introduced a new, iOS-like context menu when you press and hold a key
# that enables you to choose a character from a menu of options. If you are on Lion
# try it by pressing and holding down 'e' in any app that uses the default NSTextField
# for input.
#
# It's a nice feature and continues the blending of Mac OS X and iOS features. However,
# it's a nightmare to deal with in Sublime Text if you're running Vintage (Vim) mode,
# as it means you cannot press and hold h/j/k/l to move through your file. You have
# to repeatedly press the keys to navigate.
@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!"
@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 / 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 / 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_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_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_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_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