JTr*_*ant 1 sql oracle tablespace
我使用的是 Oracle 数据库 12c。据我所知,表空间是一种逻辑存储单元,由一个或多个数据文件组成,其中存储有关架构对象的数据。我也了解如何创建表空间。
我的问题是:哪些模式对象可以分配给不同的表空间?我们如何使用 SQL 将这些对象分配到表空间?
编辑:
我发现要将表移动到不同的表空间,我们使用以下语法:
ALTER TABLE <TABLE NAME to be moved> MOVE TABLESPACE <destination TABLESPACE NAME>
Run Code Online (Sandbox Code Playgroud)
此外,要将相应的索引移动到表空间,我们在执行上述查询后使用以下语法:
alter index <owner>."<index_name>" rebuild;
Run Code Online (Sandbox Code Playgroud)
但是,是否还有更多架构对象可以移动到如上所述的表空间?
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';
Run Code Online (Sandbox Code Playgroud)
alter table SCOTT.EMP modify default attributes tablespace TARGET_TS;
Run Code Online (Sandbox Code Playgroud)
-- 然后调用此查询生成的 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;
Run Code Online (Sandbox Code Playgroud)
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';
Run Code Online (Sandbox Code Playgroud)
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';
Run Code Online (Sandbox Code Playgroud)
与分区表类似,但使用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')
;
Run Code Online (Sandbox Code Playgroud)
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')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11938 次 |
| 最近记录: |