Difference between revisions of "(Re)create user/schema using DataPump"
| (6 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | If the user does not yet exist on the destination database, just import it using the procedure outlined [[ | + | Remember, one thing Datapump doesn't do (by design) is recreate grants to objects owned by SYS.<br /><br /> |
| − | + | If the user does not yet exist on the destination database, just import it using the procedure outlined [[Data Pump|here]].<br /> | |
| + | Or if you are asked to create a user 'like' another user, use this: | ||
| + | <pre> | ||
| + | $ expdp schemas=CURRENTUSER content=metadata_only | ||
| + | $ impdp remap_schema=CURRENTUSER:NEWUSER | ||
| + | </pre> | ||
If however, the user(schema) already exists, it will have to be dropped and re-created before the data can be imported.<br /> | If however, the user(schema) already exists, it will have to be dropped and re-created before the data can be imported.<br /> | ||
| − | + | Run [[Extract ddl with "dbms metadata.get ddl"#Get User DDL with related grants|this script]] to generate the recreation DDL<br /> | |
| − | + | After this has been run, the following command can be executed: | |
| − | + | <pre> | |
| − | + | drop user <schema name> cascade; | |
| − | + | </pre> | |
| − | The | + | Now, recreate the schema with the above-mentioned DDL<br /> |
| − | + | The dumpfile (or a part thereof) can now be imported to fill up the currently empty schema: | |
| − | + | <pre> | |
| − | + | impdp <usr>/<pwd> parfile=schema.par | |
| + | </pre> | ||
where schema.par would look like this: | where schema.par would look like this: | ||
| − | + | <pre> | |
| − | + | directory=DATA_PUMP_DIR | |
| + | dumpfile=<schema_name>.DMP | ||
| + | schemas=(<schema_name>) | ||
| + | </pre> | ||
| + | and/or maybe one or more of the following: | ||
| + | <pre> | ||
| + | exclude=grants | ||
| + | tables=(<schema_name>.<table_name>) | ||
| + | remap_tablespace=old:new | ||
| + | </pre> | ||
Finally, recompile all invalid objects: | Finally, recompile all invalid objects: | ||
| − | + | <pre> | |
| − | + | exec utl_recomp.recomp_serial(); | |
| − | + | or | |
| − | + | exec utl_recomp.recomp_parallel(4); | |
| − | + | or | |
| − | + | @?\rdbms\admin\utlrp.sql | |
| − | + | or | |
| + | @?\rdbms\admin\utlprp.sql(4) | ||
| + | </pre> | ||
Latest revision as of 12:01, 13 November 2013
Remember, one thing Datapump doesn't do (by design) is recreate grants to objects owned by SYS.
If the user does not yet exist on the destination database, just import it using the procedure outlined here.
Or if you are asked to create a user 'like' another user, use this:
$ expdp schemas=CURRENTUSER content=metadata_only $ impdp remap_schema=CURRENTUSER:NEWUSER
If however, the user(schema) already exists, it will have to be dropped and re-created before the data can be imported.
Run this script to generate the recreation DDL
After this has been run, the following command can be executed:
drop user <schema name> cascade;
Now, recreate the schema with the above-mentioned DDL
The dumpfile (or a part thereof) can now be imported to fill up the currently empty schema:
impdp <usr>/<pwd> parfile=schema.par
where schema.par would look like this:
directory=DATA_PUMP_DIR dumpfile=<schema_name>.DMP schemas=(<schema_name>)
and/or maybe one or more of the following:
exclude=grants tables=(<schema_name>.<table_name>) remap_tablespace=old:new
Finally, recompile all invalid objects:
exec utl_recomp.recomp_serial(); or exec utl_recomp.recomp_parallel(4); or @?\rdbms\admin\utlrp.sql or @?\rdbms\admin\utlprp.sql(4)