(一)在Unix下Oracle 11g 建庫指令碼 bsb_oracle_create_db.sh

fjzcau發表於2015-02-07
使用該建庫指令碼前,請理解指令碼內容.

  1. echo "#==========================Create DB===============================#"
  2. date
  3. echo "#==========================Create DB===============================#"
  4.  
  5. #------------------------------------------------------#
  6. # 手工建庫
  7. # 以oracle使用者執行該指令碼
  8. #------------------------------------------------------#
  9. ORACLE_SID=bjtc
  10. export ORACLE_UNQNAME=bjtc
  11. export ORACLE_HOSTNAME=BJTC
  12. ORACLE_BASE=/oracle/product
  13. ORACLE_HOME=$ORACLE_BASE/11.2.3

  14. #--修改.profile
  15. cd ~
  16. cat >> ~/.profile <<EOF
  17. #-----------------------------------------#
  18. # add for oracle
  19. export ORACLE_SID=bjtc
  20. export ORACLE_UNQNAME=bjtc
  21. export ORACLE_HOSTNAME=BJTC
  22. export ORACLE_BASE=/oracle/product
  23. export ORACLE_HOME=$ORACLE_BASE/11.2.3
  24. export PATH=$ORACLE_HOME/bin:$PATH
  25. export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
  26. export NLS_DATE_FORMAT="yy-mm-dd HH24:MI:SS"
  27. export NLS_LANG=American_America.ZHS16GBK
  28. #-----------------------------------------#
  29. set -o vi
  30. alias ll='ls -l'
  31. EOF

  32. . .profile

  33. #------------------------------------------------------#
  34. #--生成建庫配置檔案 dbca.rsp
  35. #------------------------------------------------------#
  36. cat > /oracle/dbca.rsp <<EOF
  37. [GENERAL]
  38. RESPONSEFILE_VERSION = "11.2.0"
  39. OPERATION_TYPE = "createDatabase"

  40. [CREATEDATABASE]
  41. GDBNAME = "$ORACLE_SID"
  42. SID = "$ORACLE_SID"
  43. TEMPLATENAME = "General_Purpose.dbc"
  44. SYSPASSWORD = "Bsbora12#"
  45. SYSTEMPASSWORD = "Bsbora12#"
  46. EMCONFIGURATION = "NONE"
  47. SYSMANPASSWORD = "Bsbora12#"
  48. DBSNMPPASSWORD = "Bsbora12#"
  49. DATAFILEDESTINATION = /oradata
  50. #STORAGETYPE=FS
  51. CHARACTERSET = "ZHS16GBK"
  52. NATIONALCHARACTERSET= "AL16UTF16"
  53. LISTENERS = "listener"
  54. MEMORYPERCENTAGE = "40"
  55. DATABASETYPE = "MULTIPURPOSE"
  56. AUTOMATICMEMORYMANAGEMENT = "TRUE"
  57. #TOTALMEMORY = "800"
  58. EOF

  59. cd $ORACLE_HOME/bin
  60. ./dbca -silent -createdatabase -responseFile /oracle/dbca.rsp
  61. sleep 5

  62. #------------------------------------------------------#
  63. # 手工建庫後需要執行的語句
  64. #------------------------------------------------------#
  65. echo "col file_name for a50" >> $ORACLE_HOME/sqlplus/admin/glogin.sql
  66. echo "col member for a50" >> $ORACLE_HOME/sqlplus/admin/glogin.sql
  67. echo "set lines 200" >> $ORACLE_HOME/sqlplus/admin/glogin.sql
  68. echo "set pages 100" >> $ORACLE_HOME/sqlplus/admin/glogin.sql

  69. mkdir /oraredo1/$ORACLE_SID
  70. mkdir /oraredo2/$ORACLE_SID

  71. sqlplus / as sysdba << EOF
  72. shutdown immediate;
  73. EOF

  74. #--spfile放在儲存
  75. echo "spfile=/oradata/$ORACLE_SID/spfile$ORACLE_SID.ora" > $ORACLE_HOME/dbs/init$ORACLE_SID.ora
  76. mv $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora /oradata/$ORACLE_SID

  77. sqlplus / as sysdba << EOF
  78. startup mount;
  79. alter database archivelog;
  80. alter system set log_archive_dest_1='location=/archivelog';
  81. alter database open;

  82. alter profile default limit password_life_time unlimited;
  83. alter system set processes=1500 scope=spfile;
  84. alter system set open_cursors=1000 scope=spfile;

  85. alter system set db_recovery_file_dest='';
  86. alter database datafile 1 resize 4096m;
  87. alter database datafile 2 resize 4096m;
  88. alter database datafile 3 resize 20480m;
  89. alter database datafile 4 resize 1024m;
  90. alter database tempfile 1 resize 20480m;

  91. alter database add logfile group 4 ( '/oraredo1/$ORACLE_SID/redo041.log','/oraredo2/$ORACLE_SID/redo042.log') size 256M;
  92. alter database add logfile group 5 ( '/oraredo1/$ORACLE_SID/redo051.log','/oraredo2/$ORACLE_SID/redo052.log') size 256M;
  93. alter database add logfile group 6 ( '/oraredo1/$ORACLE_SID/redo061.log','/oraredo2/$ORACLE_SID/redo062.log') size 256M;
  94. alter database add logfile group 7 ( '/oraredo1/$ORACLE_SID/redo071.log','/oraredo2/$ORACLE_SID/redo072.log') size 256M;
  95. alter database add logfile group 8 ( '/oraredo1/$ORACLE_SID/redo081.log','/oraredo2/$ORACLE_SID/redo082.log') size 256M;
  96. alter database add logfile group 9 ( '/oraredo1/$ORACLE_SID/redo091.log','/oraredo2/$ORACLE_SID/redo092.log') size 256M;
  97. alter database add logfile group 10 ( '/oraredo1/$ORACLE_SID/redo1001.log','/oraredo2/$ORACLE_SID/redo1002.log') size 256M;

  98. alter system switch logfile;
  99. !sleep 3
  100. alter system switch logfile;
  101. !sleep 3
  102. alter system switch logfile;
  103. !sleep 3
  104. alter system switch logfile;
  105. !sleep 3
  106. alter system switch logfile;
  107. !sleep 3
  108. alter system switch logfile;
  109. !sleep 3
  110. alter system switch logfile;

  111. select group#,status,BYTES from v\$log;
  112. select group#,status,member from v\$logfile;

  113. alter database drop logfile group 1;
  114. alter database drop logfile group 2;
  115. alter database drop logfile group 3;
  116. alter database add logfile group 1 ( '/oraredo1/$ORACLE_SID/redo011.log','/oraredo2/$ORACLE_SID/redo012.log') size 256M;
  117. alter database add logfile group 2 ( '/oraredo1/$ORACLE_SID/redo021.log','/oraredo2/$ORACLE_SID/redo022.log') size 256M;
  118. alter database add logfile group 3 ( '/oraredo1/$ORACLE_SID/redo031.log','/oraredo2/$ORACLE_SID/redo032.log') size 256M;

  119. alter system set control_files='/oradata/$ORACLE_SID/control01.ctl','/oradata/$ORACLE_SID/control02.ctl' scope=spfile;
  120. shutdown immediate;
  121. ! cp /oradata/$ORACLE_SID/control01.ctl /oradata/$ORACLE_SID/control02.ctl
  122. startup;
  123. alter user sysman account unlock;
  124. EOF

  125. echo "#==========================End Create DB===============================#"
  126. date
  127. echo "#==========================End Create DB===============================#"

  128. cat > $ORACLE_HOME/network/admin/listener.ora << EOF
  129. SID_LIST_LISTENER =
  130.   (SID_LIST =
  131.     (SID_DESC =
  132.       (SID_NAME = PLSExtProc)
  133.       (ORACLE_HOME = /oracle/product/11.2.3)
  134.       (PROGRAM = extproc)
  135.     )
  136.     (SID_DESC =
  137.       (SID_NAME = $ORACLE_SID )
  138.       (ORACLE_HOME = /oracle/product/11.2.3)
  139.       (GLOBAL_DBNAME = $ORACLE_UNQNAME )
  140.     )
  141.   )

  142. LISTENER =
  143.   (DESCRIPTION_LIST =
  144.     (DESCRIPTION =
  145.       (ADDRESS = (PROTOCOL = TCP)(HOST = $ORACLE_HOSTNAME )(PORT = 1521))
  146.       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
  147.     )
  148.   )
  149. EOF


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1429920/,如需轉載,請註明出處,否則將追究法律責任。

相關文章