靜默建立oracle資料庫及克隆資料庫

邱東陽發表於2014-03-20


在沒有圖形介面的情況下,可以使用dbca命令進行靜默安裝資料庫。

靜默安裝的的速度是比圖形介面安裝的速度快的。

使用oracle軟體自帶的響應檔案建庫

需要響應的檔案

 

可以使用oracle磁碟響應資料夾中的dbca.rsp

[oracle@dongyang database]$ ls

doc  install  response  runInstaller  stage  welcome.html

[oracle@dongyang database]$ cd response/

[oracle@dongyang response]$ ls

custom.rsp  dbca.rsp  emca.rsp  enterprise.rsp  netca.rsp  standard.rsp

[oracle@dongyang response]$

 

檢視dbca命令如何使用

 

[oracle@dongyang ~]$ dbca -help |more

dbca  [-silent | -progressOnly | -customCreate] { }  | { [

nd> [options] ] -responseFile  } [-continueOnNonFatalErrors

| false>]

Please refer to the manual for details.

You can enter one of the following command:

 

Create a database by specifying the following parameters:

        -createDatabase  建立資料庫(步驟寫的很清楚,根據提示寫命令)

                           配置主要的幾個引數,其餘的可以在建完之後修改

                -templateName

                [-cloneTemplate]  --選擇模板 (預設為通用模板)

                -gdbName --資料庫的名字

                [-sid ]   --例項名

                [-sysPassword --建立SYS使用者密碼(使用響應檔案安裝資料庫 必須指定密碼)

                [-systemPassword ] 建立SYSTEM使用者密碼

                [-emConfiguration <CENTRAL|LOCAL|ALL|NOBACKUP|NOEMAIL|NONE>

                  --配置EM         --引數選擇配置的方式

                        -dbsnmpPassword --建立dbsnmp密碼

                        -sysmanPassword --建立sysman密碼

                    以上引數基本可以建庫了,在加上響應檔案就可以了。

 

                        [-hostUserName                          -hostUserPassword

                         -backupSchedule

m>]

                        [-smtpServer

 

ations>

                         -emailAddress ]

                        [-centralAgent ]]

                [-datafileDestination <destination directory for all database files

> |  -datafileNames

tablespaces, redo log files and spfile to their corresponding raw device file names

 mappings in name=value format.>]

這個引數指定資料檔案、日誌檔案、控制檔案存放路徑,預設為$ORACLE_BASE/oradata

設定了變數就不需要寫

                [-recoveryAreaDestination

iles>]

                [-datafileJarLocation 

r clone database creation>]

                [-storageType < FS | ASM | RAW>

                        [-asmSysPassword     ]

                        [-diskString      ]

                        [-diskList       

tabase area disk group>

                         -diskGroupName  

                         -redundancy      ]

                        [-recoveryDiskList       

r the recovery area disk group>

                         -recoveryGroupName      

                         -recoveryGroupRedundancy ]]

                [-characterSet ]

                  -指定字符集

                [-nationalCharacterSet  ]

                   --指定國家字符集

                [-registerWithDirService

                        -dirServiceUserName   

                        -dirServicePassword   

                        -walletPassword    ]

                [-listeners  ]

                [-variablesFile  

les in the template>]]

                [-variables  ]

                [-initParams ]

                [-memoryPercentage ]

                        [-databaseType ]]

 

Configure a database by specifying the following parameters:

        -configureDatabase

                -sourceDB    <source>

                [-sysDBAUserName    

                 -sysDBAPassword     ]

                [-registerWithDirService|-unregisterWithDirService|-regenerateDBPas

sword

                        -dirServiceUserName   

                        -dirServicePassword   

                        -walletPassword    ]

                [-emConfiguration

                        -dbsnmpPassword

                        -symanPassword

                        [-hostUserName

                         -hostUserPassword

                         -backupSchedule

m>]

                        [-smtpServer

ations>

                         -emailAddress ]

                        [-centralAgent ]]

 

 

Create a template from an existing database by specifying the following parameters:

        -createTemplateFromDB

                -sourceDB    ::>

                -templateName     

                -sysDBAUserName    

                -sysDBAPassword    

                [-maintainFileLocations ]

 

 

Create a clone template from an existing database by specifying the following param

eters:

        -createCloneTemplate

                -sourceSID    <source>

                -templateName     

                [-sysDBAUserName    

                 -sysDBAPassword     ]

                [-maintainFileLocations ]

                [-datafileJarLocation      

compressed format>]

 

