环境
os:linux
oracle:oraclei
primary:
standby: (主副主机都是两台普通的pc主机)
第一部分oraclei 在linux上的安装
本来我不想写这方面的东东但是对比oracli在solaris 下和在linux下安装oraclei 在linux上的安装真的是要麻烦很多下面我把我遇到的问题(好像也是大部分oracle初学者安装时遇到的问题)简要的说一下oraclei 在linux上的安装也折腾了我好几个月
)运行runinstaller的时候报错
bashb$ /runInstaller
bashb$ Initializing Java Virtual Machine from /tmp/OraInstall_PM/jre/bin/java Please wait
/tmp/OraInstall_PM/jre/bin/i/native_threads/java: error while loading shared libraries: libstdc++libcso: cannot open shared object file: No such file or directory
Oracle Net configuration Assistant
Oracle Database configuration Assistant
Agent configuration Assistant
三个工具的details错误信息都是
/home/oracle/jre//bin/lib/i/native_threads/libzipso :symbol errnoversion GLIBC_ not definded in file libcso with link time reference(libzipso)
unable to initialize threads: cannot find class java/lang/Thread
Could not create java VM
解决方法在运行runInstaller之前做下面的步骤
export LD_ASSUME_KERNEL=
ignore your kernal version
下载文件libcwaitc ftp:///drepper/libcwaitc(通过IE无法下载的话就用命令行)用gcc shared o libcwaitso fpic O libcwaitc进行编译然后export LD_PRELOAD=/$path/libcwaitso
上面的方法能使Oracle Net configuration AssistantOracle Database configuration Assistant 安装成功
修复Agent configuration Assistant不能配置成功的方法请参考chinaunix上的
在RHAS上成功安装Oracle作者:renxiao
运行runInstaller之后出现安装组件的选择结果这时点Install开始安装复制文件进度条在一点一点的增加当安装并link完后出现配置工具界面agent服务不能配置成功忽略不用管在下面修复DBCANETCAHTTP都正确配置完毕哦呵呵下面开始修复错误其实要是把各个界面抓取下来就更好了
安装p__LINUXzip补丁
此补丁也是从下下载同时要下载一个opatch软件包p__GENERICzip它主要是用来悠agent服务不能启动的错误
过程如下[quote:fa]su oracle
$ cp p__GENERICzip /tmp
$ cd /tmp
$ unzip p__GENERICzip
$ export PATH=$PATH:/tmp/OPatch
$ export PATH=$PATH:/sbin # the patch needs fuser which is located in /sbin
$ unzip p__LINUXzip
$ cd
$ opatch apply
[/quote:fa]补丁修复完成需要relinked一个mk文件
$ cd $ORACLE_HOME/network/lib
$ make f ins_oemagentmk install
现在在运行agentctl start看是不是可以成功运行agent服务了啊可以用stopstatus来停止此服务或者检查服务的状态
在这个成功之后居然不能启动Oracle说是不能找到初始化文件没办法我用dbca先删除了原来安装时建立的库再重新建立了数据库
运行dbca来创建数据库呵呵一路畅通完成数据库的安装
希望你也能成功安装
运行runInstaller后安装界面出来出现乱码
export LANG=en_us 再运行runInstaller (这是最简单实用的办法)
报/etc/oratab 错误
如果在机器上以前安装过再一次安装的时候如果报/etc/oratab 错误请将/etc/oratab 清空(删除也可)
cp /dev/null/etc/oratab
()然后开始建库当建库到%时会出现共享内存问题
ORA: unable to attach to shared memory segment
这时需要给内核指定内存可以
echo >/proc/sys/kernel/shmmax
或者
编辑/etc/nf
kernelshmmax=
这样就可以数据库的安装
运行要启动oracle要先运行数据库监听程序lsnrctlstart 关闭lsnrctl stop
运行oemapp console可以打开oracle企业管理器工具
还有一些错误可能需要修改/etc/hosts/etc/nf请大家在google上搜一下按照网友提示的方法进行修改
另外主副主机的目录设置成一样都将oracle用户主目录设为/home/oracle主副主机的数据库名字都设为oracle实例名也都设为一样都设为oracle(申明一点是否必须将主副主机的数据库名字实例名都设为相同我曾在cu上发过贴子问过好像大家都说不需要但我们这的dba说是必须反正我在这里设的是相同
第二步Dataguard配置
首先将主副两主机都设为归档模式
主节点备份并生成备用数据库控制文件
登陆主节点进行数据库备份并生成备用数据库控制文件
[oracle@primary]$ sqlplus / as sysdba
SQL> startup
SQL> shutdown immediate
SQL> exit
[oracle@primary]pwd
/home/oracle
[oracle@primary]$ ls
admindictionaryorajreoradataoraInventoryouiproductsoft
[oracle@primary]tar cvf oradatatar oradata
[oracle@primary]$ ls l *tar
rwrr oracle dba Aug : oradatatar
[oracle@primary]$ sqlplus / as sysdba
SQL> startup
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/oradata/primary/archive
Oldest online log sequence
Next log sequence to archive
Current log sequence
SQL> alter database create standby controlfile as /home/oracle/standbyctl;
Database altered
SQL> exit
[oracle@primary]
登陆备用节点(standby)ftp获得primary主机的数据库文件(即oradatatar文件)备用控制文件(/home/oracle/standbyctl) 口令文件( $ORACLE_HOME/dbs/下的orapworacle)传到standby里的相应位置
具体步骤
在standby的/home/oracle/oradata下原来有一个oracle的文件夹(里面是该主机下的dbfredolog文件)再新建一个primary文件夹将primary主机的oradatatar解开的文件全部直接(即primary不要再有文件夹)放到primary下将刚生成的备用控制文件(/home/oracle/standbyctl)也放到primary下
在standby的ORACLE_HOME/dbs/下先将以前的orapworacle备份一下(改个名字即可)再将primary的$ORACLE_HOME/dbs/下的orapworacle 文件ftp放到standby的ORACLE_HOME/dbs/下
说明一下我在查阅eygle的大作及很多人的相关文章都没有提到这一点但如果没做这一步的话再后面的启动备用数据库的时候即在
[oracle@eygle primary]$ sqlplus / as sysdba
SQL> startup nomount;
SQL> alter database mount standby database;
SQL> alter database recover managed standby database disconnect from session;
这一步时就会报ORA 错误说是Invalid passwd file询问我们的dba说是必须要用primary的orapworacle来替换standby的 我试过这样做了后就OK了
所以我这在这里就把primary的orapworacle来替换standby的orapworacl也当作一步必须步骤但我真的不能肯定这一步是否是必须的如果不是必须的为何我做这一步总会报错如果是必须的为何eygle和其他大牛的大作里都没有提到这一步难道是因为这个太简单吗?? 我真的是有些疑惑如果哪位大牛看到这请给我一个肯定的回答我不胜感激
在standby主机的$oracle/home/admin下原来有oracle目录现在新建
primary目录再在primary目录下新建bdumpcdumpudump
Primary的参数文件
oracle@primary_andy $catbash_profile
# bash_profile
# Get the aliases and functions
#if [ f ~/bashrc ]; then
# ~/bashrc
#fi
# User specific environment and startup programs
#export BASH_ENV=$HOME/bashrc
PATH=$PATH:/home/oracle/product//bin:$oracle_home/jre/bin:/opt/SUNWspro/
bin:/usr/bin:/usr/ccs/bin:/usr/ucb:/etc:/usr/local/bin:/usr/bin/saved:
export PATH
unset USERNAME
ORACLE_OWNER=oracle
ORACLE_BASE=/home/oracle
export ORACLE_BASE
ORACLE_HOME=/home/oracle/product/
export ORACLE_HOME
LANG=
LC_ALL=
ORACLE_SID=oracle
export ORACLE_SID
TNS_ADMIN=/home; export TNS_ADMIN
NLS_LANG=american_americaZHSGBK; export NLS_LANG
#ORA_NLS=$Oracle_HOME/ocommon/nls/admin/data; export ORA_NLS
CLASSPATH=$Oracle_HOME/JRE:$Oracle_HOME/jlib:$Oracle_HOME/rdbms/jlib:/opt/jsdk_nb/jsdk/bin
export CLASSPATH
TMPDIR=/tmp;export TMPDIR
umask
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/lib/tls:/lib/i:/usr/openwin/lib:/usr/dt/lib
export LD_LIBRARY_PATH
export LD_PRELOAD=/home/oracle/libcwaitso;
export LD_ASSUME_KERNEL=;
DISPLAY=:;export DISPLAY;
export PS=\u@\H $
#cat initoracleora_primary
*aq_tm_processes=
*background_dump_dest=/home/oracle/admin/oracle/bdump
patible=
ntrol_files=/home/oracle/oradata/oracle/controlctl/home/oracle/oradata/oracle/c
ontrolctl/home/oracle/oradata/oracle/controlctl
re_dump_dest=/home/oracle/admin/oracle/cdump
*db_block_size=
*db_cache_size=
*db_domain=
*db_file_multiblock_read_count=
*db_name=oracle
*dispatchers=(PROTOCOL=TCP) (SERVICE=oracleXDB)
*fast_start_mttr_target=
*hash_join_enabled=TRUE
*instance_name=oracle
*java_pool_size=
*job_queue_processes=
*large_pool_size=
*log_archive_dest_=LOCATION=/home/oracle/oradata/archivelog/
*log_archive_dest_=service=standby mandatory reopen=
*log_archive_dest_state_=ENABLE
*log_archive_format=log_%t_%sarc
*log_archive_start=TRUE
*open_cursors=
*pga_aggregate_target=
*processes=
*query_rewrite_enabled=FALSE
*remote_login_passwordfile=EXCLUSIVE
*shared_pool_size=
*sort_area_size=
*star_transformation_enabled=FALSE
*timed_statistics=TRUE
*undo_management=AUTO
*undo_retention=
*undo_tablespace=UNDOTBS
*user_dump_dest=/home/oracle/admin/oracle/udump
修改standby主机的initoracleora文件(先备份)我的initoracleora如下供参考
*aq_tm_processes=
*background_dump_dest=/home/oracle/admin/primary/bdump
patible=
ntrol_files=/home/oracle/oradata/primary/standbyctl
re_dump_dest=/home/oracle/admin/primary/cdump
*db_block_size=
*db_cache_size=
*db_domain=
*db_file_multiblock_read_count=
*db_name=oracle
*dispatchers=(PROTOCOL=TCP) (SERVICE=oracleXDB)
*fast_start_mttr_target=
*hash_join_enabled=TRUE
*instance_name=oracle
*java_pool_size=
*job_queue_processes=
*large_pool_size=
*open_cursors=
*pga_aggregate_target=
*processes=
*query_rewrite_enabled=FALSE
*remote_login_passwordfile=EXCLUSIVE
*shared_pool_size=
*sort_area_size=
*star_transformation_enabled=FALSE
*timed_statistics=TRUE
*undo_management=AUTO
*undo_retention=
*undo_tablespace=UNDOTBS
*user_dump_dest=/home/oracle/admin/primary/udump
*log_archive_format=log_%t_%sarc
*log_archive_start=TRUE
*STANDBY_FILE_MANAGEMENT=AUTO
*log_archive_dest_=LOCATION=/home/oracle/oradata/archivelog/
*log_archive_dest_state_ = ENABLE
*fal_server=primary
*fal_client=standby
*DB_FILE_NAME_CONVERT=(/home/oracle/oradata/oracle/home/oracle/oradata/primary) (主辅数据库数据文件相互转换的目录)
*STANDBY_FILE_MANAGEMENT=AUTO即可实现重命名主库的数据文件!!
*LOG_FILE_NAME_CONVERT=(/home/oracle/oradata/archivelog/home/oracle/oradata/archivelog) (主辅数据库联机日志redolog相互转换的目录)
*STANDBY_ARCHIVE_DEST=/home/oracle/oradata/archivelog
(从主数据库产生的archivelog传到辅数据库的目录)
配置主节点(primary主机上)的tnsnamesora文件
primary=(description=
(address=
(protocol=tcp)
(port=)
(host=))
(connect_data=
(SID=oracle)))
standby=(description=
(address=
(protocol=tcp)
(port=)
(host=))
(connect_data=
(SID=oracle)))
同样在副节点(standby) 的tnsnamesora文件
在副节点(standby)上配置listenerora文件 添加监听服务standby_listener在相应的节里添加有关的内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = oracle)
(GLOBAL_DBNAME = oracle)
(ORACLE_HOME = /home/oracle/oradata)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = ))
)
)
在主副库上启动lsnrctl
bashb$ lsnrctl
LSNRCTL>start # 启动监听服务
在主备节点用tnsping测试网络连通性
在primary机上
bashb$tnspingprimary
bashb$tnspingstandby
在standby机上
bashb$tnspingprimary
bashb$tnspingstandby
启动副数据库
sql> startup nomount;
SQL> alter database mount standby database;
Database altered
SQL> alter database recover managed standby database disconnect from session;
Database altered
在主节点设置归档路径
SQL> alter system set log_archive_dest_=service=standby mandatory reopen=;
System altered
定义了主库向副库传输日志
# 定义归档到备用库强制归档重试时间秒
# 如果定义为可选状态(optional)那么在归档失败后不会再次尝试归档的定义
# 为madatory状态后如果本次归档失败则在归档下一个日志时会再次尝试
SQL> alter system switch logfile;
System altered
SQL> /
System altered
SQL>
在备用节点观察日志
[oracle@eygle bdump]$ tail f alert_primarylog
MRP: Background Managed Standby Recovery process started
Starting datafile recovery in thread sequence
Datafile : /opt/oracle/oradata/primary/systemdbf
Starting datafile recovery in thread sequence
Datafile : /opt/oracle/oradata/primary/undotbsdbf
…………………………
bashb$ mkdir /home/oracle/oradata/oracle/stdarch
主辅数据库的切换(停止主数据库启用备用数据库)
修改primary的参数文件initoracleora(先做好备份)
增加
*standby_archive_dest=/home/oracle/oradata/standbyarch
*fal_server=standby
*fal_client=primary
*DB_FILE_NAME_CONVERT=(/home/oracle/oradata/primary/home/oracle/oradata/oracle)
*LOG_FILE_NAME_CONVERT=(/home/oracle/oradata/archivelog/home/oracle/oradata/archivelog)
*STANDBY_FILE_MANAGEMENT=AUTO
删除log_archive_dest_参数
修改standby的参数文件initoracleora(先做好备份)
增加
*log_archive_dest_=service=primary mandatory reopen=
*log_archive_dest_state_=ENABLE
删除
*STANDBY_ARCHIVE_DEST=/home/oracle/oradata/archivelog
*fal_server=standby
*fal_client=primary
*DB_FILE_NAME_CONVERT=(/home/oracle/oradata/primary/home/oracle/oradata/oracle)
*LOG_FILE_NAME_CONVERT=(/home/oracle/oradata/archivelog/home/oracle/oradata/archivelog)
*STANDBY_FILE_MANAGEMENT=AUTO
在primary主机上执行
SQL> alter database commit to switchover to physical standby with session shutdown ;
Database altered
察看primary主机上的后台日志
……………………………
SQL> shutdown immediate
ORA: database not mounted
ORACLE instance shut down
以备用模式(standby)启用主数据
SQL> create spfile from pfile;
SQL> startup nomount;
SQL>show parameter standby_file_management;
SQL> alter database mount standby database;
Database altered
打开备用数据库(在standby主机上执行)
[oracle@standby oracle]$ sqlplus / as sysdba
SQL> alter database commit to switchover to primary with session shutdown ;
Database altered
SQL> shutdown immediate;
ORA: database not mounted
ORACLE instance shut down
SQL>create spfile from pfile;
SQL> startup;
……
Database mounted
Database opened
SQL> select SEQUENCE#GROUP#STATUS from v$log;
SQL> select sequence#group#status from v$log;
SEQUENCE# GROUP# STATUS
INACTIVE
INACTIVE
CURRENT
SQL> alter system switch logfile;
System altered
SQL> select sequence#group#status from v$log;
SEQUENCE# GROUP# STATUS
CURRENT
INACTIVE
ACTIVE
在primary主机上执行
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered
在primary主机上观察日志应用情况
[oracle@primary bdump]$ tail f alert_oraclelog
Starting datafile recovery in thread sequence
Datafile : /opt/oracle/oradata/primary/undotbsdbf
Starting datafile recovery in thread sequence
Datafile : /opt/oracle/oradata/primary/usersdbf
………………………………………………
Media recover
现在可做一个测试在standby主机上进行数据修改(standby主机现在做primary)
SQL> create table t as select * from dba_users;
Table created
SQL> alter system switch logfile;
System altered
在从库上(primary主机上)以read only打开数据库执行查询
SQL> select username from t;
select username from t
*
ERROR at line :
ORA: database not open: queries allowed on fixed tables/views only
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Database altered
SQL> ALTER DATABASE OPEN READ ONLY;
Database altered
SQL> select username from t;
USERNAME
SYS
SYSTEM
DBSNMP
OUTLN
WMSYS
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered
常见问题
至此主副的配置已基本完成可做以下实验来验证配置的准确性
. 在主库上新建一个表看修改时候能马上传到副库上
. 在主库上新建一个表空间新增加一个datafile看修改时候能马上传到副库上(应该是只要在副库上执行恢复模式就能在副库上看到新建的表空间
. 在主库上新建一个临时表空间rename datafile 均不能应用到副库上
. 应当实时察看standby库的alert文件就能清晰明了地知道主副更新的情况
. 关于启动关闭顺序
启动的时候先从库的listener再启动从库再启动主库的listener再主库
关闭的时候先关闭主库再启动从库
i副数据库切换为主的话将无法再切为副主数据库也是! 也就是说只能完成一次切换这叫failover!i可实现主副数据库任意切换这叫switchover
第六点我理解得有些问题看了版主Rollingpig在itpub上的结论觉得他说的应该是对的现将他的陈述列在下面!
Rollingpig
我给个结论吧在i 的dataguad环境中
Switch Over 必须是Primary 正常并且是必须Primary 主动先Switch 成 standby 然后standby 才能switch 成primary
如果需要作成primary出问题standby 能接管的话必须作 failover 而不是Switch Over
察看主机当前的运行状态
SQL> select nameopen_modePROTECTION_MODEDATABASE_ROLE from v$database;
NAME OPEN_MODEPROTECTION_MODE DATABASE_ROLE
PRIMARY MOUNTED MAXIMUM PERFORMANCEPHYSICAL STANDBY
查看主数据库日志是否全部传送到副数据库可查看v$archive_gap更简单的方法是查看各自主机的日志归档目录的日志序号即可
. 常用的一些方法
可在副数据库上运行一些脚本确保主数据库上的更新能及时在副数据库上得到实现可将以下脚本放在crontab表中
oracle@standby $cat refresh (刷新脚本)
ORACLE_SID=oracle
ORACLE_HOME=/home/oracle/product/
export ORACLE_SID ORACLE_HOME
DATE=`date +%Y%m%d`
touch /home/oracle/refresh_$DATElog
$ORACLE_HOME/bin/sqlplus /nolog << EOF
spool /home/oracle/refresh_$DATElog
connect sys/abc as sysdba
shutdown immediate;
quit
EOF
$ORACLE_HOME/bin/sqlplus /nolog << EOF
spool /home/oracle/refresh__$DATElog
connect sys/abcas sysdba
startup nomount pfile=$ORACLE_HOME/dbs/initoracleora;
alter database mount standby database;
alter database set standby database to maximize performance;
alter database recover managed standby database disconnect from session;
spool off
EOF
oracle@standby $cat readonly (更新脚本)
#!/bin/sh
ORACLE_SID=oracle
ORACLE_HOME=/home/oracle/product/
export ORACLE_SID ORACLE_HOME
$ORACLE_HOME/bin/sqlplus /nolog << EOF
spool /home/oracle/refreshreadlog
connect sys/abc as sysdba
rem change from recover mode to readonly
alter database recover managed standby database cancel;
alter database open read only ;
spool off
EOF
switchover过程
把数据库切换回到主节点
先将standby此时的initoracleora恢复为以前是standby时的参数
在主节点(standby主机上)
SQL> alter database commit to switchover to physical standby;
Database altered
SQL> shutdown immediate
ORA: database not mounted
statORACLE instance shut down
SQL> startup nomountpfile=/home/oracle/product//dbs/initoracleora;
;
ORACLE instance started
Total System Global Area bytes
Fixed Size bytes
Variable Size bytes
Database Buffers bytes
Redo Buffers bytes
SQL> alter database mount standby database;
Database altered
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered
在备用节点(在primary主机上)
先将primary此时的initoracleora恢复为以前是primary时的参数
SQL> alter database commit to switchover to primary;
Database altered
SQL> shutdown immediate;
ORA: database not mounted
ORACLE instance shut down
SQL> startuppfile=/home/oracle/product//dbs/initoracleora;
ORACLE instance started
Total System Global Area bytes
Fixed Size bytes
Variable Size bytes
Database Buffers bytes
Redo Buffers bytes
Database mounted
Database opened
衷心致谢: CU oracle斑竹 sshd 我在配置dataguard时得到他的很多帮助!!
参考文献
Dataguard配置Step by step (eygle大作)