Escolar Documentos
Profissional Documentos
Cultura Documentos
SCHEMA REFRESH
SCHEMA REFRESH is a regular job for DBAs. So I decide to prepare an informative document for
schema refresh. We can achieve schema refresh in two ways, they are
Find the roles & privileges that are assigned to the schema.
Capture source database schema objects count.
Export database schema using EXP/EXPDP utility.
Drop the schema in the production database except DBLINK.
Recreate the schema with default tablespace and allocate quota.
Make required roles & privileges for the schema.
Connect to SHAM and ensure default tablespace, roles and privileges.
Import the dump file using IMP/IMPDP into the target database.
Recompile invalid objects.
Gather schema statistics after the refresh.
Refreshing sham schema on crms database. Source and destination database is same. Lets start.
OWNER SIZE in GB
------- ----------
SHAM 40.35
TABLESPACE_NAME
----------------
TBS1 TBS2 TBS3 USERS
TABLESPACE_NAME Size in GB
------------------------------ ----------
TBS1 9.062
TBS2 6.048
TBS3 8. 82
USERS 16. 42
Quota is the amount of space allocated to a user in a tablespace. In dba_ts_quotas view, MAXBYTES
column value of -1 indicates UNLIMITED, means that user can use as much space in that tablespace.
9 rows selected.
12 rows selected.
36 rows selected.
14 rows selected.
10 rows selected.
PASSWORD
-----------------
8657483259C22FDE
Export the schema from the crms database with the name of the file as refresh_sham.dmp
$ export ORACLE_SID=crms
$ exp system/manager file=refresh_sham.dmp log=schema_refresh_sham.log owner=sham direct=y
statistics=none
..
...
[Trimmed]
Export terminated successfully without warnings.
EX : SYS>@roles_privs.sql;
Script grants the roles and privileges to the user obtained before dropping it.
Connect to the user and verify allocated tablespaces, roles and privileges.
** Before drop all the objects in that Schema, connect the schema and Spool the output.
POINTS TO NOTE
Suppose if you want to remove tables manually first you have to delete child tables otherwise
oracle wont allow directly to drop parents table. Lets see.
While dropping tables manually we can see ORA-02449 error. Use the below query to find reference
key constraints and drop the tables first.
CONSTRAINT_NAME C TABLE_NAME
------------------------------ - ------------------------------
EMP_PRJ_INFO_EMPID_C5_FK R EMP_PROJ_INFO
PAYROLL_EMPID_C7_FK R PAYROLL
TRNSPRT_PRJID_C10_FK R TRANSPORT
EMP_PERS_INFO_EID_C6_FK R EMP_PERS_INFO
RECREATE THE USER WITH DEFAULT TABLESPACE , TEMPORARY TABLESPACE & QUOTAS
User created.
** Sham user has default profile. If you have specific profile name for the user add it.
SYS>@roles_privs.sql;
roles_privs.sql
$ export ORACLE_SID=crms
$ imp system/manager file=refresh_sham.dmp log=refresh_sham_imp.log fromuser=sham touser=sham
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
import done in US7ASCII character set and AL16UTF16 NCHAR character set
** Schema object count should be same before export and after import.
SYS> @?/rdbms/admin/utlrp.sql;
Check the privileges, tablespace quotas, and dblinks for that the schema. This is essential.
NO. If the schema received grant privilege from others does NOT get export when you export the
schema. So, it does NOT get import when you import the schema.