Oracle 11G R2 Data Guard

--------------------------Oracle Data Guard----------------------

环境:

Primary

ech0 192.168.1.100

Standby

ech0192.168.1.101

Syandby节点

――创建相关目录

[oracle@standby ~]$ mkdir -p /oracle/oradata/standby/

[oracle@standby ~]$ mkdir -p /oracle/admin/standby/adump/

[oracle@standby ~]$ mkdir -p /oracle/admin/standby/dpdump/

[oracle@standby ~]$ mkdir -p /oracle/archive/

[oracle@standby ~]$ mkdir -p /oracle/flashback/

Primary节点

[oracle@primary ~]$ sqlplus / as sysdba

――查看数据库为force logging状态

SQL> select force_logging from v$database;

wKiom1LPoD_SgfalAAA00tmRlFo073.jpg

――强制修改数据库为force logging状态

SQL> alter database force logging;

wKioL1LPoN6ReyYJAABhyoZoByg514.jpg

――primary库增加standby redo log

1)查询primary库当前日志组的数量

SQL> select group#,member from v$logfile;

wKiom1LPoPvRmqBwAACbo-2QBNo744.jpg

2)查询primary库当前日志组成员文件大小

SQL> select group#,bytes/1024/1024 from v$log;

wKiom1LPoSSRk4VhAABKarz6hw4900.jpg

3)创建standby redo log

SQL> alter database add standby logfile

group 4 '/oracle/oradata/primary/std_redo04.log' size 50M;

SQL> alter database add standby logfile

group 5 '/oracle/oradata/primary/std_redo05.log' size 50M;

SQL> alter database add standby logfile

group 6 '/oracle/oradata/primary/std_redo06.log' size 50M;

SQL> alter database add standby logfile

group 7 '/oracle/oradata/primary/std_redo07.log' size 50M;

4)查询创建结果

SQL> select group#,member from v$logfile where type='STANDBY';

wKiom1LPoUGzMNH5AADy1XKJ5iw894.jpg

――修改主库参数

1)创建一个pfile文件

SQL> create pfile from spfile;

2)修改pfile初始化参数 [在最下面添加]

[oracle@primary ~]$ vi /oracle/db/dbs/initprimary.ora

db_unique_name=primary

LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'

LOG_ARCHIVE_DEST_1='LOCATION=/oracle/archive/

VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary'

LOG_ARCHIVE_DEST_2='SERVICE=standby LGWR ASYNC

VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'

LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_DEST_STATE_2=ENABLE

REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

FAL_SERVER=standby

FAL_CLIENT=primary

DB_FILE_NAME_CONVERT='/oracle/oradata/standby/','/oracle/oradata/primary/'

LOG_FILE_NAME_CONVERT='/oracle/oradata/standby/','/oracle/oradata/primary/'

STANDBY_FILE_MANAGEMENT=AUTO

――修改监听

[oracle@primary ~]$ cd /oracle/db/network/admin/

[oracle@primary admin]$ vi listener.ora

LISTENER =

 (DESCRIPTION_LIST =

   (DESCRIPTION =

     (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))

   )

 )


SID_LIST_LISTENER =

(SID_LIST =

 (SID_DESC =

 (GLOBAL_DBNAME = primary)

 (SID_NAME = primary)

 )

 (SID_DESC =

 (GLOBAL_DBNAME = standby)

 (SID_NAME = standby)

 )

)

ADR_BASE_LISTENER = /oracle

[oracle@primary admin]$ vi tnsnames.ora

PRIMARY =

 (DESCRIPTION =

   (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))

   (CONNECT_DATA =

     (SERVER = DEDICATED)

     (SERVICE_NAME = primary)

   )

 )

STANDBY =

 (DESCRIPTION =

   (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))

   (CONNECT_DATA =

     (SERVER = DEDICATED)

     (SERVICE_NAME = standby)

   )

 )

――重新启动监听

[oracle@standby ~]$ lsnrctl stop

[oracle@standby ~]$ lsnrctl start

――创建控制文件controlfile

SQL> alter database create standby

controlfile as  '/oracle/oradata/primary/std_control01.ctl';

――关闭数据库

SQL> shutdown immeidate;

――复制数据文件到standby节点

[oracle@primary ~]$ cd /oracle/oradata/primary/

[oracle@primary primary]$ scp *.dbf

[email protected]:/oracle/oradata/standby/

――复制日志文件到standby节点

[oracle@primary primary]$ scp *.log [email protected]:/oracle/oradata/standby/

――复制控制文件到standby节点

[oracle@primary primary]$ scp std_control01.ctl

[email protected]:/oracle/oradata/standby/

――复制初始化文件、密码文件到standby节点

[oracle@primary primary]$ cd /oracle/db/dbs/

[oracle@primary dbs]$ scp initprimary.ora orapwprimary

[email protected]:/oracle/db/dbs/

――复制监听文件到standby节点

[oracle@primary dbs]$ cd ../network/admin/

[oracle@primary admin]$ scp listener.ora tnsnames.ora [email protected]:/oracle/db/network/admin/

――启动primary数据库

SQL> startup pfile='/oracle/db/dbs/initprimary.ora';

wKiom1LPoaeygBB-AAEtRUH-_Rk270.jpg

