8.3.2 删除表空间和删除数据文件
When you delete one or moredatafiles or drop one or more tablespaces in the primary database, you also need to delete the corresponding datafiles to the standby database. The following sections provide examples of dropping tablespaces and deleting datafiles when theSTANDBY_FILE_MANAGEMENTinitialization parameter is set toAUTOorMANUAL.
当你在主库删除一个或多个数据文件或者删除一个或多个表空间时,你也需要在备库删除相关的数据文件,以下部分提供的例子,当
8.3.2.1When STANDBY_FILE_MANAGEMENT Is Set to AUTO or MANUAL
8.3.2.1 当STANDBY_FILE_MANAGEMENT设置为AUTO或者MANUAL时
The following procedure works whether theSTANDBY_FILE_MANAGEMENTinitialization parameter is set to eitherMANUALorAUTO, as follows:
以下的步骤不管STANDBY_FILE_MANAGEMENT参数设置为MANUAL还是AUTO,都能工作,如下:
Drop the tablespace from the primary database:
1.从主库删除一个表空间
SQL> DROP TABLESPACE tbs_4;
SQL> ALTER SYSTEM SWITCH LOGFILE;
Make sure that Redo Apply is running (so that the change is applied to the standby database). If the following query returns the MRP or MRP0 process, Redo Apply is running.
确保重做应用在运行,这样备库就会应用这些变化。如果以下的查询返回的MRP或者MRP0进程,则说明重做应用在运行
SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;
To verify that deleted datafiles are no longer part of the database, query theV$DATAFILEview.
验证已经删除的数据文件不再存在数据库中,可查询V$DATAFILE视图。
Delete the corresponding datafile on the standby system after the archived redo log file was applied to the standby database. For example:
在归档重做日志被应用再备库之后,在备库删除相应的数据文件,例如:
% rm /disk1/Oracle/oradata/payroll/s2tbs_4.dbf
On the primary database, after ensuring the standby database applied the redo information for the dropped tablespace, you can remove the datafile for the tablespace. For example:
在主库中,确保备库应用删除表空间的重做信息之后,你可以从表空间移除数据文件,例如:
% rm /disk1/oracle/oradata/payroll/tbs_4.dbf
8.3.2.2Using DROP TABLESPACE INCLUDING CONTENTS AND DATAFILES
8.3.2.2 使用DROP TABLESPACE INCLUDING CONTENTS AND DATAFILES
You can issue the SQLDROP TABLESPACE INCLUDING CONTENTS AND DATAFILESstatement on the primary database to delete the datafiles on both the primary and standby databases. To use this statement, theSTANDBY_FILE_MANAGEMENTinitialization parameter must be set toAUTO. For example, to drop the tablespace at the primary site:
你可以在主库上使用DROP TABLESPACE INCLUDING CONTENTS AND DATAFILES来删除主库和备库的数据文件,前提是STANDBY_FILE_MANAGEMENT必须设置为AUTO,例如,,在主库上删除一个表空间:
SQL> DROP TABLESPACE INCLUDING CONTENTS AND DATAFILES tbs_4;
SQL> ALTER SYSTEM SWITCH LOGFILE;
###########################################################################################################
我的实验:主库使用DROP TABLESPACE INCLUDING CONTENTS AND DATAFILES删除表空间,备库中的STANDBY_FILE_MANAGEMENT参数设置为AUTO
主库:PROD
备库:PRODSTD
1.首先查看STANDBY_FILE_MANAGEMENT参数是否设置为AUTO
SYS@PRODSTD>show parameter STANDBY_FILE_MANAGEMENT
NAME TYPE VALUE
———————————— ———– ——————————
standby_file_management string AUTO
2.查看两边的表空间以及数据文件
主库:
SYS@PROD>select file_name,tablespace_name from dba_data_files;
FILE_NAME TABLESPACE_NAME
————————————————– ——————————
/u01/app/oracle/oradata/PROD/Disk1/system01.dbf SYSTEM
/u01/app/oracle/oradata/PROD/Disk1/undotbs01.dbf UNDOTBS1
/u01/app/oracle/oradata/PROD/Disk1/sysaux01.dbf SYSAUX
/u01/app/oracle/oradata/PROD/Disk1/example01.dbf EXAMPLE
/u01/app/oracle/oradata/PROD/Disk1/users01.dbf USERS
/u01/app/oracle/oradata/PROD/Disk1/swtich_tbs01.db SWTICH_TBS
f
6 rows selected.
备库:
SYS@PRODSTD>select name from v$datafile;
NAME
——————————————————————————–
/u01/app/oracle/oradata/PRODSTD/Disk1/system01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/undotbs01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/sysaux01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/example01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/PRODSTD/datafile/o1_mf_swtich_t_9m21f1f0_.
dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/users01.dbf
6 rows selected.
3.在主库执行删除表空间及数据文件
SYS@PROD>drop tablespace SWTICH_TBS including contents and datafiles;
Tablespace dropped.
——————————————————————————————
主库告警日志:
Sun Mar 30 10:47:37 2014
drop tablespace SWTICH_TBS including contents and datafiles
Sun Mar 30 10:47:42 2014
Deleted file /u01/app/oracle/oradata/PROD/Disk1/swtich_tbs01.dbf
Completed: drop tablespace SWTICH_TBS including contents and datafiles
——————————————————————————————
4.再次查看两边的表空间以及数据文件
主库:
SYS@PROD>select file_name,tablespace_name from dba_data_files;
FILE_NAME TABLESPACE_NAME
————————————————– ——————————
/u01/app/oracle/oradata/PROD/Disk1/system01.dbf SYSTEM
/u01/app/oracle/oradata/PROD/Disk1/undotbs01.dbf UNDOTBS1
/u01/app/oracle/oradata/PROD/Disk1/sysaux01.dbf SYSAUX
/u01/app/oracle/oradata/PROD/Disk1/example01.dbf EXAMPLE
/u01/app/oracle/oradata/PROD/Disk1/users01.dbf USERS
备库:
SYS@PRODSTD>select name from v$datafile;
NAME
——————————————————————————–
/u01/app/oracle/oradata/PRODSTD/Disk1/system01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/undotbs01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/sysaux01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/example01.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/PRODSTD/datafile/o1_mf_swtich_t_9m21f1f0_.dbf
/u01/app/oracle/oradata/PRODSTD/Disk1/users01.dbf
6 rows selected.
此时主库的归档重做日志还没有传到备库。
5.手动切换日志,同步主备库,让备库应用重做日志。
SYS@PROD>alter system switch logfile;
System altered.
——————————————————————————————-
主库告警日志:
LNS1 started with pid=57, OS id=3000
Sun Mar 30 10:58:08 2014
Thread 1 advanced to log sequence 34
Current log# 2 seq# 34 mem# 0: /u01/app/oracle/oradata/PROD/Disk1/redo02.log
Current log# 2 seq# 34 mem# 1: /u01/app/oracle/oradata/PROD/Disk2/redo02_1.log
Sun Mar 30 10:58:10 2014
LNS: Standby redo logfile selected for thread 1 sequence 34 for destination LOG_ARCHIVE_DEST_2
Sun Mar 30 10:58:11 2014
ARC5: Standby redo logfile selected for thread 1 sequence 33 for destination LOG_ARCHIVE_DEST_2
备库告警日志:
Sun Mar 30 10:58:11 2014
Redo Shipping Client Connected as PUBLIC
— Connected User is Valid
RFS[3]: Assigned to RFS process 2939
RFS[3]: Identified database type as ‘physical standby’
Sun Mar 30 10:58:11 2014
Redo Shipping Client Connected as PUBLIC
— Connected User is Valid
RFS[4]: Assigned to RFS process 2941
RFS[4]: Identified database type as ‘physical standby’
Primary database is in MAXIMUM PERFORMANCE mode
Primary database is in MAXIMUM PERFORMANCE mode
RFS[4]: Successfully opened standby log 6: ‘/u01/app/oracle/oradata/PRODSTD/Disk1/standby06.log’
Sun Mar 30 10:58:12 2014
RFS[3]: Successfully opened standby log 7: ‘/u01/app/oracle/oradata/PRODSTD/Disk1/standby07.log’
Sun Mar 30 10:58:17 2014
Media Recovery Log /u01/app/oracle/oradata/PRODSTD/Disk2/arch/1_33_842523531.arc
Recovery deleting file #5:’/u01/app/oracle/oradata/PRODSTD/Disk1/PRODSTD/datafile/o1_mf_swtich_t_9mh1rzf6_.dbf’ from controlfile.
Deleted Oracle managed file /u01/app/oracle/oradata/PRODSTD/Disk1/PRODSTD/datafile/o1_mf_swtich_t_9mh1rzf6_.dbf
Recovery dropped tablespace ‘SWTICH_TBS’
Media Recovery Waiting for thread 1 sequence 34 (in transit)
———————————————————————————————————–
6.查看备库数据文件
SYS@PRODSTD>select file#,name from v$datafile;
FILE# NAME
———- ——————————————————-
1 /u01/app/oracle/oradata/PRODSTD/Disk1/system01.dbf
2 /u01/app/oracle/oradata/PRODSTD/Disk1/undotbs01.dbf
3 /u01/app/oracle/oradata/PRODSTD/Disk1/sysaux01.dbf
4 /u01/app/oracle/oradata/PRODSTD/Disk1/example01.dbf
7 /u01/app/oracle/oradata/PRODSTD/Disk1/users01.dbf
此时备库的SWITCH_TBS表空间已经被删除。
相关参考:
Oracle Data Guard 重要配置参数
基于同一主机配置 Oracle 11g Data Guard
探索Oracle之11g DataGuard
Oracle Data Guard (RAC+DG) 归档删除策略及脚本
Oracle Data Guard 的角色转换
Oracle Data Guard的日志FAL gap问题
Oracle 11g Data Guard Error 16143 Heartbeat failed to connect to standby 处理方法