oracle数据库表空间及权限调整示例

简介:

一、情况说明

1.背景情况

1).用户采用DBA权限,DBA权限具有访问数据库所有用户数据的权限,不安全。
2).表空间与用户没有对应关系,无法直接标识用户与表空间(根据自己情况)。
3).迁移涉及到表、索引、LOB对象的迁移。
注:如果涉及到LONGRAW字段类型表,还需要先建LONGRAW字段转成LOB对象。

本文只是找了情景环境,做一个记录过程,相对于操作系统中文件,文件夹的数据库的移动,数据库中也就是数据库对象进行的一些操作与管理。

本文出自:http://koumm.blog.51cto.com/

2.具体任务

1.将gsjsso用户下的表全部移动到一个新建的表空间gsjsso。

2.将gsjsso用户从DBA权限降权为普通用户。

image

image

二、迁移过程如下

1.创建GSJSSO表空间,并将gsjsso用户缺省表空间改为GSJSSO表空间。

image

2.构建迁移表SQL语句

1
2
3
4
select  'alter table ' ||ds.owner|| '.' ||ds.segment_name|| ' move tablespace GSJSSO;'
from dba_segments ds
where ds.tablespace_name  in ( 'JTTSSO' ) and ds.owner =  'GSJSSO'
and ds.segment_type =  'TABLE' ;

232104728.jpg

3.构建迁移索引SQL语句

1
2
3
4
select  'alter INDEX ' ||ds.owner|| '.' ||ds.segment_name|| ' rebuild tablespace GSJSSO;'
from dba_segments ds
where ds.tablespace_name  in ( 'JTTSSO' ) and ds.owner =  'GSJSSO'
and ds.segment_type =  'INDEX' ;

image

4.构建迁移LOB大对象SQL语句过程

1)查看GSJSSO用户在JTTSSO空间中的LOB对象,说明:LOB是造成不能成功通过导入来改变空间原因。只能采用如下方式。

1
2
3
4
5
6
7
8
9
10
col TABLESPACE_NAME  for  a20;
col DS.OWNER|| '.' ||DS.SEGMENT_NAME  for  a40;
col DATA_TYPE  for  a15;
select ds.tablespace_name,ds.owner|| '.' ||ds.segment_name,ds.segment_type,
dtc.DATA_TYPE,dtc.COLUMN_NAME
from dba_tab_columns dtc , dba_segments ds
where dtc.TABLE_NAME = ds.segment_name
and dtc.OWNER = ds.owner
and ds.tablespace_name  in  ( 'JTTSSO' )
and DATA_TYPE like  '%LOB' ;

image

2)构建迁移LOB大对象SQL语句

1
2
3
select   'alter table ' ||dtc.owner|| '.' ||dtc.TABLE_NAME|| ' move lob(' ||dtc.COLUMN_NAME|| ') store as(tablespace ' ||du.default_tablespace|| ');'
from dba_tab_columns dtc,dba_users du
where dtc.OWNER = du.username and dtc.OWNER  in ( 'GSJSSO' ) and dtc.DATA_TYPE like  '%LOB' ;

image

5.执行构建SQL语句迁移表,索引,LOB对象等数据

