场景:
在生产环境修改集群环境下数据库的db_unique_name后,集群数据库资源状态与数据库实例状态发生了不一致
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修改OCR中记录的db_unique_name
首先使用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