Advertisement
account-confirmatio

wawawa

Jan 10th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. To transfer everything from an old user to a new user in Oracle without manually specifying each table name, you can use Oracle's Data Pump export and import utilities (`expdp` and `impdp`). These utilities allow you to export and import entire schemas, which include tables, views, procedures, and other schema objects, without the need to list each object individually.
  2.  
  3. Here's a general outline of the steps:
  4.  
  5. 1. **Export the Entire Schema**: Use Data Pump's `expdp` utility to export the entire schema of the old user. This can be done using a command like:
  6.  
  7. ```shell
  8. expdp old_user/password@db DIRECTORY=your_directory DUMPFILE=old_user.dmp SCHEMAS=old_user
  9. ```
  10.  
  11. - Replace `old_user`, `password`, and `db` with the old user's credentials and database.
  12. - `DIRECTORY` should be an Oracle directory object that points to a physical directory on the server.
  13. - `DUMPFILE` is the name of the file that will be created.
  14.  
  15. 2. **Create the New User**: If the new user doesn't already exist, create it in the Oracle database.
  16.  
  17. ```sql
  18. CREATE USER new_user IDENTIFIED BY new_password;
  19. GRANT CONNECT, RESOURCE TO new_user;
  20. ```
  21.  
  22. 3. **Import the Schema into the New User**: Use Data Pump's `impdp` utility to import the dump file into the new user's schema.
  23.  
  24. ```shell
  25. impdp new_user/new_password@db DIRECTORY=your_directory DUMPFILE=old_user.dmp REMAP_SCHEMA=old_user:new_user
  26. ```
  27.  
  28. - `REMAP_SCHEMA` option remaps the old user to the new user.
  29.  
  30. 4. **Verify and Correct Any Issues**: After the import, you should verify that all objects have been transferred correctly and rectify any issues that might arise.
  31.  
  32. 5. **Recompile Invalid Objects**: Sometimes, after import, some objects might be invalid. Use the following command to recompile invalid objects:
  33.  
  34. ```sql
  35. EXEC DBMS_UTILITY.compile_schema(schema => 'new_user');
  36. ```
  37.  
  38. 6. **Transfer Additional Privileges**: If the old user had specific privileges or roles granted, you would need to grant these to the new user manually.
  39.  
  40. This process should transfer most of the schema-related objects. However, remember that certain database-specific settings or roles outside the schema level won't be transferred and must be handled separately. Also, ensure you have proper backups before performing such operations.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement