環境:
os: Linux 9
oracle: Oracle9i
primary: 1.1.1.1
standby: 1.1.1.2 (主副主機都是兩台普通的pc主機)
第一部分 Oracle9i 在Linux9上的安裝
本來我不想寫這方面的東東,但是對比oracl9i在solaris下和在linux下安裝,oracle9i 在Linux9上的安裝真的是要麻煩很多,下面我把我遇到的問題(好像也是大部分oracle初學者安裝時遇到的題)簡要的說一下,Oracle9i 在Linux9上的安裝也折騰了我好幾個月,沒辦法,我太笨了。
1)運行runinstaller的時候報錯。
-bash-2.05b$ ./runInstaller -bash-2.05b$ Initializing Java Virtual Machine from /tmp/OraInstall2005-01-20_06-39-06PM/jre/bin/java. Please wait... /tmp/OraInstall2005-01-20_06-39-06PM/jre/bin/i386/ native_threads/Java: error while loading shared librarIEs: libstdc++-libc6.1-1.so.2: 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/1.1.8/binhttp://www.zhujiangroad.com/lib/i686/
native_threads/libzip.so :symbol errno,
version GLIBC_2.0 not definded 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
解決方法:
在運行runInstaller之前做下面的步驟。
export LD_ASSUME_KERNEL=2.4.19
ignore your kernal version
下載文件libcwait.c
FTP://people.redhat.com/drepper/libcwait.c
(通過IE無法下載的話,就用命令行)
用gcc -shared -o libcwait.so -fpic -O2 libcwait.c
進行編譯然後export LD_PRELOAD=/$path/libcwait.so
上面的方法能使Oracle Net configuration Assistant ,
Oracle Database configuration Assistant 安裝成功。
修復Agent configuration Assistant不能配置成功的方法:請參考chinaunix上的《在RHAS3上成功安裝Oracle9204》。
運行runInstaller之後,出現安裝組件的選擇結果,這時點“Install”,開始安裝,復制文件,進度條在一點一點的增加,當安裝並link 完後,出現配置工具界面,agent服務不能配置成功,忽略不用管,在下面修復。DBCA,NETCA,HTTP都正確配置完畢哦。
呵呵。下面開始修復錯誤。其實要是把各個界面抓取下來就更好了。
6、安裝p3238244_9204_Linux.zip補丁
此補丁也是從http://metalink.Oracle.com下下載,同時要下載一個opatch軟件包:p2617419_220_GENERIC.zip,它主要是用來悠agent服務不能啟動的錯誤。
過程如下:
[quote:864939f94a]su - oracle $ cp p2617419_210_GENERIC.zip /tmp $ cd /tmp $ unzip p2617419_210_GENERIC.zip $ export PATH=$PATH:/tmp/OPatch $ export PATH=$PATH:/sbin # the patch needs "fuser" which is located in /sbin $ unzip p3238244_9204_Linux.zip $ cd 3238244 $ opatch apply :864939f94a]補丁修復完成,需要relinked一個.mk文件。 $ cd $Oracle_HOME/network/lib $ make -f ins_oemagent.mk install
現在在運行agentctl start,看是不是可以成功運行agent服務了啊,可以用stop、status來停止此服務或者檢查服務的狀態。
在這個成功之後,居然不能啟動Oracle,說是不能找到初始化文件,沒辦法,我用dbca先刪除了原來安裝時建立的庫,再重新建立了數據庫。
7、運行dbca來創建數據庫。呵呵,一路暢通,完成數據庫的安裝。
希望你也能成功安裝。
申明一點,我在9i沒配置好Agent configuration Assistant,應該在Linux9i環境裡按照上面的步驟也能配置好。
運行runInstaller後,安裝界面出來出現亂碼
export LANG=en_us 再運行runInstaller (這是最簡單實用的辦法)
報/etc/oratab 錯誤
如果在機器上以前安裝過,再一次安裝的時候如果報/etc/oratab 錯誤。請將/etc/oratab 清空(刪除也可)
cp /dev/null /etc/oratab
(4)然後開始建庫,當建庫到46%時會出現共享內存問題,
ORA-27123: unable to attach to shared memory segment
這時需要給內核指定內存,可以:
echo 4294967295 >/proc/sys/kernel/shmmax
或者編輯/etc/sysctl.conf
kernel.shmmax=4294967295
這樣就可以數據庫的安裝。
運行:要啟動Oracle要先運行數據庫監聽程序:lsnrctl start 關閉:lsnrctl stop
運行oemapp console可以打開Oracle企業管理器工具,還有一些錯誤,可能需要修改/etc/hosts,/etc/sysctl.conf,請大家在google上搜一下按照網友提示的方法進行修改。
另外主副主機的目錄設置成一樣。都將oracle用戶主目錄設為/home/oracle.主副主機的數據庫名字都設為oracle,實例名也都設為一樣,都設為Oracle(申明一點,是否必須將主副主機的數據庫名字實例名都設為相同,我曾在cu上發過貼子問過,好像大家都說不需要,但我們這的dba說是必須,反正我在這裡設的是相同。
第二步:Dataguard配置
首先將主副兩主機都設為歸檔模式。
1. 主節點備份並生成備用數據庫控制文件
登陸主節點,進行數據庫備份,並生成備用數據庫控制文件
[oracle@primary]$ sqlplus "/ as sysdba" SQL> startup SQL> shutdown immediate SQL> exit [oracle@primary]pwd /home/oracle [oracle@primary]$ ls admin dictionary.ora jre oradata oraInventory oui product soft [oracle@primary]tar -cvf oradata.tar oradata [oracle@primary]$ ls -l *.tar -rw-r--r-- 1 oracle dba 576512000 Aug 16 10:22 oradata.tar [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 88 Next log sequence to archive 90 Current log sequence 90 SQL> alter database create standby controlfile as '/home/oracle/standby.ctl'; Database altered. SQL> exit [Oracle@primary]
3. 登陸備用節點(standby),FTP獲得primary主機的數據庫文件(即oradata.tar文件)、備用控制文件(/home/oracle/standby.ctl) ,口令文件( $ORACLE_HOME/dbs/下的orapwOracle)傳到standby裡的相應位置。
具體步驟:
3.1 在standby的/home/oracle/oradata下,原來有一個oracle的文件夾(裡面是該主機下的dbf,redolog文件),再新建一個primary文件夾。將primary主機的oradata.tar解開的文件全部直接(即primary不要再有文件夾)放到primary下,將剛生成的備用控制文件(/home/Oracle/standby.ctl)也放到primary下。
3.2 在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-01991 錯誤,說是Invalid passwd file.詢問我們的dba,說是必須要用primary的orapwOracle來替換standby的. 我試過,這樣做了後就OK了。
所以我這在這裡就把primary的orapwOracle來替換standby的orapworacl也當作一步必須步驟,但我真的不能肯定這一步是否是必須的,如果不是必須的,為何我做這一步,總會報錯。如果是必須的,為何eygle和其他大牛的大作裡都沒有提到這一步,難道是因為這個太簡單嗎?? 我真的是有些疑惑。如果哪位大牛看到這,請給我一個肯定的回答,我不勝感激。
在standby主機的$oracle/home/admin下原來有Oracle目錄。現在新建primary目錄,再在primary目錄下新建bdump,cdump,udump.
Primary的參數文件
oracle@primary_andy $cat .bash_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/9.2.0 /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/9.2.0 export ORACLE_HOME LANG= LC_ALL= ORACLE_SID=oracle export ORACLE_SID TNS_ADMIN=/home/Oracle/config/9.2.0; export TNS_ADMIN NLS_LANG=american_america.ZHS16GBK; export NLS_LANG #ORA_NLS33=$Oracle_HOME/ocommon/nls/admin/data; export ORA_NLS33 CLASSPATH=$Oracle_HOME/JRE:$Oracle_HOME/jlib:$Oracle_HOME/rdbms/ jlib:/opt/j2sdk_nb/j2sdk1.4.2/bin export CLASSPATH TMPDIR=/tmp;export TMPDIR umask 022 LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/lib/tls:/lib/i686:/usr/openwin/ lib:/usr/dt/lib export LD_LIBRARY_PATH export LD_PRELOAD=/home/oracle/libcwait.so; export LD_ASSUME_KERNEL=2.4.19; DISPLAY=1.1.1.3:0.0;export DISPLAY; export PS1="\u@\H $" #cat initoracle.ora_primary *.aq_tm_processes=1 *.background_dump_dest='/home/oracle/admin/oracle/bdump' *.compatible='9.2.0.0.0' *.control_files='/home/oracle/oradata/oracle/control01.ctl','/home/ oracle/oradata/oracle/c ontrol02.ctl','/home/oracle/oradata/oracle/control03.ctl' *.core_dump_dest='/home/oracle/admin/oracle/cdump' *.db_block_size=8192 *.db_cache_size=33554432 *.db_domain='' *.db_file_multiblock_read_count=16 *.db_name='oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=oracleXDB)' *.fast_start_mttr_target=300 *.hash_join_enabled=TRUE *.instance_name='Oracle' *.Java_pool_size=83886080 *.job_queue_processes=10 *.large_pool_size=16777216 *.log_archive_dest_1='LOCATION=/home/oracle/oradata/archivelog/' *.log_archive_dest_2='service=standby mandatory reopen=60' *.log_archive_dest_state_1='ENABLE' *.log_archive_format='log_%t_%s.arc' *.log_archive_start=TRUE *.open_cursors=300 *.pga_aggregate_target=25165824 *.processes=150 *.query_rewrite_enabled='FALSE' *.remote_login_passWordfile='EXCLUSIVE' *.shared_pool_size=83886080 *.sort_area_size=524288 *.star_transformation_enabled='FALSE' *.timed_statistics=TRUE *.undo_management='AUTO' *.undo_retention=10800 *.undo_tablespace='UNDOTBS1' *.user_dump_dest='/home/oracle/admin/Oracle/udump'
修改standby主機的initoracle.ora文件(先備份),我的initOracle.ora如下,供參考
*.aq_tm_processes=1 *.background_dump_dest='/home/oracle/admin/primary/bdump' *.compatible='9.2.0.0.0' *.control_files='/home/oracle/oradata/primary/standby.ctl' *.core_dump_dest='/home/oracle/admin/primary/cdump' *.db_block_size=8192 *.db_cache_size=33554432 *.db_domain='' *.db_file_multiblock_read_count=16 *.db_name='oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=oracleXDB)' *.fast_start_mttr_target=300 *.hash_join_enabled=TRUE *.instance_name='Oracle' *.Java_pool_size=83886080 *.job_queue_processes=10 *.large_pool_size=16777216 *.open_cursors=300 *.pga_aggregate_target=25165824 *.processes=150 *.query_rewrite_enabled='FALSE' *.remote_login_passWordfile='EXCLUSIVE' *.shared_pool_size=83886080 *.sort_area_size=524288 *.star_transformation_enabled='FALSE' *.timed_statistics=TRUE *.undo_management='AUTO' *.undo_retention=10800 *.undo_tablespace='UNDOTBS1' *.user_dump_dest='/home/oracle/admin/primary/udump' *.log_archive_format=log_%t_%s.arc *.log_archive_start=TRUE *.STANDBY_FILE_MANAGEMENT=AUTO *.log_archive_dest_1='LOCATION=/home/oracle/oradata/archivelog/' *.log_archive_dest_state_1 = 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傳到輔數據庫的目錄)
4. 配置主節點(primary主機上)的tnsnames.ora文件
primary=(description= (address= (protocol=tcp) (port=1521) (host=1.1.1.1)) (connect_data= (SID=oracle))) standby=(description= (address= (protocol=tcp) (port=1521) (host=1.1.1.2)) (connect_data= (SID=Oracle)))
同樣,在副節點(standby) 的tnsnames.ora文件。
5. 在副節點(standby)上配置listener.ora文件, 添加監聽服務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 = 1521)) ) )
在主副庫上啟動lsnrctl,
-bash-2.05b$ lsnrctl
LSNRCTL>start # 啟動監聽服務
6.在主備節點用tnsping測試網絡連通性
在primary機上
-bash-2.05b$ tnsping primary
-bash-2.05b$ tnsping standby
在standby機上
-bash-2.05b$ tnsping primary
-bash-2.05b$ tnsping standby
7. 啟動副數據庫
sql> startup nomount;
SQL> alter database mount standby database;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
8. 在主節點設置歸檔路徑
SQL> alter system set log_archive_dest_2='service=standby mandatory reopen=60';
System altered.
定義了主庫向副庫傳輸日志。
# 定義歸檔到備用庫,強制歸檔,重試時間60秒。
# 如果定義為可選狀態(optional),那麼在歸檔失敗後不會再次嘗試歸檔的。定義
# 為madatory狀態後,如果本次歸檔失敗,則在歸檔下一個日志時會再次嘗試。
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL>
在備用節點觀察日志:
[Oracle@eygle bdump]$ tail -f alert_primary.log
MRP0: Background Managed Standby Recovery process started
Starting datafile 1 recovery in thread 1 sequence 90
Datafile 1: '/opt/Oracle/oradata/primary/system01.dbf'
Starting datafile 2 recovery in thread 1 sequence 90
Datafile 2: '/opt/Oracle/oradata/primary/undotbs01.dbf'
…………………………
-bash-2.05b$ mkdir /home/oracle/oradata/Oracle/stdarch
-------------------------------------------------------
9.主輔數據庫的切換(停止主數據庫,啟用備用數據庫)
修改primary的參數文件initOracle.ora(先做好備份)
增加
*.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_2參數
修改standby的參數文件initOracle.ora(先做好備份)
增加
*.log_archive_dest_2='service=primary mandatory reopen=60'
*.log_archive_dest_state_2='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-01507: 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-01507: 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 ---------- ---------- -------------------------------- 72 1 INACTIVE 73 2 INACTIVE 74 3 CURRENT SQL> alter system switch logfile; System altered. SQL> select sequence#,group#,status from v$log; SEQUENCE# GROUP# STATUS ---------- ---------- -------------------------------- 75 1 CURRENT 73 2 INACTIVE 74 3 ACTIVE
在primary主機上執行:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
在primary主機上觀察日志應用情況
[oracle@primary bdump]$ tail -f alert_Oracle.log
Starting datafile 2 recovery in thread 1 sequence 93
Datafile 2: '/opt/Oracle/oradata/primary/undotbs01.dbf'
Starting datafile 3 recovery in thread 1 sequence 93
Datafile 3: '/opt/Oracle/oradata/primary/users01.dbf'
……………………………………………….
Media recover
10.現在可做一個測試,在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 1:
ORA-01219: 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.
常見問題
至此,主副的配置已基本完成,可做以下實驗來驗證配置的准確性。
1. 在主庫上新建一個表,看修改時候能馬上傳到副庫上;
2. 在主庫上新建一個表空間,新增加一個datafile,看修改時候能馬上傳到副庫上(應該是只要在副庫上執行恢復模式,就能在副庫上看到新建的表空間;
3. 在主庫上新建一個臨時表空間,rename datafile 均不能應用到副庫上;
4. 應當實時察看standby庫的alert文件,就能清晰明了地知道主副更新的情況;
5. 關於啟動關閉順序。
啟動的時候,先從庫的listener,再啟動從庫,再啟動主庫的listener,再主庫。
關閉的時候,先關閉主庫,再啟動從庫。
6. 8i副數據庫切換為主的話,將無法再切為副。主數據庫也是! 也就是說,只能完成一次切換,這叫failover!9i可實現主副數據庫任意切換,這叫switchover
7. 察看主機當前的運行狀態:
SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;
NAME OPEN_MODE PROTECTION_MODE DATABASE_ROLE
--------- ---------- -------------------- ----------------
PRIMARY MOUNTED MAXIMUM PERFORMANCE PHYSICAL STANDBY
8.查看主數據庫日志是否全部傳送到副數據庫,可查看v$archive_gap,更簡單的方法是查看各自主機的日志歸檔目錄的日志序號即可。
11. 常用的一些方法:
可在副數據庫上運行一些腳本,確保主數據庫上的更新能及時在副數據庫上得到實現。可將以下腳本放在crontab表中。
Oracle@standby $cat refresh (刷新腳本)
ORACLE_SID=Oracle
ORACLE_HOME=/home/Oracle/product/9.2.0
export ORACLE_SID Oracle_HOME
DATE=`date '+%Y%m%d'`
touch /home/Oracle/refresh_$DATE.log
$Oracle_HOME/bin/sqlplus /nolog << EOF
spool /home/Oracle/refresh_$DATE.log
connect sys/abc123 as sysdba
shutdown immediate;
quit
EOF
$Oracle_HOME/bin/sqlplus /nolog << EOF2
spool /home/Oracle/refresh_2_$DATE.log
connect sys/abc123 as sysdba
startup nomount pfile=$ORACLE_HOME/dbs/initOracle.ora;
alter database mount standby database;
alter database set standby database to maximize performance;
alter database recover managed standby database disconnect from session;
spool off
EOF2
Oracle@standby $cat readonly (更新腳本)
#!/bin/sh
ORACLE_SID=Oracle
ORACLE_HOME=/home/Oracle/product/9.2.0
export ORACLE_SID Oracle_HOME
$Oracle_HOME/bin/sqlplus /nolog << EOF
spool /home/Oracle/refresh-read.log
connect sys/abc123 as sysdba
rem change from recover mode to read-only
alter database recover managed standby database cancel;
alter database open read only ;
spool off
EOF
switchover過程。
12.把數據庫切換回到主節點
先將standby此時的initOracle.ora恢復為以前是standby時的參數。
在主節點(standby主機上)
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
statOracle instance shut down.
SQL> startup nomount pfile=/home/oracle/product/9.2.0/dbs/initOracle.ora;
;
Oracle instance started.
Total System Global Area 135337420 bytes
Fixed Size 452044 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database;
Database altered.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
在備用節點(在primary主機上)
先將primary此時的initOracle.ora恢復為以前是primary時的參數。
SQL> alter database commit to switchover to primary;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
Oracle instance shut down.
SQL> startup pfile=/home/oracle/product/9.2.0/dbs/initOracle.ora;
Oracle instance started.
Total System Global Area 135337420 bytes
Fixed Size 452044 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.