Skip to content

Instantly share code, notes, and snippets.

@dotmaik1
dotmaik1 / tablespaces: tablespaces query instant DBA.sql
Last active October 6, 2016 16:17
Tablespaces query for instant DBA
SELECT /* + RULE */ df.tablespace_name "Tablespace", df.bytes / (1024 * 1024) "Size (MB)", SUM(fs.bytes) / (1024 * 1024) "Free (MB)", Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free", Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used" FROM dba_free_space fs, (SELECT tablespace_name,SUM(bytes) bytes FROM dba_data_files GROUP BY tablespace_name) df WHERE fs.tablespace_name (+) = df.tablespace_name GROUP BY df.tablespace_name,df.bytes Order by 4;
@dotmaik1
dotmaik1 / tunning: SQL tunning.sql
Created October 6, 2016 16:18
Query Tunning Advisor
SQL statement with SQL_ID 113ffqdfha2gs
declare
stmt_task VARCHAR2(64);
BEGIN
STMT_TASK:=DBMS_SQLTUNE.CREATE_TUNING_TASK(SQL_ID => '7asshajftkyzw', TIME_LIMIT => 300, TASK_NAME => 'Tune_7asshajftkyzw', description => 'Tune task for 7asshajftkyzw');
END;
/
PL/SQL procedure successfully completed.
--Note: 135294.1
select to_char(creation_time, 'RRRR Month') "Month",
sum(bytes)/1024/1024 "Growth in Meg"
from sys.v_$datafile
where creation_time > SYSDATE-365
group by to_char(creation_time, 'RRRR Month')
order by "Month" desc;
select to_char(CREATION_TIME,'RRRR') year, to_char(CREATION_TIME,'MM') month, round(sum(bytes)/1024/1024/1024) "Growth in GB"
@dotmaik1
dotmaik1 / sizing: scitpts: Historical database growth.sql
Created October 6, 2016 16:23
Historical database growth script
#!/usr/bin/ksh
export ORACLE_SID=mxapps1
export ORACLE_HOME=/u001/MXDB/oracle/product/11.2.0/db
export PATH=$ORACLE_HOME/bin:$PATH
$ORACLE_HOME/bin/sqlplus -s "/as sysdba" <<EOF
SET PAGES 2000 LINES 200
SET HEAD OFF HEADING OFF FEEDBACK OFF
SET SERVEROUTPUT ON
spool /home/oracle/dbascripts/sizing/historical_db_growth.log append;
dba_users; antes en 10g se podian ver los passwords en esa vista.
SQL> select name, password from sys.user$ where name like 'LWTSADM1';
lwtsadm1
NAME PASSWORD
------------------------------ ------------------------------
SYS 8A8F025737A9097A
@dotmaik1
dotmaik1 / shrink: Segment advisor per schema.sql
Created October 6, 2016 16:26
Segment advisor per schema
DECLARE
l_object_id NUMBER;
BEGIN
-- Create a segment advisor task for the PAPERLESS tablespace.
DBMS_ADVISOR.create_task (
advisor_name => 'Segment Advisor',
task_name => 'PAPERLESS_SEGMENT_ADVISOR',
task_desc => 'Segment Advisor For PAPERLESS');
DBMS_ADVISOR.create_object (
@dotmaik1
dotmaik1 / admin: ckpid.sql
Created October 6, 2016 16:27
Get what user is doing by process ID
set verify off
col username format a8 heading 'DB User'
col terminal format a8 trunc
col osuser format a10 heading 'OS User' trunc
col sid format 9999 heading SID
col serial# format 99999 heading SRL#
col spid format a6 heading DBPROC
col process format a8 heading APPPROC
col mins format 9990.9 heading 'Status|mins'
col program format a30 trunc
@dotmaik1
dotmaik1 / admin: cksid.sql
Created October 6, 2016 16:27
Get what user is doing by SID
set verify off
col username format a13 heading 'DB User' trunc
col terminal for a10
col osuser format a12 heading 'OS User' trunc
col sid format 9999 heading SID
col serial# format 99999 heading SRL#
col spid format a6 heading DBPROC
col process format a8 heading APPPROC
col mins format 9990.9 heading 'Status|mins'
col program format a30 trunc
@dotmaik1
dotmaik1 / admin: ckusess.sql
Created October 6, 2016 16:28
Get sessions status and what their are doing
-- Script para monitoreo de procesos de usuario
set verify off
col status format a8
col username format a13 heading 'DB User' trunc
col osuser format a12 heading 'OS User' trunc
col sid format 9999 heading SID
col serial# format 99999 heading SRL#
col spid format a6 heading DBPROC
col process format a10 heading APPPROC
@dotmaik1
dotmaik1 / scripts: DB_and_listener_check.sh
Created October 6, 2016 16:29
Automatic script that checks if the database is open an accesible
#!/bin/bash
ORACLE_SID=MXBRIDGE
export ORACLE_SID
ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/MXBRIDGE
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH
mailto="[email protected]"
TIMING=`date +"%d-%b-%Y %H:%M"`
$ORACLE_HOME/bin/sqlplus scott/tiger@'(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = lfoitmatdb01.foit-foxconn.net)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = MXBRIDGE) (FAILOVER_MODE = (TYPE = select) (METHOD = basic))))' <<END