19c_dg切换

1.查看特定配置参数

std_orcl:主
orcl:备
+b : orcl路径
/u01/app/oracle/oradata/ : std_orcl路径

1.1主库

1.对比主备库日志,同步才能做下一步
SQL> select max(sequence#) from v$archived_log;

2.对比数据文件
SQL> select tablespace_name,file_name from dba_data_files;

3.查看主库状态
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ WRITE	       PRIMARY		MAXIMUM PERFORMANCE  TO STANDBY

4.查看其他配置
SQL> show parameter standby_file_management;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
standby_file_management 	     string	 AUTO

SQL> show parameter local;  

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
local_listener			     string

5.查看archive相关配置
SQL> show parameter archive;
NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target		     integer	 0
log_archive_config		     string	 DG_CONFIG=(std_orcl,orcl)
log_archive_dest		     string
log_archive_dest_1		     string	 location=/home/oracle/arch val
						     id_for=(all_logfiles,all_roles
						     ) db_unique_name=std_orcl

log_archive_dest_2		     string	 service=orcl async VALID_FOR=(
						     ONLINE_LOGFILE,PRIMARY_ROLE) D
						     B_UNIQUE_NAME=orcl

6.查看name相关
SQL>  show parameter name;


NAME				     TYPE	         VALUE
------------------------ ------------  -----------------------------------------
cdb_cluster_name		  string
cell_offloadgroup_name	  string
db_file_name_convert	  string	    +B, /u01/app/oracle/oradata
db_name 			      string	    orcl
db_unique_name			  string	    std_orcl
global_names			  boolean	    FALSE
instance_name			  string	    orcl
lock_name_space 		  string
log_file_name_convert	  string	    +B/ORCL/ONLINELOG/, /u01/app/oracle/oradata/
pdb_file_name_convert	  string
processor_group_name	 string
service_names			 string	         std_orcl

7.查看fal相关内容
SQL> show parameter fal;

NAME				     TYPE	  VALUE
----------------------   -------  ------- 
fal_client			     string	  STD_ORCL
fal_server			     string	  orcl

1.2备库

1.select max(sequence#) from v$archived_log;

2.切换时要停库,最好没有其他session链接
SQL> select username,sid from v$session where username is not null;

3.对比数据文件
SQL> select tablespace_name,file_name from dba_data_files;

4.查看备库状态
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE  NOT ALLOWED

5.查看arch,redo相关参数
SQL> show parameter archive;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target		     integer	 0
log_archive_config		     string	 DG_CONFIG=(orcl,std_orcl)
log_archive_dest		     string
log_archive_dest_1		     string	 location=/home/oracle/arch VAL
						     ID_FOR=(ALL_LOGFILES,ALL_ROLES
						     ) DB_UNIQUE_NAME=orcl

log_archive_dest_2		     string	 service=std_orcl async VALID_F
						     OR=(ONLINE_LOGFILE,PRIMARY_ROL
						     E) DB_UNIQUE_NAME=std_orcl

6.查看name相关配置
SQL> show parameter name;

NAME				         TYPE	       VALUE
-----------------------      ------------- ----------------------------------------
cdb_cluster_name		     string
cell_offloadgroup_name		 string
db_file_name_convert		 string	       /u01/app/oracle/oradata, +B
db_name 			         string	       orcl
db_unique_name			     string	       orcl
global_names			     boolean	   FALSE
instance_name			     string	       orcl
lock_name_space 		     string
log_file_name_convert		 string	      /u01/app/oracle/oradata/, +B/ORCL/ONLINELOG/
pdb_file_name_convert		 string
processor_group_name		 string
service_names			     string	      orcl

7.查看fal相关
SQL> show parameter fal;

NAME				     TYPE	 VALUE
------------------       ------- ----------- 
fal_client			     string	 ORCL
fal_server			     string	 STD_ORCL

2.切换

2.1没有其他用户登录-直接切

--主库:std_orcl
SQL> alter database commit to switchover to standby; 
SQL> set linesize 300
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

---主库变中间状态,等待确认切换状态(目前为:TO PRIMARY)
NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ ONLY	       PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY

---启用mrp0进程,并查看角色及切换状态
SQL>  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE  DISCONNECT FROM SESSION;
SQL>  select name,open_mode,database_role,protection_mode,switchover_status from v$database;
NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY



备库:orcl
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1744828000 bytes
Fixed Size		    9135712 bytes
Variable Size		  452984832 bytes
Database Buffers	 1275068416 bytes
Redo Buffers		    7639040 bytes
Database mounted.

---因为主库执行了alter database commit to switchover to standby; 备库也进入中间待切换角色状态
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  MOUNTED	       PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY

---备库切为主数据库
SQL> alter database commit to switchover to primary;
SQL> alter database open;

--原备库orcl查看:原备库角色已经变为主库
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ WRITE	       PRIMARY		MAXIMUM PERFORMANCE  TO STANDBY



---原主库std_orcl查看:已变成备库:
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE  NOT ALLOWED

原主库(现备库)查看复制状态
SQL> select process,status from v$managed_standby;

PROCESS   STATUS
--------- ------------
ARCH	  CONNECTED
DGRD	  ALLOCATED
DGRD	  ALLOCATED
ARCH	  CONNECTED
ARCH	  CONNECTED
MRP0	  APPLYING_LOG
ARCH	  CLOSING
RFS	  IDLE
RFS	  IDLE
RFS	  IDLE

10 rows selected.

至此:切换成功,orcl为新主库,std_orcl为新备库

2.2有用户登录,强制切换

主库:orcl
备库:std_orcl

--主库:orcl
SQL> alter database commit to switchover to standby with session shutdown;
SQL> shutdown 
SQL> startup mount 
ORACLE instance started.

Total System Global Area 1744828000 bytes
Fixed Size		    9135712 bytes
Variable Size		  452984832 bytes
Database Buffers	 1275068416 bytes
Redo Buffers		    7639040 bytes
Database mounted.

--主库因强制切换,现需恢复
SQL> set linesize 300
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  MOUNTED	       PHYSICAL STANDBY MAXIMUM PERFORMANCE  RECOVERY NEEDED



--备库执行:std_orcl,备库已经变为中间待切换状态
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY

---备库切换,变主库
SQL> alter database commit to switchover to primary;
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  MOUNTED	       PRIMARY		MAXIMUM PERFORMANCE  NOT ALLOWED

SQL> alter database open;

ps 至此,主备切换完成,orcl:新备库 std_orcl:新主库





--新备库:orcl
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  MOUNTED	       PHYSICAL STANDBY MAXIMUM PERFORMANCE  RECOVERY NEEDED

---重启mrp0进程,做数据恢复
SQL>  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE  DISCONNECT FROM SESSION;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE cancel;

---查看状态
SQL> select name,open_mode,database_role,protection_mode,switchover_status from v$database;

NAME	  OPEN_MODE	       DATABASE_ROLE	PROTECTION_MODE      SWITCHOVER_STATUS
--------- -------------------- ---------------- -------------------- --------------------
ORCL	  MOUNTED	       PHYSICAL STANDBY MAXIMUM PERFORMANCE  NOT ALLOWED

---开库
SQL> alter database open;

---启动mrp0进程
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE  DISCONNECT FROM SESSION;

---查看状态
SQL> select process,status from v$managed_standby;

PROCESS   STATUS
--------- ------------
ARCH	  CONNECTED
DGRD	  ALLOCATED
DGRD	  ALLOCATED
ARCH	  CONNECTED
ARCH	  CLOSING
ARCH	  CONNECTED
RFS	      IDLE
RFS	      IDLE
RFS	      IDLE
MRP0	  APPLYING_LOG

10 rows selected.

至此,强制切换完成

你可能感兴趣的:(oracle,数据库)