物理部署dg步骤

主库为 WENDING  

一.	主库

1、	设置为归档模式
SQL>alter database force logging

2、	强制归档

SQL> archive log list
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list

修改监听文件

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/oracle/product/10.2.0/)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (ORACLE_HOME = /u01/oracle/product/10.2.0/)
      (SID_NAME = WENDING)
    )
  )


3、	配置tns文件

WENDING =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = wending)
    )
  )

PHYSTDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = phystdby)
    )
    )
4、	执行rman备份

mkdir –p  /u01/oradata/WENDING/backup
rman nocatalog target sys/oracle@WENDING
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/u01/oradata/WENDING/backup/%F';
CONFIGURE CHANNEL 1 DEVICE TYPE DISK CONNECT 'sys/oracle@WENDING';
CONFIGURE SNAPSHOT CONTROLFILE NAME TO'/u01/oradata/WENDING/backup/snapcf_PRIMARY.f';

BACKUP FORMAT '/u01/oradata/WENDING/backup/%d_D_%T_%u_s%s_p%p' DATABASE;

为standby数据库创建控制文件

BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT '/u01/oradata/WENDING/backup/%d_C_%U';
SQL "ALTER SYSTEM ARCHIVE LOG CURRENT";
BACKUP FILESPERSET 10 ARCHIVELOG ALL FORMAT '/u01/oradata/WENDING/backup/%d_A_%T_%u_s%s_p%p';

5、	修改核心参数

ALTER SYSTEM SET db_unique_name = WENDING SCOPE = SPFILE;
ALTER SYSTEM SET log_archive_dest_1 ='LOCATION=/u01/oradata/WENDING/arch' SCOPE=SPFILE;
ALTER SYSTEM SET log_archive_dest_2 = 'SERVICE=PHYSTDBY VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PHYSTDBY' SCOPE=SPFILE;
ALTER SYSTEM SET fal_client = WENDING SCOPE = SPFILE;
ALTER SYSTEM SET fal_server = PHYSTDBY SCOPE = SPFILE;
ALTER SYSTEM SET standby_file_management = AUTO SCOPE = SPFILE;

6、	重启实例


二.	备库

1、	创建目录
 mkdir -p $ORACLE_BASE/admin/ORCLDB
 mkdir -p $ORACLE_BASE/admin/ORCLDB/adump
 mkdir -p $ORACLE_BASE/admin/ORCLDB/bdump
 mkdir -p $ORACLE_BASE/admin/ORCLDB/cdump
 mkdir -p $ORACLE_BASE/admin/ORCLDB/dpdump
 mkdir -p $ORACLE_BASE/admin/ORCLDB/pfile
 mkdir -p $ORACLE_BASE/admin/ORCLDB/udump
 
  将主库备份的文件复制到 相应的目录
 
 mkdir -p /u01/oradata/WENDING
 mkdir -p /u01/oradata/WENDING/arch
 mkdir -p /u01/oradata/WENDING/backup;


2、	创建主库密码文件
  $ORACLE_HOME/bin/orapwd file=$ORACLE_HOME/dbs/orapwWENDING password=oracle 

3、	将spfile从主库复制到备库
  scp dg1:$ORACLE_HOME/dbs/spfileWENDING.ora dg2:$ORACLE_HOME/dbs

4、	配置tns文件

WENDING =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = wending)
    )
  )

PHYSTDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = phystdby)
    )
    )



5、	修改监听器
SID_LIST_LISTENER_SERVER4 =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = /u01/oracle/product/10.2.0/db_1)
(SID_NAME = WENDING)
)
)

6、	重启监听
lsnrctl reload

重要:网络测试和密码文件测试:
首先要在两台机器上互相tnsping 对方 看看是否能ping通
在WENDING主机上执行:tnsping  PHYSTDBY   显示为OK表示正确
在PHYSTDBY 主机上执行 tnsping  WENDING

第二步 测试密码文件 在主机上 用tns里的名称登陆
sqlplus sys/oracle@PHYSTDBY as sysdba
在备机上测试登陆
sqlplus sys/oracle@WENDING as sysdba

能够互相登陆 则正确!


7、	启数据库为nomount
export ORACLE_SID=WENDING
$ sqlplus / as sysdba
SQL> startup nomount

8、	修改核心参数
ALTER SYSTEM SET db_unique_name = PHYSTDBY SCOPE = SPFILE;
ALTER SYSTEM SET log_archive_dest_1 ='LOCATION=/u01/oradata/WENDING/arch' SCOPE = SPFILE;
ALTER SYSTEM SET log_archive_dest_2 = 'SERVICE=WENDING VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=WENDING' SCOPE=SPFILE;
ALTER SYSTEM SET fal_client = PHYSTDBY SCOPE = SPFILE;
ALTER SYSTEM SET fal_server = WENDING SCOPE = SPFILE;
ALTER SYSTEM SET standby_file_management = AUTO SCOPE = SPFILE;

9、	重启数据库
SQL> startup nomount




在主库
执行rman 连接到备库
SQL> startup mount
$ORACLE_HOME/bin/rman NOCATALOG TARGET / AUXILIARY sys/oracle@"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg2)(PORT=1521))(CONNECT_DATA=(SID=WENDING)))"

注意此时主库必须是关闭状态
RMAN-05001: auxiliary filename 
错误原因,主库和从库目录结构一致,为防止异常覆盖,出以上报错==============
可以用duplicate target database for standby nofilenamecheck;方法解决

克隆数据库到备库
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY DORECOVER nofilenamecheck ;

在备库
重启为nomount
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP NOMOUNT

Mount克隆数据库
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;

启动恢复
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;


切换逻辑dg


关闭恢复
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


在主库
修改logarchive_dest2参数
SQL> ALTER SYSTEM SET log_archive_dest_2 = 'SERVICE=READING VALID_FOR=(ONLINE_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=READING' SCOPE=SPFILE;
执行对象重建
SQL> EXECUTE LOGSTDBY.BUILD;

在备库上:
SQL> ALTER DATABASE RECOVER TO LOGICAL STANDBY standby;
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP
SQL> ALTER DATABASE OPEN RESETLOGS;
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;
上一篇:2021-1-22初学JAVA


下一篇:kubernetes中启动探针startupProbe