由impdp导入引起的oracle用户权限的问题

本文介绍了如何在Oracle数据库中迁移用户对象至新用户,并调整表空间分配,同时解决了迁移过程中产生的权限问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      根据业务要求需要将数据库上的TEST用户下的所有对象复制到一个新建的用户TEST2上,但不需要表数据。想到的办法是先用expdp的CONTENT=METADATA_ONLY参数导出元数据,然后使用impdp的remap_schema=TEST:TEST2来转换,完成业务要求。

      提交给业务部门后,又提出要求需要将TEST2业务表使用的表空间与索引表空间分配到指定表空间并分开。

使用如下策略完成:

      首先使用expdp将TEST2导出,命令如下:

      nohup expdp system/system directory=expdp schemas=test2 dumpfile=test0213.dmp logfile=test0213.log  &

      然后修改数据的表空间并排除索引导入,命令如下:

      nohup impdp system/system directory=expdp  dumpfile=test0213.dmp logfile=test0213_table.log remap_tablespace=TEST:TEST_DATA  schemas=TEST2 exclude=index &

      再修改索引的表空间并只导入索引,命令如下:

      nohup impdp system/system directory=expdp1  dumpfile=test0213.dmp logfile=test0213_index.log remap_tablespace=TEST:TEST_INDEX schemas=TEST2 include=index  &

     导入完成后通过dba_segments查看验证发现segment_type为index的tablespace仍难有为TEST的,进一步查看是因为该索引为数据库创建主键约束时自动创建的索引,使用下面的命令进行修改:

      ALTER INDEX INDEX_NAME REBUILD TABLESPACE TEST_INDEX;

      完成后提交给业务部门,结果又提出TEST2用户拥有查询TEST用户对象的权限,要求去除掉。

     经过验证核实,TEST只赋予了connect 以及resource权限,正常情况是不能访问其他用户的信息的,但该用户确实存在该种情况。

     通过查找user_role_privs(查看用户拥有的角色权限,如connect,resource),user_tab_privs(查看用户拥有 查询、修改其他用户的下指定的表权限),仍为发现异常。可以判断问题出在以TEST用户导出时默认将该用户的权限信息导出,而导入时又将该权限赋予了新用户TEST2,导致TEST2拥有一些特殊权限。

     使用plsql develop工具查看TEST2用户的创建语句,发现有大量权限赋予,其中保护grant select any table权限,从而导致其拥有查询其他用户的权限,权限信息如下:

