Top For Oracle 143
Top For Oracle 143
Top For Oracle 143
Oratop provides a unix-top like display for oracle. Check out the following screenshot...
If you want to install oratop, there are two parts to it; a stored procedure and a shell script.
First create the stored procedure by running the following code in sqlplus while logged in as sys (just
cut&paste it into sqlplus):
oratop_proc.sql
Next, using your favourite text editor, create a file called oratop. Ideally you should place this file in a
directory on your path such as /home/oracle/bin or /usr/local/bin. Anyway, cut and paste the following
into it:
#!/bin/sh
if [ -n "$ORACLE_SID" ]; then
while [ 1 ]; do
clear
SQL
sleep 5
done
else
fi
Save the file and make it executable with the following command:
aoe
#!/usr/bin/ksh
#
=============================================================================
# File Name: aoe
#
# Function: Configures the oracle environment
#
# Usage: . aoe [SID] [-]
#
# Remarks: aoe is a simple front end to the oracle oraenv utility.
# If a SID is not specified at the command line, a menu will be
# displayed, listing all available entries in the oratab.
# Once a selection has been made oraenv is called and if one exists
# an optional config script will also be executed.
# The optional config script must be located in
# $optional_script_dir and be named as follows: aoe_<SID>
# If - is specified as the last parameter, aoe will
# launch sqlplus "/ as sysdba".
#
# Notes: It is worth adding the following to you .profile (or
.bash_profile):
# alias aoe=". aoe"
# Doing so removes the need to prefix the command with ". "
#
# Change History:
#
# Date Ver Author Change
# ======== ==== ===============
===============================================
# 15/06/06 1.0 Andy Barry Initial version.
# 30/08/06 1.1 Andy Barry Added the option to run sqlplus "/ as sysdba"
# when "-" is specified as the last parameter.
oratab=/etc/oratab
oraenv=/usr/local/bin/oraenv
optional_script_dir=/home/oracle/bin
else
echo "aoe error: Invalid SID or selection"
unset ORACLE_SID
unset ORACLE_HOME
fi
table_conf.sql
-- table_conf.sql
-- Andy Barry
-- 17/06/07
undefine owner
undefine table
prompt
prompt ======= General info ==============================================
select tablespace_name
from dba_tables
where owner = '&&owner'
and table_name = '&&table'
and tablespace_name is not null
/
prompt
prompt ======= Indexes ===================================================
select i.index_name
, nvl(i.tablespace_name, '(partitioned)') tablespace_name
, ceil(s.bytes / 1048576) "Size MB"
from dba_indexes i
, dba_segments s
where i.index_name = s.segment_name
and i.owner = '&owner'
and table_name like '&table'
order by 2, 1
/
select ti.index_name
, pi.partition_name
, pi.tablespace_name
, pi.status
from dba_indexes ti , dba_ind_partitions pi
where ti.partitioned = 'YES'
and ti.table_name = '&&table'
and pi.index_owner = '&&owner'
and pi.index_owner = ti.owner
and pi.index_name = ti.index_name
order by 1, pi.partition_position
/
prompt
prompt ======= Constraints ===============================================
prompt
prompt ======= Triggers ==================================================
undefine owner
undefine table
set verify on feedback on
user_conf.sql
-- user_conf.sql
-- Andy Barry
-- 20/02/06
undefine user
select username
, default_tablespace , temporary_tablespace
from dba_users where username = '&userid'
/
select tablespace_name
, decode(max_bytes, -1, 'unlimited'
, ceil(max_bytes / 1024 / 1024) || 'M' ) "QUOTA"
from dba_ts_quotas where username = upper('&&userid')
/
select privilege || ' ' || decode(admin_option, 'NO', '', 'YES', 'with admin
option') "PRIV"
from dba_sys_privs where grantee = upper('&&userid')
/
undefine user
set verify on
set feedback on
user_clone.sql
-- user_clone.sql
-- Andy Barry
-- 20/02/06
select username
from dba_users
order by username
/
undefine user
select username
, created
from dba_users
where lower(username) = lower('&newuser')
/
spool /tmp/user_clone_tmp.sql
spool off
undefine user
set verify on
set feedback on
set heading on
@/tmp/user_clone_tmp.sql
!rm /tmp/user_clone_tmp.sql
user_drop_objs.sql
-- drop_userobjs.sql
--
-- Andy Barry
-- 26/07/05
--
set trimspool on wrap off
set heading off feedback off
set verify off
set pages 1000 lines 1000
spool /tmp/dropuserobjs_&username..sql
select 'alter table ' || owner || '.' || table_name || ' drop primary key
cascade;'
from dba_constraints where owner = trim(upper('&username'))
and constraint_type = 'P'
/
select 'alter table ' || owner || '.' || table_name || ' drop constraint ' ||
constraint_name || ' cascade;'
from dba_constraints where owner = trim(upper('&username'))
and constraint_type = 'U'
/
select 'drop ' || object_type || ' '|| owner || '.' || object_name || ';'
from dba_objects where owner = trim(upper('&username'))
and object_type not in ('TABLE', 'INDEX', 'DATABASE LINK', 'JAVA CLASS', 'JAVA
RESOURCE')
/
spool off
user_truncate_objs.sql
-- truncate_user.sql
--
-- Andy Barry
-- 26/07/05
--
set trimspool on wrap off
set heading off feedback off
set verify off
set pages 1000 lines 1000
spool /tmp/truncate_&username..sql
select 'alter table ' || owner || '.' || table_name || ' drop primary key
cascade;'
from dba_constraints where owner = trim(upper('&username'))
and constraint_type = 'P'
/
select 'alter table ' || owner || '.' || table_name || ' drop constraint ' ||
constraint_name || ' cascade;'
from dba_constraints where owner = trim(upper('&username'))
and constraint_type = 'U'
/
select 'truncate table ' || owner || '.' || table_name || ' reuse storage;'
from dba_tables where owner = trim(upper('&username'))
/
spool off
login.sql
cr_hot_backup.sql
spool begin_backup.sql
spool end_backup.sql