ORACLE RAC+DG(单实例)

ORACLE RAC+DG(单实例)
前提条件:
1.主库RAC已经成功安装,数据库也已经创建。
2.DG备库已经安装完相同版本的oracle软件,无需创建数据库。

1、RAC开启归档。
任意节点:

alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
alter system set log_archive_dest_1='LOCATION=+DATA/arch' scope=spfile sid='*';
srvctl stop database -d racdb -o immediate
startup mount
alter database archivelog;
alter database open;
srvctl start database -d racdb

查看每个节点的归档

alter system switch logfile;
archive log list;

每个节点的归档序号是不一样的。

2、启用force logging功能

select force_logging from v$database;
alter database force logging;

3、查询主库日志文件

select thread#,group#,members,bytes/1024/1024 from v$log;
alter database add standby logfile thread 1 group 11 size 50m;
alter database add standby logfile thread 1 group 12 size 50m;
alter database add standby logfile thread 1 group 13 size 50m;
alter database add standby logfile thread 2 group 14 size 50m;
alter database add standby logfile thread 2 group 15 size 50m;
alter database add standby logfile thread 2 group 16 size 50m;

3、配置主库的初始化参数

alter system set db_unique_name='racdb' scope=spfile;
alter system set log_archive_config='DG_CONFIG=(racdb,racdg)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=+data/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=racdb' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=racdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdg' scope=both sid='*';
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
alter system set log_archive_max_processes=8 scope=both sid='*';
alter system set db_file_name_convert='/oradata/racdg/','+DATA/racdb/datafile' scope=spfile sid='*';
alter system set log_file_name_convert='/oradata/racdg/','+DATA/racdb/onlinelog' scope=spfile sid='*';
alter system set standby_file_management=AUTO scope=both sid='*';
alter system set fal_server='rac_dg' scope=both sid='*';

4、查询是否生效:

set linesize 500 pages 0
col value for a90
col name for a50
select name, value from v$parameter where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2','log_archive_dest_state_1','log_archive_dest_state_2','remote_login_passwordfile','log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert', 'log_file_name_convert', 'standby_file_management')

5、配置本地服务名(两个节点保持一致)

cd $ORACLE_HOME/network/admin
vim tnsnames.ora

RACDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = racdb)
    )
  )

RACDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.203)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = racdb)
    )
  )

RACDB2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.204)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = racdb)
    )
  )


RACDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.206)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = racdg)
    )
  )

6、复制密码到DG节点
使用oracle用户

cd $ORACLE_HOME/dbs
scp orapwracdb1 192.168.100.206:/$ORACLE_HOME/dbs/orapwracdg

7、创建初始化文件。
登录dg节点,使用oracle用户

cd $ORACLE_HOME/dbs
vim initracdg.ora
如下:
*.audit_file_dest='/u01/app/oracle/admin/racdg/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/oradata/racdg/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oradata/racdg'
*.db_domain=''
*.db_name='racdb'
*.db_unique_name='racdg'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdgXDB)'
*.fal_client='racdg'
*.fal_server='racdb'
*.log_archive_config='DG_CONFIG=(racdb,racdg)'
*.log_archive_dest_1='LOCATION=/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=racdg'
#*.log_archive_dest_2='SERVICE=racdb LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdb OPTIONAL PROPEN=15 MAX_FAILU
RE=10 NET_TIMEOUT=30'
*.log_archive_dest_2='SERVICE=racdb LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdb'
*.log_archive_dest_state_2='enable'
*.log_file_name_convert='+DATA/racdb/onlinelog','/oradata/racdg'
*.db_file_name_convert='+DATA/racdb/datafile','/oradata/racdg'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=8
*.open_cursors=300
*.pga_aggregate_target=536870912
*.processes=150
*.remote_login_passwordfile='exclusive'
*.standby_file_management='AUTO'
*.sga_target=2147483648
*.undo_tablespace='UNDOTBS1'

8、主库做备份。

rman targer /

执行:

backup database format '/oradata/backup/racdb_%T_%s';
cd /oradata/backup/
scp racdb* 192.168.200.206:/oradata/backup/

9、创建目录

mkdir -p /u01/app/oracle/admin/racdg/adump
mkdir -p /oradata/racdg/
mkdir -p /oradata/arch/

10、创建LISTENER

LISTENER =
   (DESCRIPTION_LIST =
     (DESCRIPTION =
       (ADDRESS = (PROTOCOL = TCP)(HOST = racdg)(PORT = 1521)))
          (DESCRIPTION =
       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
     )
    )
   ADR_BASE_LISTENER = /u01/app/oracle 

11、启动mount

startup mount;
rman恢复数据库
rman target /
catalog start with '/oradata/backup';
run {
allocate channel ch00 type disk;
allocate channel ch01 type disk;
allocate channel ch02 type disk;
allocate channel ch03 type disk;
set newname for datafile 1 to '/oradata/racdg/system.dbf';
set newname for datafile 2 to '/oradata/racdg/sysaux.dbf';
set newname for datafile 3 to '/oradata/racdg/undotbs1.dbf';
set newname for datafile 4 to '/oradata/racdg/users.dbf';
set newname for datafile 5 to '/oradata/racdg/undotbs2.dbf';
set newname for datafile 6 to '/oradata/racdg/test.dbf';
set newname for datafile 7 to '/oradata/racdg/test01.dbf';
restore database;
switch datafile all;
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
 }

12、standby开启实时同步

alter database recover managed standby database using current logfile disconnect from session;
停止同步:
alter database recover managed standby database cancel;

13、 主库查询进程状态(注意LNS进程)

select process, client_process, sequence#,thread#,status from v$managed_standby;
![如下图](https://img-blog.csdnimg.cn/20190702144431875.jpg)

14、备库查询进程状态(注意RFS进程和MRP0进程)

select process, client_process, sequence#,thread#,status from v$managed_standby;
![如下图](https://img-blog.csdnimg.cn/20190702144626345.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIzOTE4Nw==,size_16,color_FFFFFF,t_70)

15、查询日志

select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;

16、主库手动切换日志

alter system switch logfile;

17、查询日志

select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;

18、打开datagaurd模式

 alter database recover managed standby database cancel;
 alter database open read only;
 alter database recover managed standby database using current logfile disconnect from session;

19、查看数据库模式

    主库:
    SQL>  select open_mode,database_role,switchover_status from v$database;
    
    OPEN_MODE	     DATABASE_ROLE    SWITCHOVER_STATUS
    -------------------- ---------------- --------------------
    READ WRITE	     PRIMARY	      SESSIONS ACTIVE
    备库:
    SQL> select open_mode,database_role,switchover_status from v$database;
    
    OPEN_MODE	     DATABASE_ROLE    SWITCHOVER_STATUS
    -------------------- ---------------- --------------------
    READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED

你可能感兴趣的:(ORACLE)