Sunteți pe pagina 1din 16

Schema Refresh

Over View
To copy all the SOURCE schema objects to
respective TARGET schema based on the
client’s request. We perform Schema
Refreshes only if Schema is less than 10 Gb.
From one schema to same schema on the same
database.
From one schema to another schema in the same
Database.
From one schema in one database to another schema
of a database on the same machine.
From one schema of a database to another schema of
a database on a separate machine
1 Refresh Process

1.1 Source
Server name, Database name, and SOURCE Schema

1.2 Target
Server name, Database name and TARGET Schema

1.3 Steps
The following are the sequence of steps to be followed to complete the
task :-
 Pre Export tasks on the Source Schema

• Review the source & target DB Tablespace Sizes prior starting compare if
they are near each other in size
• If not similar in size add additional space for Tablespace Target
 Export of the Source Schema
 Backup of the Target Schema
 Pre Import tasks on Target Schema
 Dropping of objects in Target Schema
 Import into Target Schema
 Post Import tasks (recompiling , statistics etc).
2 Detailed Process

2.1 Steps for Source Schema

1.Find out total objects in the schema and their status.

SQL> select object_type, status, count(*)


from dba_objects
where owner=’SOURCE-SCHEMA’ group by object_type, status;

2. Find out status of the constraints in the schema.

SQL> select constraint_type, status, count(*)


from dba_constraints
where owner=' SOURCE-SCHEMA '
group by constraint_type, status;
1. Review the source & target DB Tablespace Sizes prior starting
compare if they are near each other in size

If not similar in size add additional space for Tablespace Target

4. Find out the total space occupied by the Schema objects.

SQL> select sum(bytes)/1024/1024


from dba_segments
where owner='SOURCE-SCHEMA';

5. Export the schema into the following directory.

/servername/exp01/DBName (in general for all servers)


/oraexp01/DBName (for dog* servers).

(FORMAT : exp_dbname_schema_ddMMMyy.dmp
exp_gemsora15d_PRD_07june05.dmp)
Log file: exp_gemsora15d_PRD_07june05.log
$ exp file= exp_dbname_schema_ddMMMyy.dmp
log=exp_dbname_schema_ddMMMyy.log owner=SOURCE- schema
Compress=n buffer=1024000 consistent=y statistics=y

 If the file is big, to take the export in compressed


format, follow the process mentioned below:

$ mknod pipe.dmp p
$ nohup /usr/bin/gzip -cNf < pipe.dmp > filename.gz &
$ nohup exp userid=system/paswd file= pipe.dmp
log= filename.log owner=SOURCE schema(s)
compress=n buffer=10240000 recordlength= 65535 direct=y statistics=y

 The export should complete without errors or


warnings.
If you think the export / import will take a long time, fire it in
nohup mode and use a script. Also have a command in the
script to mail you once the export/import is over

tail -1 <filename.log>|mailx –s “Export of <Schema> on <Database> is over“


dbaodcebiz@med.ge.com

2.2 Steps for TARGET Schema.

6. In order to find out the availability of sufficient space available


to import the source schema. Find out the size of the
TARGET schema.
SQL> select sum(bytes)/1024/1024
from dba_segments
where owner='TARGET-SCHEMA';
7. Backup the schema if the size is less than 2 GB (logical
backup). If the backup size is more than 2GB and full database
backup exists, then backup need not be taken
8. Drop all the tables in the TARGET SCHEMA .
SQL> spool drop_tab.sql
SQL> select 'drop table TARGET-SCHEMA. ‘|| table_name||' cascade
constraints;'
from dba_tables
where owner=' TARGET-SCHEMA ';
SQL> spool off
SQL> @drop_tab.sql

9. Drop all the other objects from the TARGET SCHEMA


SQL> spool drop_obj.sql
SQL> select 'drop'|| object_type ||' TARGET-SCHEMA.'|| object_name||';'
From dba_objects
where owner=' TARGET-SCHEMA
SQL> spool off
SQL> @drop_obj.sql

10. Import into the target schema using the export dump taken at Step 3
above.

$ imp file=……dmp userid=system/passwd log=… fromuser= S1,S2


touser =T1,T2 buffer=20480000 commit=y statistics=y

$ mknod /tmp/imp_pipe.dmp p
$ gunzip -c <filename.dmp.gz > /tmp/imp_pipe.dmp &
$ nohup imp userid=system/paswd file=/tmp/imp_pipe.dmp
fromuser =S1,S2 touser =T1,T2 log =filename.log buffer =20480000
commit =y statistics=y resumable=y … (only Oracle 9i)
Important Note:

 In case of multi schema export the parameters for


FROMUSER and TOUSER should be given in order (i.e. 1 -- 1
correspondence should be maintained).

 It is better to give resumable=y, which helps to increase the


Size of TS, in case of insufficient space (only from Oracle 9i).

11. If the indexes are in the same tablespace as the


tables, then rebuild the indexes into the index
tablespace using the rebuild.. tablespace clause
while rebuild.
SQL> spool idx.sql
SQL> select 'alter index schema.'||index_name||' rebuild;'
from dba_indexes where owner = SCHEMA';
SQL> spool off
SQL> @idx.sql

12. Recompile the procedures etc…(if required)


SQL> @?/rdbms/admin/utlrp.sql)
3 Verification

Do not perform Schema Refreshes over 10 Gb.


Verify whether the schema is imported properly.
Verify whether all the objects are imported properly as per the
i. SOURCE SCHEMA.
Note: Compare and verify the objects with the statistics collected
from (step 1, step 2 and step 3.)
Verify the indexes and if they are in the DATA Tablespace,
then rebuild them in the INDEX Tablespace.
Verify for invalid objects. If possible try to re-compile
procedures and views etc.

(Note: run @?/rdbms/admin/utlrp.sql)


4 Checklist
4.1 Source Schema
Obtain the Server Name, Database Name for the SOURCE and TARGET
Schema .
Take count of the total objects by object type and status in the source
schema
Take the total size of the SOURCE schema … (in MB/GB).
Do not perform Schema Refreshes over 10 Gb.
Take export of the schema(s) and place the dmp and log files in *respective
directory in the SOURCE database server following the naming conventions
as follows.
dmp file : exp_DBName_Schema_ddMMMMyy.dmp
log file : exp_DBName_Schema_ddMMMMyy.log

*
/servername/exp01/DBName (in general for all servers)
/oraexp01/DBName (for dog* servers).
Note: The export activity should be completed as normal and without any
warnings .
 Copy the export dmp and log files to the above mentioned respective database
directory (through ftp / scp) to the target machine.
 We do not perform Schema Refreshes over 10 Gb.

4.2 Target Schema


Export the schema dmp and log files into * respective directory in the TARGET
schema database directory using naming conventions for the dmp and log files. (i.e.
exp_DBName_Schema_ddMMMMyy.dmp ).
exp_DBName_Schema_ddMMMMyy.log )
*Directories
/servername/exp01/DBName (in general for all servers)
oraexp01/DBName (for dog* servers).

Drop all the tables from the TARGET schema.

Drop all the other objects from the TARGET schema .


Import the dmp file (STEP 5) which was copied into the DB Directory.
Compare and verify the objects with the statistics collected from above (step 1,step 2
and step 3)
Rebuild the indexes and other invalid objects (if required).

All the objects of the SOURCE schema should be present in the


current TARGET schema along with indexes and constraints that are
contained in the Source schema.

Do not perform Schema Refreshes over 10 Gb.

S-ar putea să vă placă și