在RAC中用NID修改資料庫名稱

space6212發表於2019-06-16
在rac中修改db_name的步驟與單例項步驟差不多,主要是要修改一些與cluster相關的引數。


停止所有例項,然後把其中一個例項啟動到mount狀態下:
SQL> startup mount
ORACLE instance started.

Total System Global Area 1476395008 bytes
Fixed Size 2030200 bytes
Variable Size 268436872 bytes
Database Buffers 1191182336 bytes
Redo Buffers 14745600 bytes
Database mounted.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

嘗試用NID修改資料庫名稱:
bash-3.00$ nid target=sys/testrac dbname=pretrade logfile=~/nid1.log

檢視日誌:
bash-3.00$ more nid1.log

DBNEWID: Release 10.2.0.3.0 - Production on 星期四 9月 27 23:00:44 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to database TRADEDB (DBID=4181457554)

NID-00120: Database should be mounted exclusively


Change of database name failed during validation - database is intact.
DBNEWID - Completed with validation errors.

發現有報錯,這個因為當前資料庫是rac,需要修改cluster_database=false,這也就是用nid修改rac資料庫名稱與修改單例項資料庫名稱的一個主要區別。

接著修改引數繼續嘗試:
bash-3.00$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.3.0 - Production on 星期四 9月 27 23:01:09 2007

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> alter system set cluster_database=false scope=spfile;

System altered.

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1476395008 bytes
Fixed Size 2030200 bytes
Variable Size 268436872 bytes
Database Buffers 1191182336 bytes
Redo Buffers 14745600 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
bash-3.00$ nid target=sys/testrac dbname=pretrade logfile=~/nid2.log
bash-3.00$ vi nid2.log


DBNEWID: Release 10.2.0.3.0 - Production on 320307306332313304 9324302 27 23:03:24 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to database TRADEDB (DBID=4181457554)

Connected to server version 10.2.0

Control Files in database:
+DATA/controlfile/control1
+DATA/controlfile/control2
+DATA/controlfile/control3

Changing database ID from 4181457554 to 3201410814
Changing database name from TRADEDB to PRETRADE
Control File +DATA/controlfile/control1 - modified
Control File +DATA/controlfile/control2 - modified
Control File +DATA/controlfile/control3 - modified
Datafile +DATA/datafile/system1.ora - dbid changed, wrote new name
Datafile +DATA/datafile/undotbs11.ora - dbid changed, wrote new name
......
Datafile +DATA/datafile/sysaux2.ora - dbid changed, wrote new name
Datafile +DATA/datafile/gpo1.ora - dbid changed, wrote new name
Datafile +DATA/datafile/gpo2.ora - dbid changed, wrote new name
Datafile +DATA/datafile/temp01.ora - dbid changed, wrote new name
Control File +DATA/controlfile/control1 - dbid changed, wrote new name
Control File +DATA/controlfile/control2 - dbid changed, wrote new name
Control File +DATA/controlfile/control3 - dbid changed, wrote new name
Instance shut down

Database name changed to PRETRADE.
Modify parameter file and generate a new password file before restarting.
Database ID for database PRETRADE changed to 3201410814.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

從日誌可以看到,資料庫名稱修改成功。
重新把cluster_database設定為true,並把db_name引數修改為新的名稱:
bash-3.00$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.3.0 - Production on 星期四 9月 27 23:04:19 2007

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1476395008 bytes
Fixed Size 2030200 bytes
Variable Size 268436872 bytes
Database Buffers 1191182336 bytes
Redo Buffers 14745600 bytes
ORA-01103: database name 'PRETRADE' in control file is not 'TRADEDB'


SQL> alter system set db_name=pretrade scope=spfile;

System altered.

SQL> alter system set cluster_database=true scope=spfile;

System altered.

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1476395008 bytes
Fixed Size 2030200 bytes
Variable Size 268436872 bytes
Database Buffers 1191182336 bytes
Redo Buffers 14745600 bytes
Database mounted.

最後在開啟的時候open resetlogs即可。
SQL> alter database open resetlogs;

把rac環境的其他節點也啟動,至此,dbname修改完成。

如果nid修改時報錯:
ID-00135: There are 1 active threads

則表示有活動程式,可能原因是:
1、上次資料庫不是乾淨關閉的
2、有其他人在操作這個資料庫

最簡單的辦法是停止監聽,然後把資料庫乾淨關閉再做操作。

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

相關文章