您的位置:首页 > 运维架构 > Shell

学习的点点滴滴shell+sql

2015-10-17 09:42 531 查看
无意义的脚本,大神勿喷/
[root@test Desktop]# vim oraclesh.sh
#!/bin/bash
clear
#函数
test_parameter1()
{
`echo `su - oracle -c 'sqlplus /nolog'<<end
conn sys/sys as sysdba
select '-------show parameter --*******查看系统所有初始化参数******' sga from dual;
show parameter;
exit
end
``;
echo ;
echo -e "\t show parameter  --*******查看系统所有初始化参数******";
}
test_sga2()
{
#1.用户SGA信息
#`echo `su - oracle -c 'sqlplus / as sysdba'<<exit
`echo `su - oracle -c 'sqlplus /nolog'<<end
conn sys/sys as sysdba
clear screen;
select '-------show parameter sga--查看SGA参数' sga from dual;
show parameter sga;
select '-------show parameter sga_max_size--查看系统SGA当前最大上限' sga from dual;
show parameter sga_max_size;
select '-------show sga--查看用户SGA信息' sga from dual;
show sga;
select '-------select sum(current_size) from v\$sga_dynamic_components--查看当前共享内存SGA总大小' sga from dual;
select sum(current_size) from v\$sga_dynamic_components;
exit
end
``;
echo " ";
echo -e "\t show parameter sga  --查看SGA参数 ";
echo -e "\t show parameter sga_max_size  --查看系统SGA当前最大上限";
echo -e "\t show sga  --查看用户SGA信息";
echo -e "\t select sum(current_size) from v\$sga_dynamic_components--查看当前共享内存SGA总大小";
echo " ";
}
test_shared3()
{
`echo `su - oracle -c 'sqlplus /nolog'<<end
conn sys/sys as sysdba
clear screen;
show parameter shared_pool_size;
select component,current_size from v\$sga_dynamic_components
where component='shared pool';
exit
end
``;
echo ;
echo -e "\t 查看共享池大小 \n \t show parameter shared_pool_size  \n";
echo -e "\t select component,current_size from v\$sga_dynamic_components \n \t where component='shared pool'";
}
test_data4()
{
`echo           `su - oracle -c 'sqlplus / as sysdba'<<end
select '-------select name from v\$datafile--查看数据文件' sga from dual;
select name from v\$datafile;
select '-------select name from v\$tempfile' sga from dual;
select name from v\$tempfile;
exit
end
``;
echo            -e "\n\t 查看数据文件:\n \t select name from v\$datafile; \n \t select name v\$tempfile;\n";
}

#数组
ora=(test_parameter1 test_sga2 test_shared3 test_data4)
#查询
PS3="查询信息:"
name=(
"用户parameter初始化信息查询!                                                      "
"用户SGA信息查询!                                                                  "
"用户分享池大小!                                                                   "
"查看数据文件磁盘所在位置!                                                         "
)
select i in "${name[@]}"
do
case $REPLY in
1|2|3|4)
clear
${ora[$[$REPLY - 1]]}
echo
;;
*)
echo
echo "选择错误,退出!"
exit 1;;
esac
done

[root@test Desktop]# sh oraclesh.sh
1) 用户parameter初始化信息查询!
2) 用户SGA信息查询!
3) 用户分享池大小!
4) 查看数据文件磁盘所在位置!
查询信息:3
SQL>
NAME         TYPE  VALUE
------------------------------------ ----------- ------------------------------
shared_pool_size       big integer 0
SQL>   2
COMPONENT        CURRENT_SIZE
---------------------------------------------------------------- ------------
shared pool           369098752
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
查看共享池大小
show parameter shared_pool_size
select component,current_size from v$sga_dynamic_components
where component='shared pool'
查询信息:
1) 用户parameter初始化信息查询!
2) 用户SGA信息查询!
3) 用户分享池大小!
4) 查看数据文件磁盘所在位置!
查询信息:4
SQL>
SGA
------------------------------------------------------
-------select name from v$datafile--查看数据文件
SQL>
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
SQL>
SGA
----------------------------------
-------select name from v$tempfile
SQL>
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/temp01.dbf
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
查看数据文件:
select name from v$datafile;
select name v$tempfile;

查询信息:e
选择错误,退出!
[root@test Desktop]#


本文出自 “一米阳光” 博客,请务必保留此出处http://sunshine3.blog.51cto.com/3988340/1703720
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: