一个用户被授予resource角色时,会自动把unlimited tablespace系统权限给用户,这个权限有潜在风险,一般情况下我们需要把这个系统权限回收,并用表空间限额的方式限制用户对表空间的使用权限。
但是,在数据泵的导出导入过程中,可能破坏这个权限控制。
1、首先创建用户及设置权限
suk@ORA10G> create tablespace a datafile 'E:\ORACLE\ORADATA\ORA10G\a.dbf' size 50m;
表空间已创建。
suk@ORA10G> create tablespace b datafile 'E:\ORACLE\ORADATA\ORA10G\b.dbf' size 50m;
表空间已创建。
suk@ORA10G> create user a identified by a default tablespace a;
用户已创建。
suk@ORA10G> create user b identified by b default tablespace b;
用户已创建。
suk@ORA10G> grant connect,resource to a;
授权成功。
suk@ORA10G> grant connect,resource to b;
授权成功。
suk@ORA10G> revoke unlimited tablespace from a;
撤销成功。
suk@ORA10G> revoke unlimited tablespace from b;
撤销成功。
suk@ORA10G> alter user a quota unlimited on a;
用户已更改。
suk@ORA10G> alter user b quota unlimited on b;
用户已更改。
suk@ORA10G> select * from dba_sys_privs where grantee='A';
未选定行
suk@ORA10G> select * from dba_sys_privs where grantee='B';
未选定行
suk@ORA10G> grant read,write on directory data_pump_dir to a;
授权成功。
suk@ORA10G> grant read,write on directory data_pump_dir to b;
授权成功。
suk@ORA10G> conn a/a@space:1522/ora10g
已连接。
a@ORA10G> create table t as select * from all_objects;
表已创建。
a@ORA10G> select segment_name,tablespace_name from user_segments;
SEGMENT_NAME
TABLESPACE_NAME
------------------------------ ------------------------------
T
A
2、用数据泵导出数据,并导入同一个库的另外一个用户下
--导出
E:\oracle\ora10g\BIN>expdp suk/suk dumpfile=a.dp schemas=a directory=data_pump_dir
Export: Release 10.2.0.1.0 - Production on 星期四, 17 1月, 2008 23:37:53
Copyright (c) 2003, 2005, Oracle.All rights reserved.
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
启动 "SUK"."SYS_EXPORT_SCHEMA_01":suk/******** dumpfile=a.dp schemas=a directo
ry=data_pump_dir
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 512 KB
处理对象类型 SCHEMA_EXPORT/USER
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/TABLESPACE_QUOTA
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA
. . 导出了 "A"."T"
400.7 KB4527 行
已成功加载/卸载了主表 "SUK"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
SUK.SYS_EXPORT_SCHEMA_01 的转储文件集为:
E:\ORACLE\ADMIN\ORA10G\DPDUMP\A.DP
作业 "SUK"."SYS_EXPORT_SCHEMA_01" 已于 23:38:03 成功完成
--导入
E:\oracle\ora10g\BIN>impdp suk/suk dumpfile=a.dp schemas=a directory=data_pump_dir REMAP_SCHEMA=a:b
Import: Release 10.2.0.1.0 - Production on 星期四, 17 1月, 2008 23:38:39
Copyright (c) 2003, 2005, Oracle.All rights reserved.
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
已成功加载/卸载了主表 "SUK"."SYS_IMPORT_SCHEMA_01"
启动 "SUK"."SYS_IMPORT_SCHEMA_01":suk/******** dumpfile=a.dp schemas=a directo
ry=data_pump_dir REMAP_SCHEMA=a:b
处理对象类型 SCHEMA_EXPORT/USER
ORA-31684: 对象类型 USER:"B" 已存在
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/TABLESPACE_QUOTA
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
. . 导入了 "B"."T"
400.7 KB4527 行
处理对象类型 SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA
作业 "SUK"."SYS_IMPORT_SCHEMA_01" 已经完成, 但是有 1 个错误 (于 23:38:44 完成)
--检查当前权限
suk@ORA10G> select * from dba_sys_privs where grantee='A';
未选定行
suk@ORA10G> select * from dba_sys_privs where grantee='B';
GRANTEE
PRIVILEGE
ADM
------------------------------ ---------------------------------------- ---
B
UNLIMITED TABLESPACE
NO
--可以发现,B用户多了UNLIMITED TABLESPACE权限
--导入B用户的T表的表空间也在A用户下
suk@ORA10G> select owner,segment_name,tablespace_name from dba_segments where owner='B' and segment_name='T';
OWNER
SEGMENT_NAME
TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
B
T
A
suk@ORA10G> drop table b.t purge;
表已删除。
suk@ORA10G> revoke unlimited tablespace from b;
撤销成功。
3、重新导入,加上REMAP_TABLESPACE参数
E:\oracle\ora10g\BIN>impdp suk/suk dumpfile=a.dp schemas=a directory=data_pump_dir REMAP_SCHEMA=a:b REMAP_TABLESPACE=a:b
Import: Release 10.2.0.1.0 - Production on 星期四, 17 1月, 2008 23:42:18
Copyright (c) 2003, 2005, Oracle.All rights reserved.
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
已成功加载/卸载了主表 "SUK"."SYS_IMPORT_SCHEMA_01"
启动 "SUK"."SYS_IMPORT_SCHEMA_01":suk/******** dumpfile=a.dp schemas=a directo
ry=data_pump_dir REMAP_SCHEMA=a:b REMAP_TABLESPACE=a:b
处理对象类型 SCHEMA_EXPORT/USER
ORA-31684: 对象类型 USER:"B" 已存在
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/TABLESPACE_QUOTA
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
. . 导入了 "B"."T"
400.7 KB4527 行
处理对象类型 SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA
作业 "SUK"."SYS_IMPORT_SCHEMA_01" 已经完成, 但是有 1 个错误 (于 23:42:21 完成)
--检查当前权限
suk@ORA10G> select * from dba_sys_privs where grantee='A';
未选定行
suk@ORA10G> select * from dba_sys_privs where grantee='B';
GRANTEE
PRIVILEGE
ADM
------------------------------ ---------------------------------------- ---
B
UNLIMITED TABLESPACE
NO
suk@ORA10G> select owner,segment_name,tablespace_name from dba_segments where owner='B' and segment_
name='T';
OWNER
SEGMENT_NAME
TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
B
T
B
--可以发现,加上REMAP_TABLESPACE参数,B用户仍然多了UNLIMITED TABLESPACE权限,但是B.T所在表空间已经在B表空间上了。
出现这个问题的原因是SCHEMA_EXPORT/ROLE_GRANT给用户授予了resource角色,把UNLIMITED TABLESPACE 带过来了,所以我们迁移完数据库一定要检查用户的权限,把有潜在危险的系统权限去掉。
|