Skip to content

Instantly share code, notes, and snippets.

-- REPLACE <<sql id>> with actual sql id
select plan_table_output from table(dbms_xplan.display_cursor('<<sql id>>', null, 'typical'));
-- if an index isn't being used or is lightly used, can it be dropped to free up resources?
-- only reflective of statements in shared SQL area, to get a more accurate reflection on
-- indexes used in the DB, run this query several times a day and dump all the output into
-- a spreadhseet or something.
with index_usage as
(
select pl.sql_id, pl.object_owner, pl.object_name, pl.operation,
pl.options, count(1) as use_count
from v$sql_plan pl
-- Value is in microseconds
-- Run this query at a couple regular intervals and take the delta to get
-- an idea of how much hard parsing is going on
select sn.statistic#, sn.name, s.value
from v$sysstat s, v$statname sn
where s.statistic# = sn.statistic#(+)
and sn.name in ('parse time cpu', 'parse count (hard)');
with statements as
(
select force_matching_signature,
count(1) over (partition by force_matching_signature) as statement_count,
row_number() over (partition by force_matching_signature order by last_load_time desc) as row_index,
parsing_schema_name,
sql_text
from v$sql
where force_matching_signature > 0
and force_matching_signature <> exact_matching_signature
-- table info is only as up to date as last time stats were gathered (last_analyzed)
select t.owner, t.table_name, t.num_rows, t.avg_row_len,
t.blocks as blocks_below_hwm, t.empty_blocks,
s.blocks as segment_blocks,
s.bytes / 1048576 as size_in_mb,
to_char(t.last_analyzed, 'YYYY-MM-DD HH24:MI') as last_analyzed
from all_tables t, dba_segments s
where t.owner = s.owner and t.table_name = s.segment_name
and t.owner = 'SCHEMA_NAME';
select column_name, avg_col_len, num_distinct, num_nulls
from all_tab_columns
where table_name = '<<table name>>'
order by column_id desc;
select ix.owner, ix.index_name, ix.table_name,
ix.distinct_keys, ix.leaf_blocks,
s.blocks as segment_blocks,
s.bytes / 1048576 as size_in_mb,
to_char(ix.last_analyzed, 'YYYY-MM-DD HH24:MI') as last_analyzed
from all_indexes ix, dba_segments s
where ix.owner = s.owner and ix.index_name = s.segment_name
order by ix.table_name, ix.index_name;
@RichVRed
RichVRed / MariaDBInstall.sh
Created April 27, 2017 21:09 — forked from mamemomonga/MariaDBInstall.sh
Install MariaDB Client 10.1 for Debian8, Ubuntu 16.04
#!/bin/bash
# ----------
# Install MariaDB Client 10.1 for Debian8, Ubuntu 16.04
# curl -L https://gist.githubusercontent.com/mamemomonga/2823ecc2b20b886e90d1b8d523515724/raw/MariaDBInstall.sh | sudo bash -eux
# ----------
set -eux
if [ `id --user` -ne 0 ]; then
echo "rootでの実行が必要"
exit 255
@RichVRed
RichVRed / gist:fe4e2e718256a431cbdd531a66fe676d
Created April 25, 2017 22:10 — forked from songlipeng2003/gist:3366275
reset mysql root password without no password in ubuntu
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi
@RichVRed
RichVRed / gitlab-version-chech.sh
Created March 31, 2017 15:45 — forked from samrocketman/gitlab-version-chech.sh
A simple bash script for checking the latest stable version of GitLab
#!/bin/bash
#Sam Gleske
#Mon Apr 28 11:11:10 EDT 2014
#Red Hat Enterprise Linux Server release 6.5 (Santiago)
#Linux 2.6.32-431.el6.x86_64 x86_64
#GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
#DESCRIPTION
# Check the latest stable version and compare with the version of gitlab installed.
# Run daily via cron.