1)复制迁移表SQL语句在SQLPLUS中执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
alter table GSJSSO.ED_SEND_CONFIG move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_HOST move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_LOG move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_ORG move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_USER move tablespace GSJSSO;
alter table GSJSSO.IDM_ROLE_MENU_ITEM move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_ADMIN_ROLE move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_ADMIN_USER move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_CONFIG move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_LOG move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_MENU move tablespace GSJSSO;
alter table GSJSSO.IDM_USER_ROLE move tablespace GSJSSO;
alter table GSJSSO.NET_PLATFORM_ORGANIZE_T move tablespace GSJSSO;
alter table GSJSSO.NET_PLATFORM_USER_T move tablespace GSJSSO;
alter table GSJSSO.PORTAL_ADAPTER move tablespace GSJSSO;
alter table GSJSSO.PORTAL_ADAPTER_RESOURCE move tablespace GSJSSO;
alter table GSJSSO.PORTAL_ADAPTER_RESOURCE_PRAM move tablespace GSJSSO;
alter table GSJSSO.PORTAL_SYS_ADMIN_USER move tablespace GSJSSO;
alter table GSJSSO.PORTAL_SYS_CONSTANTS move tablespace GSJSSO;
alter table GSJSSO.PORTAL_TEMPLATE_STYLE move tablespace GSJSSO;
alter table GSJSSO.PORTAL_TEMPLATE_USER move tablespace GSJSSO;
alter table GSJSSO.PORTAL_TEMPLATE_ZIP move tablespace GSJSSO;
alter table GSJSSO.PORTAL_USER_HEAD_PICTURE move tablespace GSJSSO;
alter table GSJSSO.PORTAL_USER_LOGIN move tablespace GSJSSO;
alter table GSJSSO.SSO_HOST move tablespace GSJSSO;
alter table GSJSSO.SSO_HOST_CONFIG move tablespace GSJSSO;
alter table GSJSSO.SSO_ORG move tablespace GSJSSO;
alter table GSJSSO.SSO_SESSION move tablespace GSJSSO;
alter table GSJSSO.SSO_USER move tablespace GSJSSO;
alter table GSJSSO.SYS_ADMIN_USER move tablespace GSJSSO;
alter table GSJSSO.SYS_CONFIG move tablespace GSJSSO;

2)复制迁移索引SQL语句在SQLPLUS中执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
alter INDEX GSJSSO.PK_ED_SEND_CONFIG rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_HOST rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_LOG rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_ORG rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.ROLE_MENU rebuild tablespace GSJSSO;
alter INDEX GSJSSO.ID_PK rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_IDM_SYS_ADMIN_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.MENUID_PK rebuild tablespace GSJSSO;
alter INDEX GSJSSO.USER_ROLE rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005154 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005157 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005159 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005161 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005163 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_SYS_ADMIN_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_SYS_CONSTANTS rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_TEMPLATE_STYLE rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_TEMPLATE_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005173 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_USER_LOGIN rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005181 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005189 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005193 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_U rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_SYS_ADMIN_USER rebuild tablespace GSJSSO;

3)复制迁移LOB对象SQL语句在SQLPLUS中执行。

1
2
alter table GSJSSO.PORTAL_USER_LOGIN move lob(DESCRIPTION) store  as (tablespace GSJSSO);
alter table GSJSSO.ED_SEND_CONFIG_LOG move lob(DETAIL) store  as (tablespace GSJSSO);

6.验证迁移后的结果

image

查询GSJSSO用户在JTTSSO表空间还有没有对象。

image

三、降权过程如下

1.查询GSJSSO用户权限,并赋予普通权限

image

2.查询GSJSSO表空间信息

image

3.取消DBA权限

image

image

4.赋予GSJSSO用户无限制使用GSJSSO表空间的权限

image

查看使用空间配额,如需要其它额外权限,可以直接赋予。

image

至此数据库调整完毕。





一、情况说明

1.背景情况

1).用户采用DBA权限,DBA权限具有访问数据库所有用户数据的权限,不安全。
2).表空间与用户没有对应关系,无法直接标识用户与表空间(根据自己情况)。
3).迁移涉及到表、索引、LOB对象的迁移。
注:如果涉及到LONGRAW字段类型表,还需要先建LONGRAW字段转成LOB对象。

本文只是找了情景环境,做一个记录过程,相对于操作系统中文件,文件夹的数据库的移动,数据库中也就是数据库对象进行的一些操作与管理。

本文出自:http://koumm.blog.51cto.com/

2.具体任务

1.将gsjsso用户下的表全部移动到一个新建的表空间gsjsso。

2.将gsjsso用户从DBA权限降权为普通用户。

image

image

二、迁移过程如下

1.创建GSJSSO表空间,并将gsjsso用户缺省表空间改为GSJSSO表空间。

image

2.构建迁移表SQL语句

1
2
3
4
select  'alter table ' ||ds.owner|| '.' ||ds.segment_name|| ' move tablespace GSJSSO;'
from dba_segments ds
where ds.tablespace_name  in ( 'JTTSSO' ) and ds.owner =  'GSJSSO'
and ds.segment_type =  'TABLE' ;

232104728.jpg

3.构建迁移索引SQL语句

