PARAMETER VALUE
------------------------------ --------------------
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_CHARACTERSET AL32UTF8
2、修改主库配置文件initLEODB.ora
这里现在数据库里修改相关的参数,与DG的参数就只与几个参数相关,大概就是日志,文件的位置的转换,GAP的处理,其实GAP已经会自动的处理,不过这里我们还是介绍配置FAL_SERVER,FAL_CLIENT参数。在修改完之后重新创建了pfile文件
先创建spfile,修改完后重新生成pfile
SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(leodb,leodbadg)';
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=leodb';
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=leodbadg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=leodbadg';
SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
SQL> alter system set FAL_SERVER=leodbadg;
SQL> alter system set FAL_CLIENT=leodb;
SQL> alter system set DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/leodbadg/','+DATA/LEODB/DATAFILE/' scope=spfile;
SQL> alter system set LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/leodbadg/','+DATA/LEODB/ONLINELOG/' scope=spfile;
SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO;
SQL> create pfile='/home/oracle/initLEODB.ora' from spfile;
DB_FILE_NAME_CONVERT和LOG_FILE_NAME_CONVERT参数必须重启数据库生效
下面是备份的主库pfile文件
leodb1.__data_transfer_cache_size=0
leodb2.__data_transfer_cache_size=0
leodb1.__db_cache_size=398458880
leodb2.__db_cache_size=394264576
leodb1.__inmemory_ext_roarea=0
leodb2.__inmemory_ext_roarea=0
leodb1.__inmemory_ext_rwarea=0
leodb2.__inmemory_ext_rwarea=0
leodb1.__java_pool_size=0
leodb2.__java_pool_size=0
leodb1.__large_pool_size=4194304
leodb2.__large_pool_size=4194304
leodb1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
leodb2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
leodb1.__pga_aggregate_target=264241152
leodb2.__pga_aggregate_target=264241152
leodb1.__sga_target=792723456
leodb2.__sga_target=792723456
leodb1.__shared_io_pool_size=29360128
leodb2.__shared_io_pool_size=29360128
leodb1.__shared_pool_size=343932928
leodb2.__shared_pool_size=348127232
leodb1.__streams_pool_size=0
leodb2.__streams_pool_size=0
leodb1.__unified_pga_pool_size=0
leodb2.__unified_pga_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/leodb/adump'
*.audit_trail='db'
*.cluster_database=TRUE
*.compatible='19.0.0'
*.control_files='+DATA/LEODB/CONTROLFILE/current.261.1056020927'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_file_name_convert='/u01/app/oracle/oradata/leodbadg/','+DATA/LEODB/DATAFILE/'
*.db_name='leodb'
*.db_recovery_file_dest_size=10737418240
*.db_recovery_file_dest='+DATA'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=leodbXDB)'
*.fal_client='LEODB'
*.fal_server='LEODBADG'
family:dw_helper.instance_mode='read-only'
leodb1.instance_number=1
leodb2.instance_number=2
*.local_listener='-oraagent-dummy-'
*.log_archive_config='DG_CONFIG=(leodb,leodbadg)'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=leodb'
*.log_archive_dest_2='SERVICE=leodbadg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=leodbadg'
*.log_archive_dest_state_1='ENABLE'
*.log_file_name_convert='/u01/app/oracle/oradata/leodbadg/','+DATA/LEODB/ONLINELOG/'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=252m
*.processes=300
*.remote_login_passwordfile='exclusive'
*.sga_target=756m
*.standby_file_management='AUTO'
leodb2.thread=2
leodb1.thread=1
leodb1.undo_tablespace='UNDOTBS1'
leodb2.undo_tablespace='UNDOTBS2'
SQL> alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby01.log' size 200m;
alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby01.log' size 200m;
alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby02.log' size 200m;
alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby03.log' size 200m;
alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby04.log' size 200m;
alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby05.log' size 200m;
alter database add standby logfile '+DATA/LEODB/ONLINELOG/standby06.log' size 200m;
col member for a60
select group#,status,type,member from v$logfile;
13、使用之前创建的initLEODBADG.ora文件启动备库到nomount状态
SELECT ROUND(SUM(BYTES)/1024/1024/1024,2)||'GB' FROM DBA_DATA_FILES;
源环境datafile大小:1.87GB
duplicate开始
在主库上通过rman进行复制备库(注意在这一步之前必须退出备库的所有连接,否则会报错)
rman target sys/oracle auxiliary sys/oracle@LEODBADG
configure device type disk parallelism 10;
rman>duplicate target database for standby nofilenamecheck from active database;
---也可使用下面语句(主库开3个通道,备库开3个通道):
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate AUXILIARY channel c4 type disk;
allocate AUXILIARY channel c5 type disk;
allocate AUXILIARY channel c6 type disk;
duplicate target database for standby nofilenamecheck from active database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
}
备库查询
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
把备库启动到open only下面。并recover
SQL> alter database open read only;
为了方便实时查询,恢复自动恢复状态。
在备库上启动数据库到恢复管理模式,并开始准备从主库接受归档日志的传输。
SQL> alter database recover managed standby database using current logfile disconnect from session;
13.主库执行:
select process,status from v$managed_standby;
查看进程,看有没有LNS进程
SQL> select process,status from v$managed_standby;
在主库进行强制归档
ALTER SYSTEM ARCHIVE LOG CURRENT;
alter system switch logfile;
检查下两边的日志同步情况
select thread#,sequence#,creator,applied,first_time,next_time from v$archived_log where applied='YES' order by sequence#;
这里注意,在备库创建之前的redo归档是不会写过来的。
查看DG是否正常工作
select dest_id,error,status from v$archive_dest where dest_id=2;
SQL> select dest_id,error,status from v$archive_dest where dest_id=2;
DEST_ID ERROR STATUS
---------- ----------------------------------------------------------------- ------------------
2 VALID
error值为空则正常
主库操作
--创建用户
create user dgtest identified by oracle;
grant dba to dgtest;
--创建表
create table dgtest (
id number(9) not null primary key,
classname varchar2(40) not null
);
insert into dgtest values(28,'class one');
commit;
刚才在sys用户下也创建了这个表,可以一起查看
为区分,分别插入两条数据:
sys用户:
insert into dgtest values(27,'sys one');
dgtest用户:
insert into dgtest values(29,'detest one');
在备库执行查询:
select * from sys.dgtest;
select * from dgtest.dgtest;
drop tablespace dfeip including contents and datafiles;
drop user dgtest cascade