重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1947|回复: 0
打印 上一主题 下一主题

[Oracle] 处理system表空间中的业务数据

[复制链接]
跳转到指定楼层
楼主
发表于 2022-2-9 16:14:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
有时部分业务表或索引在建立时错放于system表空间,
system表空间一旦被业务数据撑满,将引起整个数据库挂起,
存在严重的安全隐患,此时需数据库管理员提前将业务数据移动到业务表空间.
查业务用户在system表空间是否存在数据:
SQL> Select Owner, Segment_Name, Segment_Type, Tablespace_Name, (Bytes /1024 /1024) As "size(m)" From dba_segments Where Owner Not In ('SYS', 'SYSTEM', 'OUTLN', 'WMSYS') And Tablespace_Name = 'SYSTEM';  
以下为执行过程:
SQL> conn jack/jack
Connected.
查该用户有哪些对象:
SQL> select table_name,table_type from user_tab_comments;
TABLE_NAME              TABLE_TYPE
------------------------------ ----------------------
EMPLOYEES                TABLE
TS                             VIEW
SYS用户查询EMPLOYEES对应表空间:
SQL> conn / as sysdba
Connected.
SQL> select b.file_name,a.owner,a.segment_name,a.tablespace_name from dba_extents a,dba_data_files b where a.file_id=b.file_id and a.segment_name='EMPLOYEES' and a.owner='JACK';
FILE_NAME                                          OWNER           SEGMENT_NAME                   TABLESPACE_NAME
-------------------------------------------------- --------------- ------------------------------ ------------------------------
/u01/app/oracle/oradata/orcl150/users01.dbf        JACK             EMPLOYEES                      USERS
普通用户建表且表空间指定为system:
SQL> show user;
USER is "JACK"
SQL> create table employees1 tablespace system as select * from employees;
Table created.
SQL> conn / as sysdba
Connected.
SQL> select b.file_name,a.owner,a.segment_name,a.tablespace_name from dba_extents a,dba_data_files b where a.file_id=b.file_id and a.segment_name='EMPLOYEES1' and a.owner='JACK';
FILE_NAME                                          OWNER           SEGMENT_NAME                   TABLESPACE_NAME
-------------------------------------------------- --------------- ------------------------------ ------------------------------
/u01/app/oracle/oradata/orcl150/system01.dbf       JACK             EMPLOYEES1                     SYSTEM
普通用户建索引且表空间指定为system:
SQL> show user;
USER is "JACK"
SQL> create index employees1 on employees1(id) tablespace system;
Index created.
SQL> select index_name,table_name from user_indexes where table_name='EMPLOYEES1';
INDEX_NAME                     TABLE_NAME
------------------------------ ------------------------------
EMPLOYEES1                     EMPLOYEES1
SQL> conn / as sysdba
Connected.
SQL> select index_name,tablespace_name from dba_indexes where index_name='EMPLOYEES1';
INDEX_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
EMPLOYEES1                     SYSTEM
查业务用户存在于system表空间的对象:
SQL> conn / as sysdba
Connected.
SQL> Select Owner, Segment_Name, Segment_Type, Tablespace_Name, (Bytes / 1024 / 1024) As "size(m)"
2   From Dba_Segments
3   Where Owner Not In ('SYS', 'SYSTEM', 'OUTLN', 'WMSYS') And Tablespace_Name = 'SYSTEM';
OWNER           SEGMENT_NAME                   SEGMENT_TYPE                TABLESPACE_NAME          size(m)
--------------- ------------------------------ ------------------------------------ ------------------------------ ----------
JACK             EMPLOYEES1                     TABLE                                SYSTEM                              .0625
JACK             EMPLOYEES1                     INDEX                                SYSTEM                              .0625
问题:如何将以上EMPLOYEES1表及索引移动到users表空间?
SQL> conn JACK/JACK
Connected.
SQL> alter table EMPLOYEES1 move tablespace users;
Table altered.
SQL> conn / as sysdba
Connected.
SQL> select owner,segment_name,segment_type,tablespace_name,(bytes/1024/1024) as "size(m)" from dba_segments where owner not in ('SYS','SYSTEM','OUTLN','WMSYS') and tablespace_name='SYSTEM';
no rows selected
#查表对应表空间
SQL> select t.table_name,t.tablespace_name from dba_tables t where t.table_name='EMPLOYEES1';  
TABLE_NAME                                                   TABLESPACE_NAME
------------------------------------------------------------ ------------------------------
EMPLOYEES1                                                   USERS
SQL> select index_name,tablespace_name from dba_indexes where index_name='EMPLOYEES1';
INDEX_NAME                                                   TABLESPACE_NAME
------------------------------------------------------------ ------------------------------
EMPLOYEES1                                                   SYSTEM
#此处确认表已在users表空间,索引还在system表
SQL> conn JACK/JACK
Connected.
SQL> alter index employees1 rebuild tablespace users;
Index altered.
SQL> conn / as sysdba
Connected.
SQL> select index_name,tablespace_name from dba_indexes where index_name='EMPLOYEES1';
INDEX_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
EMPLOYEES1                     USERS
#此处确认索引employees1表空间也已更改为users.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-9-20 06:14 , Processed in 0.086982 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表