主库未设置db_file_name_convert,主备切换后新主库添加数据文件后新备库的情况
主库:
数据库:oracle 11.2.0.4
系统:CentOS7.9
主机名:oel
实例名:orcl150
备库:
数据库:oracle 11.2.0.4
系统:CentOS7.9
主机名:oeldg
实例名:orcl151
问题:主库在没有设置db_file_name_convert的情况下,主备切换后新主库添加一个数据文件,新备库会出现什么情况?
备库db_file_name_convert参数如下:
*.db_file_name_convert='/u01/app/oracle/oradata/orcl150/','/u01/app/orcl151/'
现执行switchover
1) 主库切换为备库
alter database commit to switchover to physical standby with session shutdown
startup mount
2) 备库切换为主库
alter database commit to switchover to primary with session shutdown
alter database open
3) 现备库打开只读实时应用模式
alter database open;
alter database recover managed standby database using current logfile disconnect from session;
4) 检查切换状态
select open_mode,database_role,db_unique_name from v$database;
新主库添加数据文件
SQL> select open_mode,database_role,db_unique_name from v$database;
OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME
-------------------- ---------------- ------------------------------
READ WRITE PRIMARY ORCL151
SQL> alter tablespace users add datafile '/u01/app/oracle/oradata/orcl151/users02.dbf' size 1g autoextend on;
Tablespace altered.
查看新备库数据文件
SQL> r
1* select file_name,autoextensible,tablespace_name,bytes/1024/1024 from dba_data_files
FILE_NAME AUT TABLESPACE_NAME BYTES/1024/1024
---------------------------------------------------------------------- --- ------------------------------ ---------------
/u01/app/oracle/oradata/orcl150/users01.dbf YES USERS 5
/u01/app/oracle/oradata/orcl150/undotbs01.dbf YES UNDOTBS1 30
/u01/app/oracle/oradata/orcl150/sysaux01.dbf YES SYSAUX 510
/u01/app/oracle/oradata/orcl150/system01.dbf YES SYSTEM 740
/u01/app/oracle/oradata/orcl150/users02.dbf YES USERS 25
/u01/app/oracle/oradata/orcl150/users03.dbf YES USERS 10
/u01/app/oracle/oradata/orcl150/users04.dbf YES USERS 5
/u01/app/oracle/oradata/orcl151/users02.dbf YES USERS 1024
8 rows selected.
如上所示,新备库自动增加的数据文件为/u01/app/oracle/oradata/orcl151/users02.dbf,该文件与新主库添加的文件同路径同名.
新备库告警日志:
2022-06-27 21:07:43.489000 +08:00
WARNING: File being created with same name as in Primary
Existing file may be overwritten
2022-06-27 21:07:48.805000 +08:00
Warning: VKTM detected a time drift.
Time drifts can result in an unexpected behavior such as time-outs. Please check trace file for more details.
2022-06-27 21:08:23.011000 +08:00
Recovery created file /u01/app/oracle/oradata/orcl151/users02.dbf
Successfully added datafile 8 to media recovery
Datafile #8: '/u01/app/oracle/oradata/orcl151/users02.dbf'
那么如何解决文件覆盖的问题呢?
解决过程如下,新备库执行:
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/orcl151/','/u01/app/oracle/oradata/orcl150/' scope=spfile;
System altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 2455228416 bytes
Fixed Size 2255712 bytes
Variable Size 620758176 bytes
Database Buffers 1811939328 bytes
Redo Buffers 20275200 bytes
Database mounted.
Database opened.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
新主库添加数据文件再做测试
SQL> alter tablespace users add datafile '/u01/app/oracle/oradata/orcl151/users05.dbf' size 60m autoextend on;
Tablespace altered.
验证新备库数据文件
SQL> select file_name,autoextensible,tablespace_name,bytes/1024/1024 from dba_data_files;
FILE_NAME AUT TABLESPACE_NAME BYTES/1024/1024
---------------------------------------------------------------------- --- ------------------------------ ---------------
/u01/app/oracle/oradata/orcl150/users01.dbf YES USERS 5
/u01/app/oracle/oradata/orcl150/undotbs01.dbf YES UNDOTBS1 30
/u01/app/oracle/oradata/orcl150/sysaux01.dbf YES SYSAUX 510
/u01/app/oracle/oradata/orcl150/system01.dbf YES SYSTEM 740
/u01/app/oracle/oradata/orcl150/users02.dbf YES USERS 25
/u01/app/oracle/oradata/orcl150/users03.dbf YES USERS 10
/u01/app/oracle/oradata/orcl150/users04.dbf YES USERS 5
/u01/app/oracle/oradata/orcl151/users02.dbf YES USERS 1024
/u01/app/oracle/oradata/orcl150/users05.dbf YES USERS 60
9 rows selected.
如上,生成的文件为新设置的路径.