我正在使用Oracle数据库12c。 我知道表空间是由一个或多个数据文件组成的逻辑存储单元,其中存储了有关模式对象的数据。我也了解如何创建表空间。
我的问题是:哪些架构对象可以分配给不同的表空间?我们如何使用SQL将这些对象分配给表空间?
编辑:
我发现要将表移动到其他表空间,我们使用以下语法:
ALTER TABLE <TABLE NAME to be moved> MOVE TABLESPACE <destination TABLESPACE NAME>
另外,为了将相应的索引移动到表空间,我们在执行上述查询后使用以下语法:
alter index <owner>."<index_name>" rebuild;
但是,还有其他架构对象可以移动到上面的表空间吗?
答案 0 :(得分:0)
有一个Oracle软件包DBMS_REDEFINITION.REDEF_TABLE,从理论上讲,它可以移动表及其关联的对象(索引和LOB)。它也可以处理分区表。
如果这行不通,或者您想更好地了解哪些片段可以到达何处,请考虑以下对象:
LOB
(大对象)列,例如CLOB
和BLOB
数据类型以下SQL生成SQL以移动现有对象;您将需要根据情况更改标准;这显示了SCOTT
拥有的对象从SYSAUX
表空间移动到TARGET_TS
:
select 'alter table ' || do.owner || '.' || do.object_name ||
' move tablespace TARGET_TS;' as cmd_to_invoke
from dba_objects do, dba_segments ds, dba_tables dt
where do.owner = 'SCOTT' '
and do.owner=ds.owner and do.owner=dt.owner
and do.object_name = ds.segment_name and do.object_name=dt.table_name
and dt.iot_name is null and do.object_type='TABLE'
and ds.tablespace_name = 'SYSAUX';
alter table SCOTT.EMP modify default attributes tablespace TARGET_TS;
-然后调用此查询生成的SQL:
select distinct 'alter table ' || dt.table_owner || '.' || dt.table_name ||
' move partition ' || dt.partition_name ||
' tablespace TARGET_TS' || ';' as cmd_to_invoke
from
dba_tab_partitions dt
where dt.table_owner='SCOTT'and dt.tablespace_name='SYSAUX'
order by 1;
select 'alter table ' || owner || '.' || table_name || ' move tablespace DEF_TABLESPACE;'
from dba_indexes
where owner = 'SCOTT'
and index_type = 'IOT - TOP'
and tablespace_name='SYSAUX';
select 'alter index ' || do.owner || '.' || do.object_name || ' rebuild tablespace apex;' as cmd
from dba_objects do, dba_segments ds, dba_indexes di
where do.owner = 'SCOTT'
and do.owner=ds.owner and do.owner=di.owner
and do.object_type = 'INDEX'
and di.index_type in('NORMAL', 'FUNCTION-BASED NORMAL')
and do.object_name = ds.segment_name and do.object_name = di.index_name
and ds.tablespace_name='SYSAUX';
类似于分区表,但使用alter index
并引用DBA_INDEXES
或DBA_IND_PARTITIONS
select distinct 'alter table ' || dtc.owner || '.' || dtc.table_name ||
' move lob(' || column_name || ')' ||
' store as (tablespace DEF_TABLESPACE);' as cmd_to_invoke
from dba_tab_columns dtc,
dba_tables dt,
dba_indexes di
where dt.owner=dtc.owner and dt.owner=di.owner
and dt.table_name=di.table_name and dt.table_name=dtc.table_name
and dtc.owner = 'SCOTT' and dtc.data_type like '%LOB%'
and di.index_name in
(select segment_name from dba_segments inner
where inner.owner=dt.owner and tablespace_name='SYSAUX')
;
select distinct 'alter table ' || dtc.owner || '.' || dtc.table_name ||
' move partition ' || dt.partition_name ||
' lob(' || column_name || ')' ||
' store as (tablespace TARGET_TS)' ||
';'
from dba_tab_columns dtc,
dba_tab_partitions dt,
dba_indexes di
where dt.table_owner=dtc.owner and dt.table_owner=di.owner
and dt.table_name=di.table_name and dt.table_name=dtc.table_name
and dtc.owner ='SCOTT' and dtc.data_type like '%LOB%'
and di.index_name in
(select segment_name from dba_segments inner
where inner.owner=dt.table_owner and tablespace_name='SYSAUX')