电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

DataGuard环境搭建


发布日期:2021/2/18
 

自己做的工作一直涉及的是单实例数据库对容灾也没有特别高的要求平时基本上是靠rman备份或是手工逻辑备份所以一直想做一些关于dataguard的实验去验证一些感觉很棒的操作本文参照了三思的一些文档搭建了一套这样的环境很是兴奋虽然对理论知识不是太理解但是用实践来验证理论会更好的理解吧下面是自己搭建dataguard环境时的一些简要记录

创建主库即在一台物理机上安装数据库软件及创建数据库作为主库并启动到force logging 状态(alter database force logging;)

创建备库在另一台物理机上只安装数据库软件作为备库所有路径与主库一致

在主库上创建备库的控制文件SQL> alter database create standbycontrolfile as d:\backup\controlctl;

关闭主库把主库所有数据文件(如果备库没有相关目录那么连带目录一并)拷贝到备库的相应位置把创建的备库控制文件拷贝到拷贝到相应位置然后复制与主库一样的份数及名称

拷贝主库的密码文件到备库的相应文件中

修改主库的spfile 文件主要是添加下列内容修改的时候创建pfile修改后再创建spfile:

*log_archive_format=%T%S%rARC

*DB_UNIQUE_NAME=primary

*log_archive_config=DG_CONFIG=(primarystandby)

*log_archive_dest_=location=F:\flash_recover_area\ORCL\ARCHIVELOGVALID_FOR=(ALL_LOGFILESALL_ROLES) DB_UNIQUE_NAME=PRIMARY

*log_archive_dest_=SERVICE=standbyarch ASYNC VALID_FOR=(ONLINE_LOGFILESPRIMARY_ROLE) DB_UNIQUE_NAME=standby

*STANDBY_FILE_MANAGEMENT=AUTO

*LOG_ARCHIVE_DEST_STATE_=ENABLE

*LOG_ARCHIVE_DEST_STATE_=ENABLE

*FAL_SERVER=standby

*FAL_CLIENT=primary

修改主库的tns添加下列内容

PRIMARY =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = bcde)(PORT = ))

