如何将模式对象移动到不同的表空间
How to move schema objects to a different tablespace
我正在使用 Oracle 数据库 12c。
我知道 tablespace 是由一个或多个数据文件组成的逻辑存储单元,其中存储了有关模式对象的数据。我也了解如何创建 table 空间。
我的问题是:哪些架构对象可以分配给不同的table空间?我们如何使用 SQL 将这些对象分配到 table 空间?
编辑:
我发现要将 table 移动到不同的 table 空间,我们使用以下语法:
ALTER TABLE <TABLE NAME to be moved> MOVE TABLESPACE <destination TABLESPACE NAME>
此外,要将相应的索引移动到table空间,我们在执行上述查询后使用以下语法:
alter index <owner>."<index_name>" rebuild;
但是,是否还有其他模式对象可以移动到上述 table 空间?
有一个 Oracle 程序包 DBMS_REDEFINITION.REDEF_TABLE 理论上可以移动 table 及其关联的对象(索引和 LOB)。它也处理分区的 tables。
如果这不起作用,或者如果您想更好地了解哪些棋子可以放在哪里,可以考虑以下对象:
- 表和索引
- 分区 table 和索引;正如 William Robertson 提到的,您需要确保对于分区对象,除了移动现有 data/indexes.
之外,您还需要更改 DEF_TABLESPACE 值
LOB
(大对象)table列,例如CLOB
和BLOB
数据类型
- 索引组织的 tables 这实际上是一个索引而不是真正的 table.
下面的SQL生成SQL来移动已有的对象;您需要根据您的情况更改标准;这显示了将 SCOTT
拥有的对象从 SYSAUX
table 空间移动到 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
LOBS
非分区表上的 LOBS
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')
;
分区表上的 LOBS
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')
我正在使用 Oracle 数据库 12c。 我知道 tablespace 是由一个或多个数据文件组成的逻辑存储单元,其中存储了有关模式对象的数据。我也了解如何创建 table 空间。
我的问题是:哪些架构对象可以分配给不同的table空间?我们如何使用 SQL 将这些对象分配到 table 空间?
编辑:
我发现要将 table 移动到不同的 table 空间,我们使用以下语法:
ALTER TABLE <TABLE NAME to be moved> MOVE TABLESPACE <destination TABLESPACE NAME>
此外,要将相应的索引移动到table空间,我们在执行上述查询后使用以下语法:
alter index <owner>."<index_name>" rebuild;
但是,是否还有其他模式对象可以移动到上述 table 空间?
有一个 Oracle 程序包 DBMS_REDEFINITION.REDEF_TABLE 理论上可以移动 table 及其关联的对象(索引和 LOB)。它也处理分区的 tables。
如果这不起作用,或者如果您想更好地了解哪些棋子可以放在哪里,可以考虑以下对象:
- 表和索引
- 分区 table 和索引;正如 William Robertson 提到的,您需要确保对于分区对象,除了移动现有 data/indexes. 之外,您还需要更改 DEF_TABLESPACE 值
LOB
(大对象)table列,例如CLOB
和BLOB
数据类型- 索引组织的 tables 这实际上是一个索引而不是真正的 table.
下面的SQL生成SQL来移动已有的对象;您需要根据您的情况更改标准;这显示了将 SCOTT
拥有的对象从 SYSAUX
table 空间移动到 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
LOBS
非分区表上的 LOBS
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')
;
分区表上的 LOBS
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')