环境:RHEL 6.4 + Oracle 11.2.0.4
一、主备手工切换
二、重命名数据文件
Reference
1.1.1 查看主库状态
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE;
1.1.2 切换到备库
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
1.1.3 启动到mount状态
SQL> STARTUP MOUNT
1.2.1 查看备库状态
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE;
1.2.2 切换到主库
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
1.2.3 数据库open
SQL> ALTER DATABASE OPEN;
1.3.1 备库mount状态直接启动日志应用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
1.3.2 备库切换到open状态,启用Real-time queryA physical standby database instance cannot be opened if Redo Apply is active on a mounted instance of that database. Use the following SQL statements to stop Redo Apply, open a standby instance read-only, and restart Redo Apply:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; SQL> ALTER DATABASE OPEN; SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
SQL> ALTER TABLESPACE DBS_D_JINGYU OFFLINE;
$ mv /u01/oradata01/JINGYU/datafile/o1_mf_dbs_d_ji_byqy17ph_.dbf /u01/oradata01/JINGYU/datafile/DBS_D_JINGYU01.dbf
SQL> ALTER TABLESPACE DBS_D_JINGYU RENAME DATAFILE '/u01/oradata01/JINGYU/datafile/o1_mf_dbs_d_ji_byqy17ph_.dbf' TO '/u01/oradata01/JINGYU/datafile/DBS_D_JINGYU01.dbf'; SQL> ALTER TABLESPACE DBS_D_JINGYU ONLINE;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> SHUTDOWN IMMEDIATE;
$ mv /u01/oradata01/BOSTON/datafile/o1_mf_dbs_d_ji_22qjsbps_.dbf /u01/oradata01/BOSTON/datafile/DBS_D_JINGYU01.dbf
SQL> STARTUP MOUNT
2.8.1 需要先调整参数STANDBY_FILE_MANAGEMENT为MANUAL
否则重命名数据文件时会报错 ORA-01275: Operation RENAME is not allowed if standby file management is automatic.
SQL> SHOW PARAMETER STANDBY_FILE_MANAGEMENT SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT = MANUAL;
2.8.2 重命名数据文件
SQL> ALTER DATABASE RENAME FILE '/u01/oradata01/BOSTON/datafile/o1_mf_dbs_d_ji_22qjsbps_.dbf' TO '/u01/oradata01/BOSTON/datafile/DBS_D_JINGYU01.dbf';
2.8.3 参数调整为AUTO
SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT = AUTO;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;