grant administer any sql tuning set to TEST2;
grant administer database trigger to TEST2;
grant administer sql management object to TEST2;
grant administer sql tuning set to TEST2;
grant advisor to TEST2;
grant alter any assembly to TEST2;
grant alter any cluster to TEST2;
grant alter any cube to TEST2;
grant alter any cube dimension to TEST2;
grant alter any dimension to TEST2;
grant alter any edition to TEST2;
grant alter any index to TEST2;
grant alter any indextype to TEST2;
grant alter any library to TEST2;
grant alter any materialized view to TEST2;
grant alter any mining model to TEST2;
grant alter any operator to TEST2;
grant alter any outline to TEST2;
grant alter any procedure to TEST2;
grant alter any role to TEST2;
grant alter any sequence to TEST2;
grant alter any sql profile to TEST2;
grant alter any table to TEST2;
grant alter any trigger to TEST2;
grant alter any type to TEST2;
grant alter database to TEST2;
grant alter profile to TEST2;
grant alter resource cost to TEST2;
grant alter rollback segment to TEST2;
grant alter session to TEST2;
grant alter system to TEST2;
grant alter tablespace to TEST2;
grant alter user to TEST2;
grant analyze any to TEST2;
grant audit any to TEST2;
grant audit system to TEST2;
grant backup any table to TEST2;
grant become user to TEST2;
grant change notification to TEST2;
grant comment any mining model to TEST2;
grant comment any table to TEST2;
grant create any assembly to TEST2;
grant create any cluster to TEST2;
grant create any context to TEST2;
grant create any cube to TEST2;
grant create any cube build process to TEST2;
grant create any cube dimension to TEST2;
grant create any dimension to TEST2;
grant create any directory to TEST2;
grant create any edition to TEST2;
grant create any index to TEST2;
grant create any indextype to TEST2;
grant create any job to TEST2;
grant create any library to TEST2;
grant create any materialized view to TEST2;
grant create any measure folder to TEST2;
grant create any mining model to TEST2;
grant create any operator to TEST2;
grant create any outline to TEST2;
grant create any procedure to TEST2;
grant create any sequence to TEST2;
grant create any sql profile to TEST2;
grant create any synonym to TEST2;
grant create any table to TEST2;
grant create any trigger to TEST2;
grant create any type to TEST2;
grant create any view to TEST2;
grant create assembly to TEST2;
grant create cluster to TEST2;
grant create cube to TEST2;
grant create cube build process to TEST2;
grant create cube dimension to TEST2;
grant create database link to TEST2;
grant create dimension to TEST2;
grant create external job to TEST2;
grant create indextype to TEST2;
grant create job to TEST2;
grant create library to TEST2;
grant create materialized view to TEST2;
grant create measure folder to TEST2;
grant create mining model to TEST2;
grant create operator to TEST2;
grant create procedure to TEST2;
grant create profile to TEST2;
grant create public database link to TEST2;
grant create public synonym to TEST2;
grant create role to TEST2;
grant create rollback segment to TEST2;
grant create sequence to TEST2;
grant create session to TEST2;
grant create synonym to TEST2;
grant create table to TEST2;
grant create tablespace to TEST2;
grant create trigger to TEST2;
grant create type to TEST2;
grant create user to TEST2;
grant create view to TEST2;
grant debug any procedure to TEST2;
grant debug connect session to TEST2;
grant delete any cube dimension to TEST2;
grant delete any measure folder to TEST2;
grant delete any table to TEST2;
grant drop any assembly to TEST2;
grant drop any cluster to TEST2;
grant drop any context to TEST2;
grant drop any cube to TEST2;
grant drop any cube build process to TEST2;
grant drop any cube dimension to TEST2;
grant drop any dimension to TEST2;
grant drop any directory to TEST2;
grant drop any edition to TEST2;
grant drop any index to TEST2;
grant drop any indextype to TEST2;
grant drop any library to TEST2;
grant drop any materialized view to TEST2;
grant drop any measure folder to TEST2;
grant drop any mining model to TEST2;
grant drop any operator to TEST2;
grant drop any outline to TEST2;
grant drop any procedure to TEST2;
grant drop any role to TEST2;
grant drop any sequence to TEST2;
grant drop any sql profile to TEST2;
grant drop any synonym to TEST2;
grant drop any table to TEST2;
grant drop any trigger to TEST2;
grant drop any type to TEST2;
grant drop any view to TEST2;
grant drop profile to TEST2;
grant drop public database link to TEST2;
grant drop public synonym to TEST2;
grant drop rollback segment to TEST2;
grant drop tablespace to TEST2;
grant drop user to TEST2;
grant execute any assembly to TEST2;
grant execute any class to TEST2;
grant execute any indextype to TEST2;
grant execute any library to TEST2;
grant execute any operator to TEST2;
grant execute any procedure to TEST2;
grant execute any program to TEST2;
grant execute any type to TEST2;
grant execute assembly to TEST2;
grant export full database to TEST2;
grant flashback any table to TEST2;
grant flashback archive administer to TEST2;
grant force any transaction to TEST2;
grant force transaction to TEST2;
grant global query rewrite to TEST2;
grant grant any object privilege to TEST2;
grant grant any privilege to TEST2;
grant grant any role to TEST2;
grant import full database to TEST2;
grant insert any cube dimension to TEST2;
grant insert any measure folder to TEST2;
grant insert any table to TEST2;
grant lock any table to TEST2;
grant manage scheduler to TEST2;
grant manage tablespace to TEST2;
grant merge any view to TEST2;
grant on commit refresh to TEST2;
grant query rewrite to TEST2;
grant restricted session to TEST2;
grant resumable to TEST2;
grant select any cube to TEST2;
grant select any cube dimension to TEST2;
grant select any mining model to TEST2;
grant select any sequence to TEST2;
grant select any table to TEST2;
grant select any transaction to TEST2;
grant under any table to TEST2;
grant under any type to TEST2;
grant under any view to TEST2;
grant update any cube to TEST2;
grant update any cube build process to TEST2;
grant update any cube dimension to TEST2;
grant update any table to TEST2;


解决办法:使用dba用户进行权限收回,命令如下:

revoke administer any sql tuning set from  TEST2;
revoke administer database trigger from TEST2;
revoke administer sql management object from TEST2;


