如何修改資料庫例項及資料庫名

zhangsharp20發表於2014-12-29
一、修改例項:

將原引數檔案重新命名即可


即原例項為orcl,原引數檔案為spfileorcl.ora,則將其改為例項為credit的引數檔案,即spfilecredit.ora

可以透過命令

SQL>create pfile='/home/dbs/pfilecredit.ora' from spfile='/home/dbs/spfileorcl.ora';

先建立一個pfie檔案,然後透過命令

>create spfile from pfile

建立一個spfilecredit.ora的檔案


二、修改資料庫名


可以透過oracle的內部nid命令進行修改,此命令在$ORACLE_HOME/dbs/bin目錄下

現將引數檔案中的db_name引數修改到目標資料庫名

>alter system set db_name=credit scpoe =both;

>shutdown immediate;

>startup mount

>! nid target=sys/123456 db_name=credit

Change database ID and database name zhuzerp to CREDIT? (Y/[N]) =》y

>
shutdown immedaite

>startup

>select name from v$database;

>select instance_name from v$instance;


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

另附參考:轉自

1.用oracle自帶的工具nid改資料庫名

    在本例中,假設原來的資料庫名為test,要改成testdb,原例項名(service_name,instance_name)test,要改成testdb.

    nid是自帶的工具,在oracle_home/bin目錄中。以下方法假設登陸到資料庫本機做。

    1.1 sqlplus “sys/password as sysdba”

    1.2 sql》shutdown immediate --先停掉資料庫

    1.3 sql》startup mount --nid需要在mount狀態下才能做。

    1.4sql》host nid target=sys/password dbname=new_dbname --nid是一個在作業系統下執行的命令,在sqlplus環境中用host 去呼叫作業系統環境下的命令。命令中,當你想將資料庫名字改為TESTDB時,應寫成dbname=testdb

    1.5執行後程式會詢問:

    Change database ID and database name TEST to TESTDB? (Y/[N]) =》y

    敲y確定。

    之後程式會對控制檔案,資料檔案進行修改:

    Control File C:ORACLEORADATATESTCONTROL01.CTL - modified

    Control File C:ORACLEORADATATESTCONTROL02.CTL - modified

    Control File C:ORACLEORADATATESTCONTROL03.CTL - modified

    Datafile C:ORACLEORADATATEST YSTEM01.DBF - dbid changed, wrote new name

    Datafile C:ORACLEORADATATESTUNDOTBS01.DBF - dbid changed, wrote new nam

    Datafile C:ORACLEORADATATESTINDX01.DBF - dbid changed, wrote new name

    Datafile C:ORACLEORADATATESTTOOLS01.DBF - dbid changed, wrote new name

    Datafile C:ORACLEORADATATESTUSERS01.DBF - dbid changed, wrote new name

    Datafile D:DATAFILEPORMALS_SPA.DBF - dbid changed, wrote new name

    Datafile C:ORACLEORADATATESTOEM_REPOSITORY.DBF - dbid changed, wrote ne

    name

    Datafile D:DATAFILEPORMALS_SPA_01.DBF - dbid changed, wrote new name

    Datafile C:ORACLEORADATATESTTEMP01.DBF - dbid changed, wrote new name

    Control File C:ORACLEORADATATESTCONTROL01.CTL - dbid changed, wrote new

    name

    Control File C:ORACLEORADATATESTCONTROL02.CTL - dbid changed, wrote new

    name

    Control File C:ORACLEORADATATESTCONTROL03.CTL - dbid changed, wrote new

    name

    Database name changed to TESTDB.

    Modify parameter file and generate a new password file before restarting.

    Database ID for database TESTDB changed to 2321050327.

    All previous backups and archived redo logs for this database are unusable.

    Shut down database and open with RESETLOGS option.

    Succesfully changed database name and ID.

    DBNEWID - Completed succesfully.

    1.6 停庫再到mount狀態下改db_name:

    sql》shutdown immediate;

    sql》startup mount

    sql》alter system set db_name=testdb scope=spfile;

    sql》shutdown immediate;

    1.7 重新建立sys的password檔案:

    passwd檔案通常放在oracle_home/database目錄下,檔案命名形式為PWDsid.ora,sid為例項名(Service_name),如當前的資料庫名及service_name為test,則passwd檔案為PWDtest.ora

    sql》host orapwd file=c:oracleora92databasepwdtest.ora password=123456 entries=5

    要注意一下,此時雖然資料庫名已經改成testdb了,但instance_name還是test,所以,passwd檔案必須跟以前一樣。否則會出錯。

    1.8 開啟資料庫:(要open resetlogs)

    sql》startup mount

    sql》alter database open resetlogs;

    1.9 檢查:

    sql》select dbid,name from v$database;

    2.改好資料庫名後,接著改instance_name

    2.1如果是windows系統,要先把所有的oracle服務先關閉,否則會出錯。

    2.2先將原來的service_name刪除:

    在作業系統中,進入cmd,

    oradim -delete -sid test

    2.3建立密碼檔案

    orapwd file=c:/oracle/ora92/database/pwdtestdb.ora password=。…entries=

    2.4建立一個新的sid,也就是你想改名的sid:

    oradim -new -sid testdb -intpwd 密碼 -startmode a -pfile c:oracleora92databaseinittestdb.ora

    當資料庫啟動時,會在database目錄中找spfile,如果spfile不在就找initSID.ora這個檔案來頂。所以,可以把pfile直接建立在這裡。方便資料庫的啟動。

    2.5 進入oracle並建立spfile:

    c: set oracle_sid=testdb

    c:sqlplus “sys/password as sysdba”

    sql》create spfile from pile=‘c:oracleora92databaseinittestdb.ora’;

    2.6 reload listener:

    c:lsnrctl reload

    2.7 open resetlogs:

    ====================================================

    ============改資料庫名字==精簡版================

    1.用oracle自帶的工具nid改資料庫名

    1.1 sqlplus “sys/zhuzerp as sysdba”

    1.2 sql》shutdown immediate

    1.3 sql》startup mount

    1.4 sql》host nid target=sys/zhuzerp dbname=ORCLERP

    1.5 Change database ID and database name zhuzerp to ORCLERP? (Y/[N]) =》y

    1.6 sql》shutdown immediate

    sql》startup mount

    sql》alter system set db_name=ORCLERP scope=spfile;

    sql》shutdown immediate

    1.7 重新建立sys的password檔案

    host orapwd file=D:OracledatabasePWDzhuzerp.ora password=orclerp entries=5

    1.8 sql》startup mount

    sql》alter database open resetlogs;

    1.9 sql》select dbid,name from v$database;

    2.更改instance_name

    2.1 net stop oracleservicezhuzerp

    2.2 oradim -delete -sid zhuzerp

    2.3 orapwd file=D:OracledatabasePWDORCLERP.ora password=orclerp entries=5

    2.4 修改檔案中的db_name和instance_name

    D:Oracleadmintestpfileinit.ora.8252009155525

    2.5 oradim -new -sid ORCLERP -intpwd orclerp -startmode a -pfile D:Oracleadminzhuzerppfileinit.ora

    2.6 set oracle_sid=orclerp

    2.7 sqlplus “sys/orclerp as sysdba”

    2.8 create spfile from pfile=‘D:Oracleadminzhuzerppfileinit.ora’;

    2.9 lsnrctl reload

    ====================================================

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

相關文章