天天看點

Oracle Data Guard_ 主庫删除表空間

8.3.2 删除表空間和删除資料檔案

when you delete one or more datafiles 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 the ​

<code>​standby_file_management​</code>​ initialization parameter is set to ​<code>​auto​</code>​ or ​<code>​manual​</code>​.

當你在主庫删除一個或多個資料檔案或者删除一個或多個表空間時,你也需要在備庫删除相關的資料檔案,以下部分提供的例子,當standby_file_management參數設定為auto或者manual時關于删除表空間和删除資料檔案。

8.3.2.1 當standby_file_management設定為auto或者manual時

the following procedure works whether the ​<code>​standby_file_management​</code>​ initialization parameter is set to either ​<code>​manual​</code>​ or ​<code>​auto​</code>​, as follows:

以下的步驟不管standby_file_management參數設定為manual還是auto,都能工作,如下:

drop the tablespace from the primary database:

1.從主庫删除一個表空間

sql&gt; drop tablespace tbs_4;

sql&gt; 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&gt; select process, status from v$managed_standby;

to verify that deleted datafiles are no longer part of the database, query the <code>v$datafile</code> view.

驗證已經删除的資料檔案不再存在資料庫中,可查詢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.2 使用drop tablespace including contents and datafiles

you can issue the sql ​<code>​drop tablespace including contents and datafiles​</code>​ statement on the primary database to delete the datafiles on both the primary and standby databases. to use this statement, the ​<code>​standby_file_management​</code>​ initialization parameter must be set to ​

<code>​auto​</code>​. for example, to drop the tablespace at the primary site:

你可以在主庫上使用drop tablespace including contents and datafiles來删除主庫和備庫的資料檔案,前提是standby_file_management必須設定為auto,例如,在主庫上删除一個表空間:

sql&gt; drop tablespace including contents and datafiles tbs_4;

###########################################################################################################

我的實驗:主庫使用drop tablespace including contents and datafiles删除表空間,備庫中的standby_file_management參數設定為auto

主庫:prod

備庫:prodstd

1.首先檢視standby_file_management參數是否設定為auto

sys@prodstd&gt;show parameter standby_file_management

name                                 type        value

------------------------------------ ----------- ------------------------------

standby_file_management              string      auto

2.檢視兩邊的表空間以及資料檔案

主庫:

sys@prod&gt;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&gt;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

3.在主庫執行删除表空間及資料檔案

sys@prod&gt;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.再次檢視兩邊的表空間以及資料檔案

/u01/app/oracle/oradata/prodstd/disk1/prodstd/datafile/o1_mf_swtich_t_9m21f1f0_.dbf

此時主庫的歸檔重做日志還沒有傳到備庫。

5.手動切換日志,同步主備庫,讓備庫應用重做日志。

sys@prod&gt;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

備庫告警日志:

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'

rfs[4]: assigned to rfs process 2941

rfs[4]: identified database type as 'physical standby'

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&gt;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表空間已經被删除。