至此,终于完成业务要求,也顺便将该次碰到的问题及解决思路汇总。

<think>嗯,用户在使用Oracleimpdp导入数据时遇到了问题,因为用户名不同导致存储过程报错。我需要仔细分析这个问题,并给出解决方案。首先,我得回忆一下impdp的基本机制。impdp导入的时候,默认情况下存储过程、函数等对象是归属于导出时的用户的,即使导入到不同的用户下,对象的拥有者可能还是原来的用户,这会导致权限问题或者引用错误。然后,用户提到用户名不一致,所以可能需要使用remap_schema参数来重新映射模式。比如,从原用户A导出,导入用户B,就需要remap_schema=A:B。这样可以确保对象的所有权转移到新用户。但可能存在存储过程中有硬编码的原用户名,这时候即使模式映射了,存储过程里的引用可能还是指向原用户,导致报错。这时候可能需要进一步的修改,比如重新编译存储过程或者替换代码中的用户名。 另外,impdp的transform参数可能有用,特别是transform=oid:n,这样可以让对象使用新的OID,避免与原用户冲突。还有,检查导入时是否使用了正确的权限,比如是否有足够的权限创建或替换存储过程。可能需要赋予新用户相应的系统权限,如CREATEANY PROCEDURE,或者直接授予DBA角色,但要注意安全性问题。 还要考虑存储过程中是否有依赖其他对象,如表或视图,这些对象是否也被正确导入到新用户下。如果依赖对象没有正确映射,也会导致存储过程报错。需要确保所有相关的对象都通过remap_schema或者其他参数正确转移。 用户可能已经尝试过remap_schema,但仍有问题,可能需要更详细的步骤,比如在导入命令中明确指定转换参数,或者在导入后执行脚本来修改存储过程的定义。另外,查看导入日志和alert日志,确认具体的错误信息,有助于定位问题,比如权限不足、对象不存在等。 总结下来,解决方案可能包括:使用remap_schema映射模式,使用transform参数处理对象OID,导入后重新编译存储过程,检查并修改存储过程中的硬编码用户名,以及确保依赖对象正确导入。同时,提醒用户导入前检查导出文件的元数据,确认原用户信息,并在导入后验证对象的属性和依赖关系。</think>### 解决方案:Oracle impdp导入用户名不同导致存储过程报错的处理方法 #### 1. **使用`REMAP_SCHEMA`参数映射用户** - 在`impdp`命令中明确指定原用户与新用户的映射关系,例如原用户`A`导入到新用户`B`: ```bash impdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp REMAP_SCHEMA=A:B ``` 此操作会将存储过程、表等对象的属主从`A`自动改为`B`[^3]。 #### 2. **处理存储过程代码中的硬编码用户** - **问题原因**:若存储过程中存在类似`A.TABLE_NAME`的硬编码引用,即使映射了用户,仍会因对象路径错误报错。 - **解决方法**: - **导入后修改代码**:手动修改存储过程中的用户名引用为`B`。 - **动态替换**:在导入时使用`sqlfile`参数生成SQL脚本,批量替换用户名后执行: ```bash impdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp SQLFILE=replace_script.sql ``` #### 3. **使用`TRANSFORM`参数调整对象属性** - 添加`TRANSFORM=OID:N`参数,避免因对象OID冲突导致权限问题: ```bash impdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp REMAP_SCHEMA=A:B TRANSFORM=OID:N ``` 此操作会为新用户生成新的对象标识符[^2]。 #### 4. **检查依赖对象权限** - **问题场景**:若存储过程依赖其他用户的对象(如`C.TABLE_NAME`),需为新用户`B`授权: ```sql GRANT SELECT ON C.TABLE_NAME TO B; ``` - **导入后操作**:重新编译失效的存储过程: ```sql ALTER PROCEDURE B.PROCEDURE_NAME COMPILE; ``` #### 5. **验证导出文件的元数据** - 通过`expdp`导出时添加`FULL=Y`参数确保所有依赖关系完整: ```bash expdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp FULL=Y ``` - 导入前检查导出文件内容: ```bash impdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp SQLFILE=metadata.sql ``` #### 6. **日志分析与错误定位** - 查看`impdp`日志文件及数据库`alert.log`,定位具体报错(如权限不足或表空间问题)[^2]: ```sql -- 查询alert日志路径 SHOW PARAMETER BACKGROUND_DUMP_DEST; ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值