Professional Documents
Culture Documents
SCHEMA REFRESH
SCHEMA REFRESH is a regular job for DBA’s. 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.
Send the full export backup .dmp file to target server.
Create the schema with default tablespace and allocate quota.
Make required roles & privileges for the schema.
Connect to user 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.
If the schema is already existing on the target database server, then take export backup of existing
schema from the target database. After that you can drop it and recreate the schema.
$ hostname -i
192.168.1.130
$ ping 192.168.1.131
PING 192.168.1.131 (192.168.1.131) 56(84) bytes of data.
64 bytes from 192.168.1.131: icmp_seq=0 ttl=64 time=4.10 ms
64 bytes from 192.168.1.131: icmp_seq=1 ttl=64 time=0.156 ms
64 bytes from 192.168.1.131: icmp_seq=2 ttl=64 time=0.216 ms
...
$ hostname –i
192.168.1.131
$ ping 192.168.1.130
PING 192.168.1.130 (192.168.1.130) 56(84) bytes of data.
64 bytes from 192.168.1.130: icmp_seq=0 ttl=64 time=15.2 ms
64 bytes from 192.168.1.130: icmp_seq=1 ttl=64 time=0.263 ms
64 bytes from 192.168.1.130: icmp_seq=2 ttl=64 time=0.134 ms
...
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.
SHAM SEQUENCE 2
SHAM SYNONYM 1
SHAM TABLE 12
SHAM TABLE PARTITION 3
SHAM TRIGGER 2
SHAM VIEW 1
SHAM DATABASE LINK 1
12 rows selected.
36 rows selected.
14 rows selected.
10 rows selected.
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
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
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8MSWIN1252 character set (possible charset conversion)
$ gzip refresh_sham.dmp
$ scp refresh_sham.dmp.gz roles_privs.sql oracle@192.168.1.131:$HOME
oracle@192.168.1.131's password:
refresh_sham.dmp.gz
$ gunzip refresh_sham.dmp.gz
$ ls refresh*
refresh_sham.dmp
Before drop the schema from the target database, take export backup of the schema.
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 won’t allow directly to drop parents table. Let’s 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.
SYS>@roles_privs.sql;
roles_privs.sql
By executing above script we can assign all privileges to the new user as per source database.
you can do them manually.
$ 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
If the schema made any object privilege to other users in the source database, you have to assign
the same privilege to the user in target database. You must create the user in target database.
In source database, you can get information using following sql statement.
** 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.