(CONNECT_DATA =

(SERVICE_NAME = orcl)

STANDBY =

(DESCRIPTION =

(ADDRESS_LIST =

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

(CONNECT_DATA =

(SERVICE_NAME = orcl)

当然备库的spfile也得修改主要添加下列内容

*log_archive_format=%T%S%rARC

*DB_UNIQUE_NAME=standby

*log_archive_config=DG_CONFIG=(primarystandby)

*log_archive_dest_=location=F:\flash_recover_area\ORCL\ARCHIVELOGVALID_FOR=(ALL_LOGFILESALL_ROLES) DB_UNIQUE_NAME=standby

*log_archive_dest_=SERVICE=primaryarch ASYNC VALID_FOR=(ONLINE_LOGFILESPRIMARY_ROLE) DB_UNIQUE_NAME=primary

*STANDBY_FILE_MANAGEMENT=AUTO

*LOG_ARCHIVE_DEST_STATE_=ENABLE

*LOG_ARCHIVE_DEST_STATE_=ENABLE

*FAL_CLIENT=standby

*FAL_SERVER=primary

修改备库的tns添加下列内容

PRIMARY =

(DESCRIPTION =

(ADDRESS_LIST =

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

(CONNECT_DATA =

(SERVICE_NAME = orcl)

STANDBY =

(DESCRIPTION =

(ADDRESS_LIST =

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

(CONNECT_DATA =

(SERVICE_NAME = standby)

由于备库没有实力服务所以在备库中创建实例的服务

用oradim工具创建备库orcl实例 ?

oradimnew sid orcl startmode m ?

oradimedit sid orcl startmode a ?

其实到这里配置基本上就结束了下面就是启动和验证是否可用了

启动及关闭顺序启动时先启动备库再主库关闭时先关闭主库再备库

在备库将实例启动到mount 状态

SQL> startup nomount;

SQL>alter database mount standby database ;

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

SQL>alter database recover managed standby database cancel;

备库启监听

$lsnrctl start

主库启实例

SQL> startup;

主库启监听

$lsnrctl start

在主库验证归档目录是否有效

SQL> SELECT STATUSDESTINATION ERROR FROM V$ARCHIVE_DEST;

如果有错误要排查原因

SQL> alter system switch logfile;

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

主备切换

主库

SQL> select switchover_status fromv$database;

SWITCHOVER_STATUS

TO STANDBY

SQL> alter database commit to switchoverto physical standby with session shutdown ;

数据库已更改

SQL> alter database commit to switchoverto physical standby;

alter database commit to switchover tophysical standby

*

行出现错误

ORA: 未装载数据库

SQL> shutdown immediate;

ORA: 未装载数据库

ORACLE 例程已经关闭

SQL> startup

ORACLE 例程已经启动

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

数据库装载完毕

数据库已经打开

SQL> alter database commit to switchoverto physical standby;

数据库已更改

SQL> select switchover_status fromv$database;

SWITCHOVER_STATUS

TO PRIMARY

SQL> shutdown immediate;

数据库已经关闭

已经卸载数据库

ORACLE 例程已经关闭

SQL> startup nomount;

ORACLE 例程已经启动

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

SQL> alter database mount standbydatabase;

数据库已更改

SQL> alter database recover managedstandby database disconnect from session;

数据库已更改

备库

SQL> select switchover_status fromv$database;

SWITCHOVER_STATUS

SWITCHOVER PENDING

SQL> alter database commit to switchoverto primary;

alter database commit to switchover toprimary

*

ERROR at line :

ORA: media recovery required

开始介质恢复

SQL> alter database recover managedstandby database finish;

Database altered

SQL> alter database commit to switchoverto primary;

Database altered

SQL> shutdown immediate;

ORA: database not open

Database dismounted

ORACLE instance shut down

SQL> startup;

ORACLE instance started

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

Database mounted

Database opened

SQL> alter system switch logfile;

System altered

SQL> select switchover_status fromv$database;

SWITCHOVER_STATUS

TO STANDBY

以下是介质恢复时的alert 日志

alterdatabase commit to switchover to primary

Maximumwait for role transition is minutes

Databasenot available for switchover

EndOfREDO archived log file has beenreceived

EndOfREDO archived log file has not beenrecovered

Archived log files detected beyondEndOfREDO

Incomplete recovery SCN:: archiveSCN::

Databasenot available for switchover

EndOfREDO archived log file has beenreceived

EndOfREDO archived log file has not beenrecovered

Archived log files detected beyondEndOfREDO

Incomplete recovery SCN:: archiveSCN::

Switchover:Media recovery required standby not in limbo

ORAsignalled during: alter database commit to switchover to primary…

WedSep ::

alterdatabase recover managed standby database finish

SerialMedia Recovery started

ManagedStandby Recovery not using Real Time Apply

WARNING!Recovering data file from a fuzzy file If not the current file

itmight be an online backup taken without entering the begin backup command

WARNING!Recovering data file from a fuzzy file If not the current file

itmight be an online backup taken without entering the begin backup command

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

WedSep ::

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

WedSep ::

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

WedSep ::

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

WedSep ::

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC

IdentifiedEndOfRedo for thread sequence

Resettingstandby activation ID xca)

MediaRecovery EndOfRedo indicator encountered

MediaRecovery Applied through change

Completed:alter database recover managed standby database finish

好像是当时主库传过来的归档日志都没有应用另外注意到原始主库发出归档命令时先归档到主库中后归档到备库中切换之后现在的主库发出归档命令后还是先归档到原来的主库(即现在的备库)然后才是自己

上一篇:redhat 7.2下面配置VPN客户端理论联系实际

下一篇:OEM联机自动热备份全攻略(2)