Oracle入門教程:在資料表空間之間移動資料對象

來源:互聯網
上載者:User

在資料表空間之間移動資料對象  

一、基礎指令碼

在Oracle資料庫的資料表空間之間移動對象會涉及多種類型的資料對象
移動表:

  1. alter table t_a move tablespace tbs_a;  

移動索引:

  1. alter index i_a rebuild tablespace tbs_a;  

移動LOBSEGMENT:

  1. alter table t_a move lob(colume_a) store as (tablespace tbs_a);  

根據實際檢驗LOBINDEX會隨著相應的LOBSEGMENT自動移動
移動表的同時移動LOBSEGMENT:

  1. alter table t_a move tablespace tbs_a lob(colume_a) store as (tablespace tbs_a);  

如果表中有欄位為LONG類型的,那麼該表不能按照上面的方法移動,只能使用EXP/IMP來移動了

二、批量產生移動指令碼

如果有大量的對象需要移動,一行一行寫指令碼就很不現實,可以使用下面的指令碼來產生移動的指令碼

--產生LOBSEGMENT的移動語句,目的是把使用者USR_A的LOBSEGMENT對象從資料表空間TBS_OLD移動到TBS_NEW,所產生的語句執行後,相應的LOBINDEX對象也會跟著移動到TBS_NEW

  1. select 'alter table ' || owner || '.' || table_name || ' move LOB(' || column_name || ') store as (tablespace TBS_NEW);' from dba_lobs where owner = 'USR_A' and tablespace_name='TBS_OLD';  

--如要把LOB段所在的表也隨同LOB段移動到新的資料表空間,可使用以下語句來產生指令碼

  1. select 'alter table ' || owner || '.' || table_name || ' move tablespace TBS_NEW LOB(' || column_name || ') store as (tablespace TBS_NEW);' from dba_lobs where owner = 'USR_A' and tablespace_name='TBS_OLD';  

--產生移動USR_A的表和索引的指令碼,排序是為了移動表的指令碼在前,移動索引的指令碼在後,按序執行即可;否則先移索引後移表會導致索引失效

  1. select 'alter ' || segment_type || ' USR_A.' || segment_name || ' ' || decode(segment_type,'TABLE','move','INDEX','rebuild') || ' ' || 'tablespace TBS_NEW;' from dba_segments where owner = 'USR_A' and tablespace_name='TBS_OLD' and segment_type in ('TABLE','INDEX') order by segment_type desc;  

--可以用以下語句檢查dba_indexes資料字典表中的失效的索引資訊

  1. select * from dba_indexes where status = 'UNUSABLE';  

三、一些可能會用到的查詢語句

另外還有一些可能會用到的查詢資料表空間中資料對象資訊的語句

--統計使用者USR_A的資料對象數

  1. select count(*) from dba_segments where owner='USR_A';  

--查看使用者USR_A的資料對象所分布的資料表空間名

  1. select distinct tablespace_name from dba_segments where owner='USR_A';  

--查看使用者USR_A的LOB段和LOB索引對象

  1. select * from dba_segments where owner='USR_A' and segment_type in ('LOBSEGMENT','LOBINDEX');  

--分資料表空間、段類型統計使用者USR_A的資料對象數

  1. select tablespace_name,segment_type,count(*) from dba_segments where owner='USR_A';  
  2. group by tablespace_name,segment_type;  
  3. order by tablespace_name,segment_type;  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.