win->linux
1.单机到单机迁移(尽量减少停机时间)
使用dataguard技术,可以跨系统、跨版本
停机时间:数据库升级时间,应用切换时间,IP地址切换等因素,需要做充分测试。
数据不能丢失
主库/win | 备库/linux | |
---|---|---|
ip | 192.168.5.87 | 192.168.5.144 |
监听 | 动态/静态 | 静态 |
omf | 启用 | 启用 |
db_recovery | 启用 | 启用 |
db_name | orcl | orcl |
db_unique_name | orcl | dgorcl |
主库配置
1.启动强制日志
alter database force logging;
2.启动归档
修改归档文件格式
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;
3.修改归档路径
使用快速闪回去存放归档
alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST';
4.重启数据库
shutdown immediate;
startup mount;
SQL> alter database archivelog ;
SQL> alter database open;
5.设置初始化参数
—注意windows路径需要大写
alter system set log_archive_config='DG_CONFIG=(orcl,dgorcl)' scope=spfile;
alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' scope=spfile;
alter system set log_archive_dest_2='SERVICE=tnsdgorcl LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dgorcl' scope=both;
alter system set standby_file_management='AUTO' scope=both;
alter system set fal_client='tnsorcl' scope=both;
alter system set fal_server='tnsdgorcl' scope=both;
alter system set db_file_name_convert='/opt/oracle/oradata/orcl','D:\U01\APP\ORACLE\ORADATA\ORCL' scope=spfile;
alter system set log_file_name_convert='/opt/oracle/oradata/orcl','D:\U01\APP\ORACLE\ORADATA\ORCL','/opt/oracle/fast_recovery_area/orcl/onlinelog','D:\U01\APP\RECOVERY_AREA\ORCL\ONLINELOG' scope=spfile;
备库配置
1.创建初始化参数文件
*.audit_file_dest='/opt/oracle/admin/orcl/adump'
*.compatible='12.2.0'
*.control_files='/opt/oracle/oradata/orcl/controlfile/control01.ctl','/opt/oracle/fast_recovery_area/orcl/controlfile/control02.ctl'#Restore Controlfile
*.db_file_name_convert='D:\U01\APP\ORACLE\ORADATA\ORCL','/opt/oracle/oradata/orcl/'
*.db_name='orcl'
*.db_recovery_file_dest='/opt/oracle/fast_recovery_area/'
*.db_recovery_file_dest_size=20g
*.db_unique_name='dgorcl'
*.fal_client='tnsdgorcl'
*.fal_server='tnsorcl'
*.log_archive_config='DG_CONFIG=(orcl,dgorcl)'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dgorcl'
*.log_archive_dest_2='SERVICE=tnsorcl LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.log_file_name_convert='D:\U01\APP\ORACLE\ORADATA\ORCL','/opt/oracle/oradata/orcl/','D:\U01\APP\RECOVERY_AREA\ORCL\ONLINELOG','/opt/oracle/fast_recovery_area/orcl/onlinelog/'
*.pga_aggregate_target=850m
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2600m
*.standby_file_management='AUTO'
2.创建目录
mkdir -p /opt/oracle/fast_recovery_area/orcl/onlinelog
3.启动到nomount阶段
注意:以spfile启动实例,不要用pfile启动
create spfile from pfile;
startup nomount;
4.创建监听
注意静态监听sid一定要大写
tnsping 192.168.5.87 1522
tnsping 192.168.5.144 1522
linux备库 listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /opt/oracle/product/12.2.0/dbhome_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1522))
)
ADR_BASE_LISTENER = /opt/oracle
linux备库 cat tnsnames.ora
TNSDGORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
TNSORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.87)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
win 主库 listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\u01\app\oracle\product\12.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\u01\app\oracle\product\12.2.0\dbhome_1\bin\oraclr12.dll")
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = D:\u01\app\oracle\product\12.2.0\dbhome_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.87)(PORT = 1522))
)
)
ADR_BASE_LISTENER = D:\u01\app\oracle\product\12.2.0\dbhome_1\log
win 主库 tnsnames.ora
TNSGDORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
TNSORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.87)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
5.主备库参数检查
db_unique_name 需重启数据库
compatible='12.2.0'
log_archive_config='DG_CONFIG=(fx,sfx)' 是指的DB_UNIQUE_NAME值
log_archive_dest_1
log_archive_dest_2
log_archive_dest_state_1
log_archive_dest_state_2
ENABLE(默认)
DEFER:禁用redo传输
ALTERNATE:其他的传输失败,这个将启用。
db_file_name_convert
log_file_name_convert
standby_file_management
fal_client 指tnsname
fal_server
7.使用Duplicate创建物理standby
rman target sys/Oracle123@tnsorcl
connect auxiliary sys/Oracle123@tnsdgorcl ;
duplicate target database for standby from active database nofilenamecheck;
alter database open;
8.添加Standby日志组
alter database add standby logfile group 4 size 200m;
alter database add standby logfile group 5 size 200m;
alter database add standby logfile group 6 size 200m;
alter database add standby logfile group 7 size 200m;
alter database drop standby logfile group 4;
alter database drop standby logfile group 5;
alter database drop standby logfile group 6;
alter database drop standby logfile group 7;
视图:
v$logfile
v$standby_log
--------------------------------------------------------------
select decode(g.THREAD#, null, vs.THREAD#, g.THREAD#) THREAD#,
decode(g.GROUP#, null, vs.GROUP#, g.GROUP#) GROUP#,
decode(g.BYTES, null, vs.BYTES / 1024 / 1024, g.BYTES / 1024 / 1024) BYTES,
decode(g.STATUS, null, vs.STATUS, g.STATUS) STATUS,
decode(g.ARCHIVED, null, vs.ARCHIVED, g.ARCHIVED) ARCHIVED,
--decode(g.GROUP#,null,'STANDBY REDO','REDO') type,
gf.TYPE,
gf.MEMBER
from v$logfile gf
left join v$log g
on gf.GROUP# = g.GROUP#
left join v$standby_log vs
on gf.GROUP# = vs.GROUP#
order by 1, 2;
9.开起实时同步
开启redo应用(实时同步)commit
自Oracle Database 12.1起,USING CURRENT LOGFILE子句已弃用
alter database recover managed standby database using current logfile disconnect from session;弃用
alter database recover managed standby database using current logfile disconnect;弃用
alter database recover managed standby database disconnect;
停止redo应用
alter database recover managed standby database cancel;
开启redo应用(日志切换才会同步)
alter database recover managed standby database using archived logfile disconnect;
alter system switch logfile;
查看状态:
select name,open_mode,database_role,protection_mode,protection_level from v$database;
10.数据测试
create table t (id int);
insert into t values (100);
10.关闭同步
alter database recover managed standby database cancel;