叢集修改OCR中記錄的db_unique_name以及db_name

sjw1933發表於2022-10-09

場景:

SQL> show parameter db_unique_name

NAME                                 TYPE       VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string     racdb

SQL> show parameter db_name
NAME                                 TYPE       VALUE
------------------------------------ ----------- ------------------------------
db_name                             string     prod

SQL> alter system set db_unique_name=orcl scope=spfile sid='*';
System altered.

重啟節點1節點2例項:
節點1:
SQL> shutdown immediate;
SQL> startup;

節點2:
SQL> shutdown immediate;
SQL> startup;

SQL> show parameter db_unique_name
NAME                                 TYPE       VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string     ORCL
db_unique_name修改完畢

[grid@rac1 ~]$ crsctl status res -t
檢視資源狀態:
ora.racdb.db
    1       OFFLINE OFFLINE                               Instance Shutdown   
    2       OFFLINE OFFLINE                               Instance Shutdown

真實資料庫例項狀態:
SQL> select instance_name,status from v$instance;
INSTANCE_NAME   STATUS
---------------- ------------
racdb1           OPEN

SQL> select instance_name,status from v$instance;
INSTANCE_NAME   STATUS
---------------- ------------
racdb2           OPEN

叢集資料庫資源狀態與真實資料庫例項狀態不一致。
是因為OCR中記錄的db_unique_name與實際資料庫的db_unique_name不一致導致的。
並且ora.racdb.db資源是按db_unqiue_name識別的ora.<db_unique_name>.db

檢視資料庫資源資訊:
[grid@rac1 ~]$ srvctl config database -d racdb   //-d db_unique_name
Database unique name: racdb
Database name: prod
Oracle home: /oracle/app/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/racdb/spfileracdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: racdb
Database instances: racdb1,racdb2
Disk Groups: DATA
Mount point paths: 
Services: session
Type: RAC
Database is administrator managed

[grid@rac1 ~]$ crsctl status res ora.racdb.db -f
....
....
DB_UNIQUE_NAME=racdb
....
....

可以看出OCR中記錄的db_unique_name皆為racdb,而資料庫實際db_unique_name為orcl

解決方法:

方式一:srvctl 與 crsctl修改資源屬性

首先使用srvctl進行修改

srvctl modify database -d <db_unique_name> [-n <db_name>]
[grid@rac1 ~]$ srvctl modify database -d orcl
PRCD-1120 : The resource for database prod could not be found.
PRCR-1001 : Resource ora.prod.db does not exist
提示ora.prod.db資源不存在,說明該資源是根據db_unique_name來識別的,srvctl無法修改。

使用crsctl修改OCR中記錄的db_unique_name資訊:
[root@rac1 ~]# /oracle/grid/crs_1/bin/crsctl modify res ora.racdb.db -attr 'DB_UNIQUE_NAME=orcl';

[grid@rac1 ~]$ crsctl status res ora.racdb.db -f
....
DB_UNIQUE_NAME=orcl
....

[grid@rac1 ~]$ srvctl config database -d racdb
Database unique name: orcl
Database name: prod
Oracle home: /oracle/app/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/racdb/spfileracdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: racdb
Database instances: racdb1,racdb2
PRCD-1120 : The resource for database orcl could not be found.
PRCR-1001 : Resource ora.orcl.db does not exist

修改成功,但是這種方式僅僅修改了OCR中記錄的db_unique_name,修改後叢集資料庫資源狀態與真實資料庫例項狀態仍不一致。
認為是db_unique_name變化後,資源名稱也隨之變化的問題

方式二:新增新資料庫資源

方式二:新增一個資料庫資源

[oracle@rac1 ~]$ srvctl add database -d orcl -o /oracle/app/product/11.2.0/db_1 -n prod -p +DATA/racdb/spfileracdb.ora -r PRIMARY -s open -t immediate -y AUTOMATIC 
選項列表:
  -d <db_unique_name>     Unique name for the database
  -o <oracle_home>         ORACLE_HOME path
  -c <type>               Type of database: RAC One Node, RAC, or Single Instance
  -e <server_list>         Candidate server list for RAC One Node database
  -i <inst_name>           Instance name prefix for administrator-managed RAC One Node database 
  -w <timeout>             Online relocation timeout in minutes
  -x <node_name>           Node name. -x option is specified for single-instance databases
  -m <domain>             Domain for database. Must be set if database has DB_DOMAIN set.
  -p <spfile>             Server parameter file path
  -r <role>               Role of the database (primary, physical_standby, logical_standby, snapshot_standby)
  -s <start_options>       Startup options for the database. Examples of startup options are OPEN, MOUNT, or 'READ ONLY'.
  -t <stop_options>       Stop options for the database. Examples of shutdown options are NORMAL, TRANSACTIONAL, IMMEDIATE, or ABORT.
  -n <db_name>             Database name (DB_NAME), if different from the unique name given by the -d option
  -y <dbpolicy>           Management policy for the database (AUTOMATIC, MANUAL, or NORESTART)
  -g "<serverpool_list>"   Comma separated list of database server pool names
  -a "<diskgroup_list>"   Comma separated list of disk groups
  -j "<acfs_path_list>"   Comma separated list of ACFS paths where database's dependency will be set
  -h                       Print usage

嘗試啟動新新增資料庫資源:
[grid@rac1 ~]$ srvctl start database -d orcl
PRKO-3119 : Database orcl cannot be started since it has no configured instances

[grid@rac1 ~]$ srvctl config database -d orcl
Database unique name: orcl
Database name: prod
Oracle home: /oracle/app/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/racdb/spfileracdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: orcl
Database instances: 
Disk Groups: 
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed

向資料庫資源新增例項://新增例項該方式新增
[oracle@rac1 ~]$ srvctl add instance -d orcl -i racdb1 -n rac1
[oracle@rac1 ~]$ srvctl add instance -d orcl -i racdb2 -n rac2

[grid@rac1 ~]$ srvctl config database -d orcl
Database unique name: orcl
Database name: prod
Oracle home: /oracle/app/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/racdb/spfileracdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: orcl
Database instances: racdb1,racdb2
Disk Groups: 
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed

再次啟動:
[grid@rac1 ~]$ srvctl start database -d orcl

ora.orcl.db
    1       ONLINE ONLINE       rac1                     Open                
    2       ONLINE ONLINE       rac2                     Open


此時叢集資料庫資源狀態與真實資料庫例項狀態保持一致。

待例項關閉後,刪除舊資料庫資源
[root@rac1 ~]#crsctl delete res ora.racdb.db

附加: 修改OCR中的DB_NAME

修改OCR中的DB_NAME

[root@rac1 ~]# /oracle/grid/crs_1/bin/srvctl modify database -d racdb -n prod     // -n代表修改後的名字

[grid@rac1 ~]$ srvctl config database -d racdb 
Database unique name: racdb
Database name: prod
Oracle home: /oracle/app/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/racdb/spfileracdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: racdb
Database instances: racdb1,racdb2
Disk Groups: DATA
Mount point paths: 
Services: session
Type: RAC
Database is administrator managed


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

相關文章