1、配置dataguard
配置dataguard的内容请参照books->Data Guard Concepts and Administration。
? 原题
在同一台主机上(db机),将prod数据库配置一个本地的物理standby数据库。如何操作?
答案:
配置步骤如下:
1)首先关闭主数据库,然后启动到mount模式(在备库创建完成之前,主库最好一直处于mount状态)
shutdown immediate
starutp mount
2)打开主数据库的logging功能
ALTER DATABASE FORCE LOGGING;
3)打开主数据库的归档功能
alter database archivelog;
4)将dataguard配置设定为最大可用模式(看题目要求)
alter database set standby database to maximize availability;
5)添加备用的logfile group,大小和数量大于online redo log(如果online log为3组,则创建standby log为4组)【使用lgwr async方式】
alter database add standby logfile group 4 '/u01/app/oradata/tdb/sredo4.dbf' size 20m;
alter database add standby logfile group 5 '/u01/app/oradata/tdb/sredo5.dbf' size 20m;
alter database add standby logfile group 6 '/u01/app/oradata/tdb/sredo6.dbf' size 20m;
alter database add standby logfile group 7 '/u01/app/oradata/tdb/sredo7.dbf' size 20m;
注:standby logfile的大小需 ≥ online logfile
6)创建dataguard数据库的控制文件(此处dataguard数据库命名为std,考试时需要仔细审题)
alter database create standby controlfile as '/u01/app/oradata/std/control01.ctl';
7)复制主数据库的数据文件、日志文件、standy日志文件到/oracle/oradata/std
8)配置网络参数
监听器和TNSNAMES
LISTENER.ORA文件内容如下:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = prod)
(ORACLE_HOME = /u01/app/oracle/product/10.2.1/db_1)
(SID_NAME = prod)
)
(SID_DESC =
(GLOBAL_DBNAME = std)
(ORACLE_HOME = /u01/app/oracle/product/10.2.1/db_1)
(SID_NAME = std)
)
)
TNSNAMES.ORA文件内容如下:
prod =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prod)
)
)
stb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stb)
)
)
9)创建备用数据库的参数文件(创建DATAGUARD数据库需要修改很多参数,最好使用pfile进行编辑,这样比较快),在主库操作创建pfile文件(如果已经使用pfile启动则可以跳过这一步),如create pfile from spfile。然后将原有的spfile(spfileprod.ora)改名为spfileprod.ora.bak。在主prod数据库pfile文件中,添加以下参数:
DB_UNIQUE_NAME=tdb
LOG_ARCHIVE_CONFIG='DG_CONFIG=(tdb,std)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/arch/tdb VALID_FOR=(ALL_LOGFILES,ALL_ROLES) '
LOG_ARCHIVE_DEST_2='SERVICE=std LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=std'
FAL_SERVER=std
FAL_CLIENT=tdb
DB_FILE_NAME_CONVERT='/u01/app/oradata/std','/u01/app/oradata/tdb'
LOG_FILE_NAME_CONVERT='/u01/app/oradata/std','/u01/app/oradata/tdb'
STANDBY_FILE_MANAGEMENT=AUTO
注意:
第一,删除一切关于MTS的参数(shared server、dispatcher),否则有可能数据库无法切换。
第二,如果不添加DB_FILE_NAME_CONVERT和LOG_FILE_NAME_CONVERT参数,则需要在standby数据库中修改数据文件和日志文件的路径,使用CONVERT参数一定要写好对应关系,不要写反,前面为对方数据库,后面的地址为本数据库。如果有多个对应关系,则按照逗号隔开如:'/u01/oradata/stb','/u01/oradata/prod' ,'/u01/stb','/u01/oradata/prod' 。
接下来,把主库的参数文件拷贝为备用库
cp inittdb.ora initstd.ora
同时拷贝密码文件
cp orapwtdb.ora orapwstd.ora
备STANDBY数据库修改以下Pfile内容
control_files='/u01/app/oradata/std/control01.ctl'
core_dump_dest='/u01/app/admin/std/cdump'
user_dump_dest='/u01/app/admin/std/udump'
background_dump_dest='/u01/app/admin/std/bdump'
DB_UNIQUE_NAME=stb
LOG_ARCHIVE_CONFIG='DG_CONFIG=(std,tdb)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/arch/stb VALID_FOR=(ALL_LOGFILES,ALL_ROLES) '
LOG_ARCHIVE_DEST_2='SERVICE=tdb LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=tdb'
FAL_SERVER=tdb
FAL_CLIENT=std
DB_FILE_NAME_CONVERT='/u01/app/oradata/tdb','/u01/app/oradata/std'
LOG_FILE_NAME_CONVERT='/u01/app/oradata/tdb','/u01/app/oradata/std'
STANDBY_FILE_MANAGEMENT=AUTO
10)启动备用数据库到standby模式
在操作系统终端输入:
export ORACLE_SID=std
sqlplus / as sysdba
startup nomount
alter database mount standby database;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
此命令为进入自动恢复模式
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
此命令为退出自动恢复模式
11)将主数据库重启
在操作系统终端输入:
export ORACLE_SID=prod
sqlplus / as sysdba
shutdown immediate
startup
12)查看数据库的状态(在两台上同时查看)
13)进行数据库角色切换时,需先将主数据库切换为备用数据库,然后将备用数据库切换为主数据库
select database_role,switchover_status from v$database;
select OPEN_MODE,database_role,PROTECTION_MODE,PROTECTION_LEVEL,SWITCHOVER_STATUS from v$database;
在主库上操作,切换到备用数据库
alter database commit to switchover to physical standby with session shutdown;
with session shutdown可以将session active直接切换
切换后,此时的数据库是一种不正常状态,需要先关闭再启动到备用模式
shutdown immediate
startup nomount
alter database mount;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
在备库上操作,切换到主数据库
alter database commit to switchover to primary with session shutdown;
alter database open;
切换后,按照要求执行脚本
注意:如果不需要互切,那么主库不用增加db_unique_name,也就是不用停机