1
2
3
4
select  'alter INDEX ' ||ds.owner|| '.' ||ds.segment_name|| ' rebuild tablespace GSJSSO;'
from dba_segments ds
where ds.tablespace_name  in ( 'JTTSSO' ) and ds.owner =  'GSJSSO'
and ds.segment_type =  'INDEX' ;

image

4.构建迁移LOB大对象SQL语句过程

1)查看GSJSSO用户在JTTSSO空间中的LOB对象,说明:LOB是造成不能成功通过导入来改变空间原因。只能采用如下方式。

1
2
3
4
5
6
7
8
9
10
col TABLESPACE_NAME  for  a20;
col DS.OWNER|| '.' ||DS.SEGMENT_NAME  for  a40;
col DATA_TYPE  for  a15;
select ds.tablespace_name,ds.owner|| '.' ||ds.segment_name,ds.segment_type,
dtc.DATA_TYPE,dtc.COLUMN_NAME
from dba_tab_columns dtc , dba_segments ds
where dtc.TABLE_NAME = ds.segment_name
and dtc.OWNER = ds.owner
and ds.tablespace_name  in  ( 'JTTSSO' )
and DATA_TYPE like  '%LOB' ;

image

2)构建迁移LOB大对象SQL语句

1
2
3
select   'alter table ' ||dtc.owner|| '.' ||dtc.TABLE_NAME|| ' move lob(' ||dtc.COLUMN_NAME|| ') store as(tablespace ' ||du.default_tablespace|| ');'
from dba_tab_columns dtc,dba_users du
where dtc.OWNER = du.username and dtc.OWNER  in ( 'GSJSSO' ) and dtc.DATA_TYPE like  '%LOB' ;

image

5.执行构建SQL语句迁移表,索引,LOB对象等数据

1)复制迁移表SQL语句在SQLPLUS中执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
alter table GSJSSO.ED_SEND_CONFIG move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_HOST move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_LOG move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_ORG move tablespace GSJSSO;
alter table GSJSSO.ED_SEND_CONFIG_USER move tablespace GSJSSO;
alter table GSJSSO.IDM_ROLE_MENU_ITEM move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_ADMIN_ROLE move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_ADMIN_USER move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_CONFIG move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_LOG move tablespace GSJSSO;
alter table GSJSSO.IDM_SYS_MENU move tablespace GSJSSO;
alter table GSJSSO.IDM_USER_ROLE move tablespace GSJSSO;
alter table GSJSSO.NET_PLATFORM_ORGANIZE_T move tablespace GSJSSO;
alter table GSJSSO.NET_PLATFORM_USER_T move tablespace GSJSSO;
alter table GSJSSO.PORTAL_ADAPTER move tablespace GSJSSO;
alter table GSJSSO.PORTAL_ADAPTER_RESOURCE move tablespace GSJSSO;
alter table GSJSSO.PORTAL_ADAPTER_RESOURCE_PRAM move tablespace GSJSSO;
alter table GSJSSO.PORTAL_SYS_ADMIN_USER move tablespace GSJSSO;
alter table GSJSSO.PORTAL_SYS_CONSTANTS move tablespace GSJSSO;
alter table GSJSSO.PORTAL_TEMPLATE_STYLE move tablespace GSJSSO;
alter table GSJSSO.PORTAL_TEMPLATE_USER move tablespace GSJSSO;
alter table GSJSSO.PORTAL_TEMPLATE_ZIP move tablespace GSJSSO;
alter table GSJSSO.PORTAL_USER_HEAD_PICTURE move tablespace GSJSSO;
alter table GSJSSO.PORTAL_USER_LOGIN move tablespace GSJSSO;
alter table GSJSSO.SSO_HOST move tablespace GSJSSO;
alter table GSJSSO.SSO_HOST_CONFIG move tablespace GSJSSO;
alter table GSJSSO.SSO_ORG move tablespace GSJSSO;
alter table GSJSSO.SSO_SESSION move tablespace GSJSSO;
alter table GSJSSO.SSO_USER move tablespace GSJSSO;
alter table GSJSSO.SYS_ADMIN_USER move tablespace GSJSSO;
alter table GSJSSO.SYS_CONFIG move tablespace GSJSSO;

