ORACLE9I DATAGUARD部署文档
服务器环境
HOST IP | DB release | SID | DG ROLE |
192.168.32.29 | oracle Enterprise 9.2.0.4.0 | qjhweb | primary |
192.168.32.35 | oracle Enterprise 9.2.0.4.0 | qjhdg | standby |
部署部分
1、在主服务器(192.168.32.29)上安装数据库软件和创建数据库(详细步骤省略)
这里仅将遇到的几个问题列出来:
1.1 开始安装时运行runInstaller的时候报错,报错信息如下:
Error occurred during initialization of VM
Unable to load native library: /tmp/OraInstall2003-10-25_03-14-57PM/jre/lib/i386/libjava.so:
symbol __libc_wait, version GLIBC_2.0 not defined in file libc.so.6 with link time reference
解决方法是打补丁包p3006854_9204_linux.zip
将包解压出来是一个脚本rhel3_pre_install.sh,运行脚本后重新运行runInstaller即可进行安装。
1.2安装完成后dbca和netca不能使用的问题,信息如下:
[oracle@b29 ~]$ dbca
/opt/u01/oracle/jre/1.1.8/bin/../lib/i686/green_threads/libzip.so: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference (libzip.so)
Unable to initialize threads: cannot find class java/lang/Thread
Could not create Java VM
解决方法如下:
[oracle@b29 ~]$ ls $ORACLE_BASE/jre
1.1.8 1.3.1
[oracle@b29 ~]$ cd $ORACLE_HOME
[oracle@b29 9.2.0.4]$ mv JRE JRE.bak
[oracle@b29 9.2.0.4]$ ln -s $ORACLE_BASE/jre/1.3.1 $ORACLE_HOME/JRE
[oracle@b29 9.2.0.4]$ cd /opt/u01/oracle/jre/1.3.1/bin/
[oracle@b29 bin]$ ln -s /opt/u01/oracle/jre/1.3.1/bin/.java_wrapper jre
[oracle@b29 bin]$ cd i386/native_threads/
[oracle@b29 native_threads]$ ln -s java jre
netmgr用不了
vim /opt/u01/oracle/product/9.2.0.4/bin/netmgr
$JRE -classpath .... ===>$JRE -noverify -classpath ...
2、在从服务器(192.168.32.35)上安装数据库软件,不创建数据库(详细步骤省略)
以下在主库上操作
1、确认主库是否设置归档
SQL>Archive log list;
如果没有开启归档,先设置归档,方法如下:
关闭数据库:
SQL>Shutdown immediate;
创建数据库归档目录:
mkdir /opt/u01/oracle/oradata/qjhweb/archivelog
启动数据库到mount 状态:
SQL>Startup mount;
开启归档:
SQL>alter database archive log;
打开数据库:
SQL>alter database open;
2、确定主库是否强制归档,如果不是则修改成强制归档
SQL> select force_logging from v$database;
SQL> alter database force logging;
3、创建主库密码文件
orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=1 force=y
4、调整主库的参数(先创建文本参数文件方便编辑)
SQL> create pfile='/opt/u01/oracle/product/10.2.0/dbs/initqjhweb.ora' from spfile;
vim /opt//u01/oracle/product/10.2.0/dbs/initqjhweb.ora
*.aq_tm_processes=1
*.background_dump_dest='/opt/u01/oracle/admin/qjhweb/bdump'
*.compatible='9.2.0.0.0'
*.control_files='/opt/u01/oracle/oradata/qjhweb/control01.ctl','/opt/u01/oracle/oradata/qjhweb/control02.ctl','/opt/u01/oracl
e/oradata/qjhweb/control03.ctl'
*.core_dump_dest='/opt/u01/oracle/admin/qjhweb/cdump'
*.db_block_size=8192
*.db_cache_size=33554432
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='/opt/u01/oracle/oradata/qjhdg/','/opt/u01/oracle/oradata/qjhweb/'
*.db_name='qjhweb'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=qjhwebXDB)'
*.FAL_CLIENT='qjhweb'
*.FAL_SERVER='qjhdg'
*.fast_start_mttr_target=300
*.hash_join_enabled=TRUE
*.instance_name='qjhweb'
*.java_pool_size=83886080
*.job_queue_processes=10
*.large_pool_size=16777216
*.log_archive_dest_1='LOCATION=/opt/u01/oracle/oradata/qjhweb/archivelog'
*.log_archive_dest_2='SERVICE=qjhdg LGWR'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s.dbf'
*.log_archive_start=true
*.log_file_name_convert='/opt/u01/oracle/oradata/qjhdg/','/opt/u01/oracle/oradata/qjhweb/'
*.open_cursors=300
*.pga_aggregate_target=25165824
*.processes=150
*.query_rewrite_enabled='FALSE'
*.remote_archive_enable='TRUE'
*.remote_login_passwordfile='EXCLUSIVE'
*.shared_pool_size=83886080
*.sort_area_size=524288
*.standby_archive_dest='/opt/u01/oracle/stdarch'
*.standby_file_management='AUTO'
*.star_transformation_enabled='FALSE'
*.timed_statistics=TRUE
*.undo_management='AUTO'
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/opt/u01/oracle/admin/qjhweb/udump'
5、关闭数据库
SQL>Shutdown immediate;
6、删除原来的spfile,生成新的spfile
rm $ORACLE_HOME/dbs/spfileqjhweb.ora
SQL>create spfile from pfile;
7、各种文件的收集,用于建立从库(包括主库的数据文件,参数文件,standby控制文件,密码文件)
收集数据文件(这步可以有多种方法:如冷备份,热备份,以及rman备份)
我们使用冷备份复制所有的数据文件到一个目录 /tmp/oratmp
cp /opt/u01/oracle/oradata/qjhweb/*.dbf /tmp/oratmp
收集参数文件
cp /u01/oracle/product/10.2.0/dbs/initqjhweb.ora /tmp/oratmp/initqjhdg.ora
收集standby控制文件
SQL>Startup mount
SQL>alter database create standby controlfile as ‘/tmp/oratmp/qjhdg01.ctl’
收集密码文件
cp /opt/u01/oracle/product/9.2.0.4/dbs/orapwqjhweb /tmp/oratmp/orapwqjhdg
将以上收集到的文件通过scp传送到从机(standby)下
8、修改主库到从库的网络配置
vim $ORACLE_HOME/network/admin/tnsnames.ora
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
QJHDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.32.35)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = qjhdg)
)
)
配置主库的监听
vim $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = qjhweb)
(ORACLE_HOME = /u01/oracle/product/10.2.0)
(SID_NAME = qjhweb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.32.29)(PORT = 1521))
)
)
9、打开数据库
SQL>startup;
到此,主库上的配置基本完成。
以下在从库上操作。
1、 修改从库参数文件
*.aq_tm_processes=1
*.background_dump_dest='/opt/u01/oracle/admin/qjhdg/bdump'
*.compatible='9.2.0.0.0'
*.control_files='/opt/u01/oracle/oradata/qjhdg/payroll2.ctl'
*.core_dump_dest='/opt/u01/oracle/admin/qjhdg/cdump'
*.db_block_size=8192
*.db_cache_size=33554432
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='/opt/u01/oracle/oradata/qjhweb/','/opt/u01/oracle/oradata/qjhdg/'
*.db_name='qjhweb'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=qjhdgXDB)'
*.FAL_CLIENT='qjhdg'
*.FAL_SERVER='qjhweb'
*.fast_start_mttr_target=300
*.hash_join_enabled=TRUE
*.instance_name='qjhdg'
*.java_pool_size=83886080
*.job_queue_processes=10
*.large_pool_size=16777216
*.lock_name_space='qjhdg'
*.log_archive_dest_1='LOCATION=/opt/u01/oracle/oradata/qjhdg/archivelog'
*.log_archive_dest_2='SERVICE=qjhweb LGWR'
*.log_archive_dest_state_2='enable'
*.log_archive_format='log%d_%t_%s.arc'
*.log_archive_start=true
*.log_file_name_convert='/opt/u01/oracle/oradata/qjhweb/','/opt/u01/oracle/oradata/qjhdg/'
*.open_cursors=300
*.pga_aggregate_target=25165824
*.processes=150
*.query_rewrite_enabled='FALSE'
*.remote_archive_enable='TRUE'
*.remote_login_passwordfile='EXCLUSIVE'
*.shared_pool_size=83886080
*.sort_area_size=524288
*.standby_archive_dest='/opt/u01/oracle/stdarch'
*.standby_file_management='AUTO'
*.star_transformation_enabled='FALSE'
*.timed_statistics=TRUE
*.undo_management='AUTO'
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/opt/u01/oracle/admin/qjhdg/udump'
2、 创建相关目录包括(adump,bdump,cdump,udump),数据文件目录,flash_recovery以及归档目录
mkdir -p /opt/u01/oracle/admin/qjhpdg/{a,b,c,u}dump
mkdir -p /opt/u01/oracle/oradata/qjhdg/
mkdir -p /opt/u01/oracle/flash_recovery_area
mkdir -p /opt//u01/oracle/oradata/qjhdg/archivelog
mkdir -p /opt/u01/oracle/stdarch
3、 将从主库通过scp传送过来的文件集复制到相关的路径下(注意standby controlfile只有一份,要 按照参数文件指定个数进行多路复制)
4、修改从库到主库的网络配置
vim $ORACLE_HOME/network/admin/tnsnames.ora
QJHWEB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.32.29)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = qjhweb)
)
)
5、配置从库的监听
vim $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = qjhdg)
(ORACLE_HOME = /u01/oracle/product/10.2.0)
(SID_NAME= qjhdg)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.32.35)(PORT = 1521))
)
)
6、在从库创建STANDBY LOGFILE
SQL>alter database add standby logfile '/opt/u01/oracle/oradata/qjhdg/standby01.log'
SQL>alter database add standby logfile '/opt/u01/oracle/oradata/qjhdg/standby02.log'
SQL>alter database add standby logfile '/opt/u01/oracle/oradata/qjhdg/standby03.log'
SQL>alter database add standby logfile '/opt/u01/oracle/oradata/qjhdg/standby04.log'
7、将从库置于mount standby database状态(注意这一步,和10G dataguard有不同)
SQL> startup nomount;
SQL> alter database mount standby database;
SQL> alter database recover managed standby database disconnect from session;
到此,从库配置上的配置基本完成
此时,从库将接收从主库传送过来的日志
日志传送和应用测试
测试日志有没有传送和同步
1、主库
SQL>select max(sequence#) from v$archived_log;
SQL>alter system switch logfile;
SQL>select max(sequence#) from v$archived_log;
2、从库
SQL>select max(sequence#) from v$archived_log;
两个库上看到的序列号一致表示日志成功传送;
测试日志是否能应用(测试数据是否一致)
1、主库
在主库上建立一个测试表并插入数据并提交比如:
SQL>conn scott/tigger
SQL>create table test (name varchar2(10),job varchar2(20));
SQL>insert into test values('qiujunhua','dba');
SQL>insert into test values('qjh','plsql developer');
SQL>commit;
SQL>alter system switch logfile;
2、从库
在从库上应用日志
SQL>alter database recover managed standby database disconnect from session;
在open从库之前先停止应用日志
SQL>alter database recover managed standby database cancel;
打开数据库验证数据是否一致
SQL>alter database open read only;
SQL>conn scott/tigger
SQL>select * from test;
若看到的数据和主库一致,说明日志成功应用
3、返回到接收日志状态
从库启动应用日志:(在从库OPEN的状态下直接执行不用先shutdown)
SQL>alter database recover managed standby database disconnect from session;
从库停止应用日志,但是继续接收日志
SQL>alter database recover managed standby database cancel;
执行后从库处于mount状态
切换测试
SWTICHOVER
1、 查看主库状态
SQL> select switchover_status from v$database;
正常状态下为“to standby”
如果为“session active”
使用“alter database commit to switchover to physical standby WITH SESSION SHUTDOWN”语句来关闭活动会话
2、将主库切换为从库
SQL> alter database commit to switchover to physical standby ;
执行之后数据库的状态是nomount
将数据库打开到mount状态
SQL> shutdown immediate
SQL> startup mount;
此时primary库已经切换成standby库了
3、查看从库状态
SQL> select switchover_status from v$database;
正常应该是“TO_PRIMARY”
如果为“SWITCHOVER PENDING” 证明还有日志没有应用
先应用日志
alter database recover managed standby database disconnect from session;
再看从库状态
SQL> select switchover_status from v$database;
应该是“TO_PRIMARY”
4、将从库切换为主库
SQL>alter database commit to switchover to primary;
执行后数据库是nomount状态!
SQL> shutdown immediate;
SQL> startup;
此时standby库已经切换成primary库了
重复日志传送和应用测试步骤来验证是否切换成功
再切换回去测试是否成功
FAILOVER(没有做测试)
1、原则上在主库上不进行操作
因为既然是FAILOVER ,生产情况主库已经崩溃或者无法打开!!!无法执行,这里仅测试。
2、从库取消恢复
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
---force关键字将会停止当前活动RFS进程,以便立即执行failover
3、备库直接切换为主库
SQL>ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
4、启动数据库
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
切换成功后原来主库已经不是dg里的一部分了。
接下来的工作就是将原来的主库恢复数据或者重新改造成dg里的standby库!!!
维护部分
基本维护:
1、 查看主、备库的日志
主库日志位置在$ORACLE_BASE/admin/orcl/bdump/alertorcl[1-2].ora
备库日志位置在$ORACLE_BASE/admin/orcl/bdump/alertorcl.ora
2、查看主库的日志传输情况
SQL>select dest_id,error from v$archive_dest; --如果传送日志有问题,会将问题报错写在error列
3、查看日志应用情况
select dest_id, applied, archived, deleted, status,sequence# from v$archived_log; --日志应用后applied为YES
4、通过第3条中的语句查看应用日志情况,或日志文件中的显示判断是否出现GAP。如果有GAP 产生,可将没有传输到备库的日志手动发送到备库,并执行“alter database register logfile ‘logfile’;”来手动的应用日志。
数据启动和停止相关:
停止
通常是先停主库再停从库
如果要先停从库
应当在主库上执行alter system set log_archive_state_2=DEFER
(暂停日志传送,这样先停止从库时,主库的alert.log里面就不会记录由于日志无法传送产生的错误信息)
启动
1、启动从库的监听再将从库启动到mount状态
2、启动主库的监听再将主库启动到open状态