Generate scripts to create database by specifying the following parameters:

        -generateScripts

                -templateName

                -gdbName

                [-scriptDest       ]

 

Delete a database by specifying the following parameters:

        -deleteDatabase

                -sourceDB    <source>

                [-sysDBAUserName    

                 -sysDBAPassword     ]

 

Configure ASM DiskGroups by specifying the following parameters:

        -configureASM

                [-asmSysPassword   ]

                [-diskString    ]

                [-diskList     

a disk group>

                 -diskGroupName

                 -redundancy    ]]

                [-recoveryDiskList       

tabase area disk group>

                 -recoveryGroupName      

--More--

 

根據幫助寫出建庫命令

 

[oracle@dongyang response]$ dbca -silent -cloneTemplate -gdbName orcl -sid orcl -sysPassword oracle -systemPassword oracle -emConfiguration LOCAL -dbsnmpPassword oracle -sysmanPassword oracle  characterSet AL32UTF8 -nationaICharaterSet AL16UTF16 -responseFile /home/oracle/database/response/dbca.rsp

 

 

等待完成。

登入到資料庫進行相關設定

 

[oracle@dongyang ~]$ export ORACLE_SID=orcl

[oracle@dongyang ~]$ sqlplus "/ as sysdba"

查詢資料庫當前可以的登入的賬號

SQL> select username,account_status from dba_users where account_status='OPEN';

 

USERNAME                       ACCOUNT_STATUS

------------------------------ --------------------------------

SYSTEM                         OPEN

SYS                            OPEN

MGMT_VIEW                      OPEN

SYSMAN                         OPEN

DBSNMP                         OPEN

 

SQL>

修改可以登入的賬號密碼

使用SQL生成一個修改使用者密碼的指令碼

SQL> select 'alter user '||username||' identified by oracle111;' from dba_users

  2  where  account_status='OPEN';

 

'ALTERUSER'||USERNAME||'IDENTIFIEDBYORACLE111;'

------------------------------------------------------------------

alter user SYSTEM identified by oracle111;

alter user SYS identified by oracle111;

alter user MGMT_VIEW identified by oracle111;

alter user SYSMAN identified by oracle111;

alter user DBSNMP identified by oracle111;

 

將結果儲存到/u01/app/oracle/pass.sql

開啟spool建立一個檔案

SQL> spool /u01/app/oracle/pass.sql

執行的結果都會保留在檔案中

SQL> /

 

'ALTERUSER'||USERNAME||'IDENTIFIEDBYORACLE111;'

------------------------------------------------------------------

alter user SYSTEM identified by oracle111;

alter user SYS identified by oracle111;

alter user MGMT_VIEW identified by oracle111;

alter user SYSMAN identified by oracle111;

alter user DBSNMP identified by oracle111;

關閉spool

SQL> spool off

使用OS命令 只保留/u01/app/oracle/pass.sql檔案中以alter開頭的所有行、

 

SQL> ho sed -n '/^alter/p' /u01/app/oracle/pass.sql  -i

檢視/u01/app/oracle/pass.sql檔案內容

SQL> ho cat /u01/app/oracle/pass.sql

alter user SYSTEM identified by oracle111;                                     

alter user SYS identified by oracle111;                                        

alter user MGMT_VIEW identified by oracle111;                                  

alter user SYSMAN identified by oracle111;                                     

alter user DBSNMP identified by oracle111;                                      

執行指令碼修改密碼

SQL> @/u01/app/oracle/pass.sql

 

User altered.

 

 

User altered.

 

 

User altered.

 

 

User altered.

 

 

User altered.

 

SQL>

 

使用OS的模板建庫

檢視OS自帶模板

 

[oracle@dongyang templates]$ pwd

/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates

[oracle@dongyang templates]$ ls

Data_Warehouse.dbc   New_Database.dbt   Seed_Database.dfb           example.dmp

General_Purpose.dbc  Seed_Database.ctl  Transaction_Processing.dbc  example01.dfb

[oracle@dongyang templates]$

 

使用通用模板靜默建庫

 

[oracle@dongyang ~]$ dbca -silent -createDatabase -templateName $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc  -gdbName orcl1 sid orcl1 -sysPassword oracle -systemPassword oracle -responseFile NO_VALUE characterSet AL32UTF8 -nationaICharaterSet AL16UTF16 –emConfiguration LOCAL -dbsnmpPassword oracle -sysmanPassword oracle

 

-responseFile NO_VALUE  --不使用響應檔案

 

 

也可以自己手工定義一個模板來建庫

確認要克隆的庫

 

[oracle@dongyang ~]$ ps -ef |grep ora_

oracle    4063     1  0 09:04 ?        00:00:12 ora_pmon_fengzi

oracle    4065     1  0 09:04 ?        00:00:06 ora_psp0_fengzi

oracle    4067     1  0 09:04 ?        00:00:06 ora_mman_fengzi

oracle    4069     1  0 09:04 ?        00:00:10 ora_dbw0_fengzi

oracle    4071     1  0 09:04 ?        00:00:09 ora_lgwr_fengzi

oracle    4073     1  0 09:04 ?        00:00:20 ora_ckpt_fengzi

oracle    4075     1  0 09:04 ?        00:00:02 ora_smon_fengzi

oracle    4077     1  0 09:04 ?        00:00:00 ora_reco_fengzi

oracle    4079     1  0 09:04 ?        00:00:15 ora_cjq0_fengzi

oracle    4081     1  0 09:04 ?        00:00:11 ora_mmon_fengzi

oracle    4083     1  0 09:04 ?        00:00:12 ora_mmnl_fengzi

oracle    4085     1  0 09:04 ?        00:00:00 ora_d000_fengzi

oracle    4087     1  0 09:04 ?        00:00:00 ora_s000_fengzi

oracle    4090     1  0 09:04 ?        00:00:05 ora_asmb_fengzi

oracle    4094     1  0 09:04 ?        00:00:06 ora_rbal_fengzi

oracle    4097     1  0 09:04 ?        00:00:00 ora_o000_fengzi

oracle    4101     1  0 09:04 ?        00:00:06 ora_rvwr_fengzi

oracle    4107     1  0 09:04 ?        00:00:00 ora_arc0_fengzi

oracle    4111     1  0 09:04 ?        00:00:01 ora_arc1_fengzi

oracle    4115     1  0 09:04 ?        00:00:01 ora_qmnc_fengzi

oracle    4127     1  0 09:05 ?        00:00:00 ora_q000_fengzi

oracle    4129     1  0 09:05 ?        00:00:01 ora_q001_fengzi

oracle    5468  4016  0 11:44 pts/2    00:00:00 grep ora_

[oracle@dongyang ~]$

 

 

克隆SIDfengzi的資料庫

注意:

要克隆的資料庫必須可以正常的開啟與關閉。否則克隆模板不能正常使用。

 

[oracle@dongyang ~]$ dbca -help

Create a clone template from an existing database by specifying the following parameters:

        -createCloneTemplate   --建立克隆模板

                -sourceSID      <source>--指定SID

                -templateName        --新的模板名字

                [-sysDBAUserName    

                 -sysDBAPassword     ]

                [-maintainFileLocations ]

                [-datafileJarLocation       ]

 

[oracle@dongyang ~]$ dbca -silent -createCloneTemplate -sourceSID fengzi -templateName clonefengzi

模板預設地址

 

[oracle@dongyang ~]$ ls $ORACLE_HOME/assistants/dbca/templates

Data_Warehouse.dbc   New_Database.dbt   Seed_Database.dfb           example.dmp

General_Purpose.dbc  Seed_Database.ctl  Transaction_Processing.dbc  example01.dfb

Clonefengzi.dbc       Clonefengzi.dfb       Clonefengzi.ctl

[oracle@dongyang ~]$

 

.ctl字尾檔案   --是控制檔案的備份

.dbc字尾檔案  -- 這個就是克隆的模板

.dfb字尾檔案   --RMAN進行的備份集,其中包括庫中所有資料檔案

使用自定義模板方式建庫

使用這個模板,資料庫其中的內容跟SID為fengzi的資料庫中的內容是一樣的。(也就是克隆技術)

 

[oracle@dongyang ~]$dbca -silent -createDatabase -templateName $ORACLE_HOME/assistants/dbca/templates/clonefengzi.dbc  -gdbName orcl2 -sid orcl2 -datafileDestination $ORACLE_BASE/oradata -responseFile NO_VALUE  characterSet AL32UTF8 -nationaICharaterSet AL16UTF16 –emConfiguration LOCAL -dbsnmpPassword oracle -sysmanPassword oracle

 

 

 

靜默刪除資料庫

刪除資料庫就非常簡單了

 

[oracle@dongyang ~]$ dbca –help

Delete a database by specifying the following parameters:

        -deleteDatabase

                -sourceDB    database sid>(<source>一定是SID )

                [-sysDBAUserName    

                 -sysDBAPassword     ]

 

 

[oracle@dongyang ~]$dbca –silent –deleteDatabase  -sourceDB orcl1

 

 


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

相關文章