實戰:oracle建立資料表空間的shell指令碼,oracleshell

來源:互聯網
上載者:User

實戰:oracle建立資料表空間的shell指令碼,oracleshell

#!/bin/bash#ocpyang@126.com#create tablespaceif [ $# -ne 2 ]; then  echo "Usage: $0 TABLESPACE_NAME TABLESPACE_SIZE"  exit 1fi#configure oracle env:about oracle envs, username and passwordORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1ORACLE_SID=orclora_data=/u01/app/oracle/product/11.2.0/db_1/dbs/ora_user="sys"ora_pass="password"tablespace_name=$(echo $1 | tr '[a-z]' '[A-Z]') tablespace_size=$2    outfiletmp01=/tmp/createtpstmp01.txt  #specify the output file location outfiletmp03=/tmp/createtpstmp03.txt  #specify the output file location outfiletmp02=/tmp/createtpstmp02.txt  #specify the output file location #check oracle instance is down or up sqlplus -S "${ora_user}/${ora_pass} as sysdba" <<!01 >/dev/null #禁止sqlplus執行結果回顯set heading off;set feedback off;set termout off;set pagesize 0;set verify off;set echo off;spool ${outfiletmp01}select sysdate from dual; spool offexit;!01ins_jug=`grep -i "ORA-01034:"  ${outfiletmp01} >${outfiletmp02} ` if [ -s ${outfiletmp02} ]; thenecho -e "\e[1;31m  ******************************************************************  \e[0m"echo -e "\e[1;31m  !!!!, oracle IS down!  \e[0m"echo -e "\e[1;31m  ******************************************************************  \e[0m"rm -rf ${outfiletmp01}rm -rf ${outfiletmp02}exit 1fi#  sqlplus -S "${ora_user}/${ora_pass} as sysdba" <<!01 >/dev/null #禁止sqlplus執行結果回顯set heading off;set feedback off;set termout off;set pagesize 0;set verify off;set echo off;spool $outfiletmp03select tablespace_name from dba_tablespaces where tablespace_name='${tablespace_name}'; spool offexit;!01tps_jug=`grep -i ${tablespace_name} ${outfiletmp03} ` if [ "${tps_jug}" = "${tablespace_name}" ]; then        echo -e "\e[1;32m  The tablespace ${tablespace_name} exits! \e[0m"      rm -rf ${outfiletmp03}    exit 1  elsewind_var=$(sqlplus -s "{ora_user}/${ora_pass} as sysdba" <<EOF create tablespace ${tablespace_name}datafile '${ora_data}/${tablespace_name}.dbf'size $tablespace_sizeextent management localuniform size 128ksegment space management auto;EXIT ;EOF) echo -e "\e[1;32m  ${wind_var} \e[0m"   #Direct display returns resultsrm -rf ${outfiletmp03}exit 1fi



oracle怎建立資料表空間

建立一個Command Window 在提示符下輸入一下命令,斷行符號執行就可以了
create tablespace dbspace datafile 'D:\oracle\product\10.2.0\oradata\orcl\dbspace.dbf' size 400M autoextend on next 10m maxsize unlimited;--建立資料表空間
DROP TABLESPACE dbspace INCLUDING CONTENTS AND DATAFILES;--刪除資料表空間

其中
1) DATAFILE: 資料表空間資料檔案存放路徑
2) SIZE: 起初設定為200M
3) UNIFORM: 指定區尺寸為128k,如不指定,區尺寸預設為64k
4) 空間名稱histdb 與 資料檔案名稱 histdb.dbf 不要求相同,可隨意命名.
5) AUTOEXTEND ON/OFF 表示啟動/停止自動擴充資料表空間
6) alter database datafile ' D:\oracle\product\10.2.0\oradata\orcl\histdb.dbf ' resize 500m; //手動修改資料檔案大小為

下列命令用於為資料表空間建立使用者,將使用者的預設資料表空間設定為剛建立的資料表空間
create user test1 identified by test1 default tablespace dbspace;
alter database default tablespace dbspace;
create user test identified by test;
select username, default_tablespace defspace from dba_users where username='TEST';
 
linux系統+oracle資料庫+shell指令碼都學會了,以後發展會怎?

如果只是學會,我相信沒什麼好炫耀的,因為linux+oracle+shell,基本的我都會。建議你精通一到兩個就可以了。其他略懂略懂,相信這樣的話,你就可以再未來的企業裡很好滴發展了。

linux+oralce是很多大型企業用的很多的作業系統和資料庫,精通了這兩門,你過萬月薪根本沒問題。加油吧GG或MM
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.