Move all database objects from one tablespace to another
来源:互联网 发布:电脑安装mac os x 编辑:程序博客网 时间:2024/06/04 17:43
Sometime is necessary to move all database objects from one tablespace to another.
Basically are tables, indexes and lobs.
This script permit move database objects from one user and/or tablespace to another:
1、此脚本只用于产生相应语句。
2、如果是同一用户下的表schema_user 为空,否则会把所有用户下数据查出来
---------------------------------------------------------------------
set echo off
set heading off
var tbs_source varchar2;
var tbs_dest varchar2;
var schema_user varchar2;
-- '' if it isn't relevant.
exec :tbs_source := 'TSSAWF';
-- '' if it isn't relevant.
exec :schema_user := '';
exec :tbs_dest := 'TSSAIOMS';
select 'Transporting tablespace ' || :tbs_source || ' or user ' || :schema_user || ' to tablespace ' || :tbs_dest from dual;
select 'Size: ' || to_char((sum(ext.bytes) / 1048576), '9,990.00') || ' MB'
from dba_objects ob
inner join (
select ta.owner, ta.table_name as nom, ta.tablespace_name as tbs, 'TABLE' as tipo from dba_tables ta
union
select ind.owner, ind.index_name as nom, ind.tablespace_name as tbs, 'INDEX' as tipo from dba_indexes ind
) tb on tb.owner=ob.owner and tb.nom=ob.object_name and tb.tipo=ob.object_type
inner join dba_extents ext on ext.segment_name = ob.object_name
where ob.object_type in ('INDEX', 'TABLE', 'LOB') and (tb.tbs = :tbs_source or ob.owner = :schema_user);
select 'alter user ' || ob.owner || ' quota unlimited on ' || :tbs_dest || ' default tablespace ' || :tbs_dest || ';'
from dba_objects ob
inner join (
select ta.owner, ta.table_name as nom, ta.tablespace_name as tbs, 'TABLE' as tipo from dba_tables ta
union
select ind.owner, ind.index_name as nom, ind.tablespace_name as tbs, 'INDEX' as tipo from dba_indexes ind
) tb on tb.owner=ob.owner and tb.nom=ob.object_name and tb.tipo=ob.object_type
where ob.object_type in ('INDEX', 'TABLE', 'LOB') and (tb.tbs = :tbs_source or ob.owner = :schema_user)
group by ob.owner;
select
decode(ob.object_type,
'TABLE',
'alter table "' || ob.owner || '"."' || ob.object_name || '" move tablespace ' || :tbs_dest || ';',
'alter index "' || ob.owner || '"."' || ob.object_name || '" rebuild tablespace ' || :tbs_dest || ';'
)
from dba_objects ob
inner join (
select ta.owner, ta.table_name as nom, ta.tablespace_name as tbs, 'TABLE' as tipo from dba_tables ta
union
select ind.owner, ind.index_name as nom, ind.tablespace_name as tbs, 'INDEX' as tipo from dba_indexes ind
) tb on tb.owner=ob.owner and tb.nom=ob.object_name and tb.tipo=ob.object_type
where ob.object_type in ('TABLE') and (tb.tbs = :tbs_source or ob.owner = :schema_user);
select
'alter table "' || lo.owner || '"."' || lo.table_name ||
'" move lob ("' || lo.column_name || '") store as (tablespace ' || :tbs_dest || ');'
from dba_lobs lo
inner join dba_segments se on se.segment_name = lo.segment_name
where se.tablespace_name = :tbs_source or se.owner = :schema_user;
select
decode(ob.object_type,
'TABLE',
'alter table "' || ob.owner || '"."' || ob.object_name || '" move tablespace ' || :tbs_dest || ';',
'alter index "' || ob.owner || '"."' || ob.object_name || '" rebuild tablespace ' || :tbs_dest || ';'
)
from dba_objects ob
inner join (
select ta.owner, ta.table_name as nom, ta.tablespace_name as tbs, 'TABLE' as tipo from dba_tables ta
union
select ind.owner, ind.index_name as nom, ind.tablespace_name as tbs, 'INDEX' as tipo from dba_indexes ind
) tb on tb.owner=ob.owner and tb.nom=ob.object_name and tb.tipo=ob.object_type
where ob.object_type in ('INDEX') and (tb.tbs = :tbs_source or ob.owner = :schema_user);
- Move all database objects from one tablespace to another
- How to move RAC Database ORACLE_HOME from one location to another one (Doc ID 1438719.1)
- How to move ASM database files from one diskgroup to another
- How to move ASM database files from one diskgroup to another
- Transfer Statistics from one Database to Another
- How to move Oracle data from one machine to another
- Move an installed (Open)Solars from one disk to another
- How to Move or Copy a Tablespace to Another Database【每日一译】--2012-11-03
- How to Export and Import the AWR Repository From One Database to Another (文档 ID 785730.1)
- Transferring Data from One Table to Another
- Migrating Queries from One User To Another
- copy from one array to another
- 101.You want to move all objects of the APPS user in the test database to the DB_USER schema of the
- 从一个表的数据拷贝到另一个表,Copy all columns from one table to another table:
- BAPI to Copy Materials from one Plant to Another
- BAPI to Copy Materials from one Plant to Another
- BAPI to Copy Materials from one Plant to Another
- BW--ABAP to copy aggregates from one cube to another
- ubuntu安装tftpserver
- 被delphi控件折磨了两天
- IPC_CREAT | 0660
- 网站测试基本方法-19. 平台测试
- ubuntu网络配置
- Move all database objects from one tablespace to another
- EXT 解析器与数据的关系
- Dojo.tree
- DEMO:字符串反转
- Linux 网络学习笔记 1
- 2010年7月20日再次在CSDN安家!!!
- 最简单的授权文件
- AppScan使用
- 『IT视界』 [原创评论]揪出"程序员"身上的"六宗罪"