Skip to content

Instantly share code, notes, and snippets.

@tmuth
tmuth / osw-gather.sh
Created August 5, 2014 13:10
Scripted OSWatcher file collection - iostat, last 7 days
#/bin/bash
file_name=""
if [ $# -gt 0 ]
then
file_name="_$1"
fi
while read line; do
(ssh -n -q root@$line 'find /opt/oracle.oswatcher/osw/archive \
@tmuth
tmuth / split-on-lines.sh
Created June 2, 2014 15:10
Split a text file every n number of lines
#!/bin/bash
# parameter 1: file to split
# parameter 2: number of lines per file
echo "About to split file $1"
echo "every $2 lines"
md5sum $1 > $1.md5
split -l $2 $1 $1.split.
@tmuth
tmuth / impdp.grep.sh
Last active August 29, 2015 14:01
orcl datapump import > grep for object counts
# Use impdp to write DDL of an export out to a file.
# In this case, the source was SQLT > SQL Test Case Builder
impdp system/password@//localhost:1521/noncdb directory=TCB_IMP_DIR dumpfile=sqlt_s83913_tcb_dpexp.dmp TRANSFORM=SEGMENT_ATTRIBUTES:n sqlfile=objects.sql
# Note there are lots of filters you could apply to impdp to target just schemas and/or object types, etc
# Lets get an idea of the schemas referenced in the export:
grep -ioE "\"[[:alnum:]]{1,30}\"\." objects.sql | sort |uniq -c
# Count of objects by schema:
@tmuth
tmuth / top-n-timed-events-by-snapid-awr.sql
Last active August 29, 2015 13:56
Top 5 Timed Events (FG & BG) from AWR Repository by SNAP_ID for a given snapshot range
----------------------------------------------------------------------------------------
--
-- File name: top-n-timed-events-by-snapid-awr.sql
-- Purpose: List the top N events per snapshot from the AWR repository, by snap_id.
-- The data is aggregated for all nodes in a cluster, though it wouldn't
-- be hard to add instance_number as a dimension.
--
-- Author: Tyler D. Muth
--
-- Usage: There are 3 bind variables in this script, all are required:
@tmuth
tmuth / gist:7359033
Created November 7, 2013 18:00
R > data.table() > bin top SQL from AWR repository
# bin SQL by elapsed per exec seconds
brks <- as.vector(c(0.1,0.25,0.5,0.75,1,1.5,5,10,60,600,3600,21600)) #establish bins for SQL
DT_SQL_BY_SNAPID[,bin:=findInterval(ELAP_P_EXEC, brks)] #create a new column with those bin index numbers
DT_SQL_BY_SNAPID[,bin2:=as.character(brks[1+findInterval(ELAP_P_EXEC, brks,all.inside=FALSE)])] #create another new column with the bin values
DT_SQL_BY_SNAPID[is.na(bin2),bin2:=paste0((brks[length(brks)]),"+")] #anything over the top bin will be NA, so change it to "top bin+"
@tmuth
tmuth / plan-capture.sql
Last active December 14, 2015 13:28
Run a .sql script and capture v$mystat, 2 versions of dbms_xplan, and Active SQL Monitor report
----------------------------------------------------------------------------------------
--
-- File name: plan-capture.sql
-- Purpose: Run a .sql script and capture v$mystat, 2 versions of dbms_xplan,
-- and Active SQL Monitor report
-- Author: Tyler Muth - http://tylermuth.wordpress.com
-- Parameters:
-- 1: sql script to run containing the query
-- 2: output file name prefix. This is used for the name of the spool file and sqlmon html files
-- 3: An additional script to run first. I use this for "alter session" parameters. I created