2)复制迁移索引SQL语句在SQLPLUS中执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
alter INDEX GSJSSO.PK_ED_SEND_CONFIG rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_HOST rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_LOG rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_ORG rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_ED_SEND_CONFIG_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.ROLE_MENU rebuild tablespace GSJSSO;
alter INDEX GSJSSO.ID_PK rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_IDM_SYS_ADMIN_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.MENUID_PK rebuild tablespace GSJSSO;
alter INDEX GSJSSO.USER_ROLE rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005154 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005157 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005159 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005161 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005163 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_SYS_ADMIN_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_SYS_CONSTANTS rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_TEMPLATE_STYLE rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_TEMPLATE_USER rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005173 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_PORTAL_USER_LOGIN rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005181 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005189 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.SYS_C005193 rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_U rebuild tablespace GSJSSO;
alter INDEX GSJSSO.PK_SYS_ADMIN_USER rebuild tablespace GSJSSO;

3)复制迁移LOB对象SQL语句在SQLPLUS中执行。

1
2
alter table GSJSSO.PORTAL_USER_LOGIN move lob(DESCRIPTION) store  as (tablespace GSJSSO);
alter table GSJSSO.ED_SEND_CONFIG_LOG move lob(DETAIL) store  as (tablespace GSJSSO);

6.验证迁移后的结果

image

查询GSJSSO用户在JTTSSO表空间还有没有对象。

image

三、降权过程如下

1.查询GSJSSO用户权限,并赋予普通权限

image

2.查询GSJSSO表空间信息

image

3.取消DBA权限

image

image

4.赋予GSJSSO用户无限制使用GSJSSO表空间的权限

image

查看使用空间配额,如需要其它额外权限,可以直接赋予。

image

至此数据库调整完毕。


本文转自 koumm 51CTO博客,原文链接:http://blog.51cto.com/koumm/1314154,如需转载请自行联系原作者


相关文章
|
13天前
|
SQL Oracle 关系型数据库
【Oracle】玩转Oracle数据库(一):装上去,飞起来!
【Oracle】玩转Oracle数据库(一):装上去,飞起来!
55 7
|
1月前
|
Oracle 关系型数据库 数据库
Oracle数据库基本概念理解(3)
Oracle数据库基本概念理解(3)
18 2
|
13天前
|
SQL Oracle 关系型数据库
【Oracle】玩转Oracle数据库(七):RMAN恢复管理器
【Oracle】玩转Oracle数据库(七):RMAN恢复管理器
40 5
|
1月前
|
Oracle 关系型数据库 数据库
Oracle数据库基本概念理解(2)
Oracle数据库基本概念理解(2)
13 1
|
5天前
|
存储 Oracle 关系型数据库
Oracle的模式与模式对象:数据库的“城市规划师”
【4月更文挑战第19天】在Oracle数据库中,模式是用户对象的集合,相当于数据库的城市规划,包含表、视图、索引等模式对象。模式对象是数据存储结构,如表用于存储数据,视图提供不同查看角度,索引加速数据定位。良好的模式与模式对象设计关乎数据效率、安全和稳定性。规划时需考虑业务需求、性能、安全和可扩展性,以构建高效数据库环境,支持企业业务发展。
|
13天前
|
存储 SQL Oracle
【Oracle】玩转Oracle数据库(二):体系结构、存储结构与各类参数
【Oracle】玩转Oracle数据库(二):体系结构、存储结构与各类参数
35 7
|
1月前
|
Oracle 关系型数据库 数据库
Oracle数据库基本概念理解(1)
Oracle数据库基本概念理解(1)
13 1
|
5天前
|
关系型数据库 MySQL 分布式数据库
《MySQL 简易速速上手小册》第6章:MySQL 复制和分布式数据库(2024 最新版)
《MySQL 简易速速上手小册》第6章:MySQL 复制和分布式数据库(2024 最新版)
35 2
|
21天前
|
SQL 数据可视化 关系型数据库
轻松入门MySQL:深入探究MySQL的ER模型,数据库设计的利器与挑战(22)
轻松入门MySQL:深入探究MySQL的ER模型,数据库设计的利器与挑战(22)
105 0
|
21天前
|
存储 关系型数据库 MySQL
轻松入门MySQL:数据库设计之范式规范,优化企业管理系统效率(21)
轻松入门MySQL:数据库设计之范式规范,优化企业管理系统效率(21)

推荐镜像

更多