第一次搭建oracle dataguard.学oracle很长时间,却没有完整的搭过dg,说起来让人笑.总得有第一次,而且第一次总是很痛苦的.
数据库版本:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
一、两台机器平台信息
node248
[root@node248 ~]# uname -a
Linux node248.gewara 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
[root@node248 ~]# hostname
node248.gewara
[root@node248 ~]# hostname -i
192.168.2.248
node249
Linux node249.gewara 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
[root@node249 ~]# hostname
node249.gewara
[root@node249 ~]# hostname -i
192.168.2.249
二、node248建库
用dbca工具,用oracle自带的模板,不带sample schema,不用em,开启archive模式,同一管理密码oracle.global name:dbtest.node248.gewara,实例名:dbtest
三、配置主库
SQL>shutdown immediate
SQL>startup mount
SQL>alter database force logging;
SQL>alter database open;
SQL>create pfile='/tmp/initdbtest.ora' from spfile;
编辑/tmp/initdbtest.ora,添加如下参数
dbtest.__db_cache_size=671088640
dbtest.__java_pool_size=16777216
dbtest.__large_pool_size=16777216
dbtest.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
dbtest.__pga_aggregate_target=671088640
dbtest.__sga_target=973078528
dbtest.__shared_io_pool_size=0
dbtest.__shared_pool_size=251658240
dbtest.__streams_pool_size=0
*._JOB_QUEUE_INTERVAL=120
*.audit_file_dest='/u01/app/oracle/admin/dbtest/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/dbtest/control01.ctl','/u01/app/oracle/flash_recovery_area/dbtest/control02.ctl'
*.db_block_size=8192
*.db_domain='node248.gewara'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4070572032
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dbtestXDB)'
*.memory_target=1639972864
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.DB_UNIQUE_NAME='db248' #必须指定,并且跟备库不同
*.db_name='dbtest' #数据库名,跟实例名最好一致,并且备库数据库名也一致
*.FAL_CLIENT='dbprimary' #*.FAL两个参数,是为主备切换准备的,值都是tns中所配置的tnsname
*.FAL_SERVER='dbstandby'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(db248,db249)' #指定主备库
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/archive/ #指定归档日志的存放路径,DB_UNIQUE_NAME为主库的DB_UNIQUE_NAME
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=db248'
*.LOG_ARCHIVE_DEST_2='SERVICE=dbstandby LGWR ASYNC #配置日志传输,DB_UNIQUE_NAME为备库的DB_UNIQUE_NAME
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=db249'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' #归档日志命名规则*.STANDBY_FILE_MANAGEMENT='AUTO' #备库文件管理方式为自动
用pfile启动数据库
SQL>shutdown immediate
SQL>startup pfile='/tmp/initdbtest.ora'
SQL>create spfile from pfile='/tmp/initdbtest.ora'
配置监听:修改$ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/products/11.2/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = dbtest.node248.gewara)
(ORACLE_HOME = /u01/app/oracle/products/11.2/db_1)
(SID_NAME = dbtest)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.2.248 )(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
配置好后,启动监听
$lsnrctl start
配置TNS,修改$ORACLE_HOME/network/admin/tnsnames.ora
DBSTANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.249)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbtest.node249.gewara)
)
)
DBPRIMARY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.248)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbtest.node248.gewara)
)
)
DBTEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.248)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbtest.node248.gewara)
)
)
重建密码文件:
主备库的密码文件必须保持一致,并且密码文件必须有固定的格式,具体为$ORACLE_HOME/dbs/orapw$ORACLE_SID
orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=10
密码文件修改后,重启数据库生效
SQL>shutdown immediate
SQL>startup
SYS@dbtest 00:52:32>select * from v$pwfile_users;
USERNAME SYSDB SYSOP SYSAS
------------------------------ ----- ----- -----
SYS TRUE TRUE FALSE
sys用户必须在v$pwfile_users中,并且
SYS@dbtest 00:52:32>show parameter passw
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string EXCLUSIVE