――创建spfile

SQL> create spfile from pfile;

Standby节点

――修改监听

[oracle@standby ~]$ vi /oracle/db/network/admin/listener.ora

LISTENER =

 (DESCRIPTION_LIST =

   (DESCRIPTION =

     (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))

   )

 )


SID_LIST_LISTENER =

(SID_LIST =

 (SID_DESC =

 (GLOBAL_DBNAME = primary)

 (SID_NAME = primary)

 )

 (SID_DESC =

 (GLOBAL_DBNAME = standby)

 (SID_NAME = standby)

 )

)

ADR_BASE_LISTENER = /oracle

――启动监听

[oracle@standby ~]$ lsnrctl start

――测试监听 [parmarystandby节点都执行]

[oracle@standby ~]$ tnsping standby

wKioL1LPoeixTHCIAAHUvtMLsPU454.jpg

[oracle@standby ~]$ tnsping primary

wKiom1LPogWAR_b8AAHV2z8i1eg181.jpg

――复制控制文件

[oracle@standby dbs]$ cd /oracle/oradata/standby/

[oracle@standby standby]$ cp std_control01.ctl std_control02.ctl

[oracle@standby standby]$ cp std_control01.ctl std_control03.ctl

――编辑初始化文件

[oracle@standby standby]$ cd /oracle/db/dbs/

[oracle@standby dbs]$ mv initprimary.ora initstandby.ora

[oracle@standby dbs]$ mv orapwprimary orapwstandby

[oracle@standby dbs]$ vi initstandby.ora

*.audit_file_dest='/oracle/admin/standby/adump'

*.control_files='/oracle/oradata/standby/std_control01.ctl',

'/oracle/oradata/standby/std_control02.ctl',

'/oracle/oradata/standby/std_control03.ctl'

最下面添加

db_unique_name=standby

LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'

DB_FILE_NAME_CONVERT='/oracle/oradata/primary/','/oracle/oradata/standby/'

LOG_FILE_NAME_CONVERT='/oracle/oradata/primary/','/oracle/oradata/standby/'

LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc

LOG_ARCHIVE_DEST_1='LOCATION=/oracle/archive/

VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=syandby'

LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_DEST_2='SERVICE=primary LGWR ASYNC

VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'

LOG_ARCHIVE_DEST_STATE_2=ENABLE

REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

FAL_SERVER=primary

FAL_CLIENT=standby

STANDBY_FILE_MANAGEMENT=AUTO

――启动standby备库

SQL> startup mount

――启动redo apply

SQL> alter database recover managed standby database disconnect from

session;

――测试1

1)在primary库查看当前最大日志序列号

SQL> select max(sequence#) from v$archived_log;

wKioL1LPoyOiXSXhAABXdUa3zFE012.jpg

2)在primary切换日志

SQL> alter system switch logfile;

3)在primary库再次查看当前最大日志序列号

SQL> select max(sequence#) from v$archived_log;

wKiom1LPo1WwKpytAABtMLIq83g275.jpg

3standby查看是否同步

SQL> select max(sequence#) from v$archived_log;

wKioL1LPotahpmtAAABXdUa3zFE653.jpg

――测试2

1)primary库创建一个表空间、查看syandby库是否同步

SQL> create tablespace test datafile '/oracle/oradata/primary/test01.dbf' size 10M;

2)在primary库检查是否创建成功

SQL> select name from v$datafile;

wKiom1LPpAXzUkCBAAD77cMAsWM719.jpg

3)standby库上检查是否同步 [显示同步失败]

SQL> select name from v$datafile;

wKioL1LPpBvwtCspAAEA5dRWh4w038.jpg

4)在primary库切换日志、促发日志传输

SQL> alter system switch logfile;

5)standby库再次检查是否同步

SQL> select name from v$datafile;

wKioL1LPpFyh3DHgAAFpttlSrts114.jpg

――物理standbyswitchover

1)primary库查看是否支持switchover[TO STANDBY为支持]

SQL> select database_role,switchover_status from v$database;

wKioL1LPpJqAgewuAACxqLqAAq4744.jpg

2)切换primary库为standby

SQL> alter database commit to switchover to physical standby withsession shutdown;

3)重新启动primary库为mount状态

SQL> shutdown immediate

SQL> startup mount

4启动redo apply

SQL>alter database recover managed standby database disconnect from session;

5standby库查看是否支持switchover[TO PRIMARY为支持]

SQL> select database_role,switchover_status from v$database;

wKiom1LPpNbzED_JAACzh9EnTqs468.jpg

6)切换standby库为primary

SQL> alter database commit to switchover to primary;

7)打开新的primary

SQL> alter database open;

8)查看是否切换成功

SQL> select database_role,switchover_status from v$database;

wKioL1LPpOvz0ErxAAC8_dQ8Tc8334.jpg

9检查是否同步

-在新的primary看当前最大日志序列号

SQL> select max(sequence#) from v$archived_log;

wKioL1LPpRvBEpKFAABYFOFebF0400.jpg

-在新standby库查看是否同步

SQL> select max(sequence#) from v$archived_log;

wKiom1LPpVrjJ7xHAABV41R-U3k211.jpg


你可能感兴趣的:(oracle,Data,guard)