schema refresh

Upload: shibueratt

Post on 10-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Schema Refresh

    1/16

    Schema RefreshSchema Refresh

  • 8/8/2019 Schema Refresh

    2/16

    Over ViewOver View

    To copy all the SOURCE schema objects toTo copy all the SOURCE schema objects torespective TARGET schema based on therespective TARGET schema based on theclients request. We perform Schemaclients request. We perform SchemaRefreshes only if Schema is less than 10 Gb.Refreshes only if Schema is less than 10 Gb.

    From one schema to same schema on the sameFrom one schema to same schema on the samedatabase.database.

    From one schema to another schema in the sameFrom one schema to another schema in the sameDatabase.Database.

    From one schema in one database to another schemaFrom one schema in one database to another schemaof a database on the same machine.of a database on the same machine.

    From one schema of a database to another schema ofFrom one schema of a database to another schema ofa database on a separate machinea database on a separate machine

  • 8/8/2019 Schema Refresh

    3/16

    1 Refresh Process1 Refresh Process

    11..11 SourceSourceServer name, Database name, and SOURCE SchemaServer name, Database name, and SOURCE Schema

    11..22 TargetTargetServer name, Database name and TARGET SchemaServer name, Database name and TARGET Schema

    11..33 StepsStepsThe following are the sequence of steps to be followed to complete theThe following are the sequence of steps to be followed to complete the

    task :task :--

    Pre Export tasks on the Source SchemaPre Export tasks on the Source Schema

    Review the source & target DB Tablespace Sizes prior starting compare ifReview the source & target DB Tablespace Sizes prior starting compare ifthey are near each other in sizethey are near each other in size

    If not similar in size add additional space for Tablespace TargetIf not similar in size add additional space for Tablespace Target

  • 8/8/2019 Schema Refresh

    4/16

    Export of the Source SchemaExport of the Source Schema

    Backup of the Target SchemaBackup of the Target Schema

    Pre Import tasks on Target SchemaPre Import tasks on Target Schema

    Dropping of objects in Target SchemaDropping of objects in Target Schema

    Import into Target SchemaImport into Target Schema Post Import tasks (recompiling , statistics etc).Post Import tasks (recompiling , statistics etc).

  • 8/8/2019 Schema Refresh

    5/16

    22 Detailed ProcessDetailed Process

    22..11 StepsSteps forfor SourceSource SchemaSchema

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

    SQL> select object_type, status, count(*)SQL> select object_type, status, count(*)from dba_objectsfrom dba_objects

    where owner=where owner=SOURCESOURCE--SCHEMASCHEMA group by object_type, status; group by object_type, status;

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

    SQL> select constraint_type, status, count(*)SQL> select constraint_type, status, count(*)

    from dba_constraintsfrom dba_constraints

    where owner='where owner=' SOURCESOURCE--SCHEMASCHEMA ''

    group by constraint_type, status;group by constraint_type, status;

  • 8/8/2019 Schema Refresh

    6/16

    3.3. Review the source & target DB Tablespace Sizes prior startingReview the source & target DB Tablespace Sizes prior startingcompare if they are near each other in sizecompare if they are near each other in size

    If not similar in size add additional space for Tablespace TargetIf not similar in size add additional space for Tablespace Target

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

    SQL> select sum(bytes)/1024/1024SQL> select sum(bytes)/1024/1024

    from dba_segmentsfrom dba_segments

    where owner='where owner='SOURCESOURCE--SCHEMASCHEMA';';

    5. Export the schema into the following directory.5. Export the schema into the following directory.

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

    /oraexp01/DBName (for dog* servers)./oraexp01/DBName (for dog* servers).

    (FORMAT : exp_dbname_schema_ddMMMyy.dmp(FORMAT : exp_dbname_schema_ddMMMyy.dmp

    exp_gemsora15d_PRD_07june05.dmp)exp_gemsora15d_PRD_07june05.dmp)

    Log file: exp_gemsora15d_PRD_07june05.logLog file: exp_gemsora15d_PRD_07june05.log

  • 8/8/2019 Schema Refresh

    7/16

    $ exp file= exp_dbname_schema_ddMMMyy.dmp$ exp file= exp_dbname_schema_ddMMMyy.dmp

    log=exp_dbname_schema_ddMMMyy.log owner=SOURCElog=exp_dbname_schema_ddMMMyy.log owner=SOURCE-- schemaschemaCompress=n buffer=1024000 consistent=y statistics=yCompress=n buffer=1024000 consistent=y statistics=y

    If the file is big, to take the export in compressedIf the file is big, to take the export in compressedformat, follow the process mentioned below:format, follow the process mentioned below:

    $ mknod pipe.dmp p$ mknod pipe.dmp p

    $ nohup /usr/bin/gzip$ nohup /usr/bin/gzip --cNf < pipe.dmp > filename.gz &cNf < pipe.dmp > filename.gz &$ nohup exp userid=system/paswd file= pipe.dmp$ nohup exp userid=system/paswd file= pipe.dmp

    log= filename.log owner=SOURCE schema(s)log= filename.log owner=SOURCE schema(s)

    compress=n buffer=10240000 recordlength= 65535 direct=y statistics=ycompress=n buffer=10240000 recordlength= 65535 direct=y statistics=y

    The export should complete without errors orThe export should complete without errors or

    warnings.warnings.

  • 8/8/2019 Schema Refresh

    8/16

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

    tailtail --1 |mailx1 |mailx s Export of on is overs Export of on is over

    [email protected]@med.ge.com

    22..22 StepsSteps forfor TARGETTARGET SchemaSchema..

    66.. InIn orderorder toto findfind outout thethe availabilityavailability ofof sufficientsufficient spacespace availableavailabletoto importimport thethe sourcesource schemaschema.. FindFind outout thethe sizesize of of thethe

    TARGETTARGET schemaschema..SQL>SQL> selectselect sum(bytes)/sum(bytes)/10241024//10241024

    from dba_segmentsfrom dba_segments

    where owner='TARGETwhere owner='TARGET--SCHEMA';SCHEMA';

  • 8/8/2019 Schema Refresh

    9/16

    7. Backup the schema if the size is less than 2 GB (logical7. Backup the schema if the size is less than 2 GB (logicalbackup). If the backup size is more than 2GB and full databasebackup). If the backup size is more than 2GB and full databasebackup exists, then backup need not be takenbackup exists, then backup need not be taken

    8. Drop all the tables in the TARGET SCHEMA8. Drop all the tables in the TARGET SCHEMA ..

    SQL> spool drop_tab.sqlSQL> spool drop_tab.sql

    SQL> select 'drop table TARGETSQL> select 'drop table TARGET--SCHEMA. || table_name||' cascadeSCHEMA. || table_name||' cascade

    constraints;'constraints;'

    from dba_tablesfrom dba_tables

    where owner=' TARGETwhere owner=' TARGET--SCHEMA ';SCHEMA ';

    SQL> spool offSQL> spool offSQL> @drop_tab.sqlSQL> @drop_tab.sql

    9. Drop all the other objects from the TARGET SCHEMA9. Drop all the other objects from the TARGET SCHEMA

  • 8/8/2019 Schema Refresh

    10/16

    SQL> spool drop_obj.sqlSQL> spool drop_obj.sql

    SQL> select 'drop'|| object_type ||' TARGETSQL> select 'drop'|| object_type ||' TARGET--SCHEMA.'|| object_name||';'SCHEMA.'|| object_name||';'

    From dba_objectsFrom dba_objects

    where owner=' TARGETwhere owner=' TARGET--SCHEMASCHEMA

    SQL> spool offSQL> spool off

    SQL> @drop_obj.sqlSQL> @drop_obj.sql

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

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

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

    $ mknod /tmp/imp_pipe.dmp p$ mknod /tmp/imp_pipe.dmp p

    $ gunzip$ gunzip --c /tmp/imp_pipe.dmp &c /tmp/imp_pipe.dmp &

    $ nohup imp userid=system/paswd file=/tmp/imp_pipe.dmp$ nohup imp userid=system/paswd file=/tmp/imp_pipe.dmp

    fromuser =S1,S2 touser =T1,T2 log =filename.log buffer =20480000fromuser =S1,S2 touser =T1,T2 log =filename.log buffer =20480000

    commit =y statistics=y resumable=y (only Oracle 9i)commit =y statistics=y resumable=y (only Oracle 9i)

  • 8/8/2019 Schema Refresh

    11/16

    Important Note:Important Note:

    In case of multi schema export the parameters forIn case of multi schema export the parameters forFROMUSER and TOUSER should be given in order (i.e. 1FROMUSER and TOUSER should be given in order (i.e. 1 ---- 11correspondence should be maintained).correspondence should be maintained).

    It is better to give resumable=y, which helps to increase theIt is better to give resumable=y, which helps to increase theSize of TS, in case of insufficient space (only from Oracle 9i).Size of TS, in case of insufficient space (only from Oracle 9i).

    11. If the indexes are in the same tablespace as the11. If the indexes are in the same tablespace as thetables, then rebuild the indexes into the indextables, then rebuild the indexes into the indextablespace using the rebuild.. tablespace clausetablespace using the rebuild.. tablespace clausewhile rebuild.while rebuild.

  • 8/8/2019 Schema Refresh

    12/16

    SQL> spool idx.sqlSQL> spool idx.sql

    SQL> select 'alter index schema.'||index_name||' rebuild;'SQL> select 'alter index schema.'||index_name||' rebuild;'

    from dba_indexes where owner = SCHEMA';from dba_indexes where owner = SCHEMA';

    SQL> spool offSQL> spool off

    SQL> @idx.sqlSQL> @idx.sql

    12. Recompile the procedures etc(if required)12. Recompile the procedures etc(if required)

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

  • 8/8/2019 Schema Refresh

    13/16

    3 Verification3 Verification

    1.1. Do notDo not perform Schema Refreshes over 10 Gb.perform Schema Refreshes over 10 Gb.

    2.2. Verify whether the schema is imported properly.Verify whether the schema is imported properly.

    3.3. Verify whether all the objects are imported properly as per theVerify whether all the objects are imported properly as per the

    i.i. SOURCE SCHEMA.SOURCE SCHEMA.

    Note: Compare and verify the objects with the statistics collectedNote: Compare and verify the objects with the statistics collected

    from (step 1, step 2 and step 3.)from (step 1, step 2 and step 3.)

    4.4. Verify the indexes and if they are in the DATA Tablespace,Verify the indexes and if they are in the DATA Tablespace,then rebuild them in the INDEX Tablespace.then rebuild them in the INDEX Tablespace.

    5.5. Verify for invalid objects. If possible try to reVerify for invalid objects. If possible try to re--compilecompileprocedures and views etc.procedures and views etc.

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

  • 8/8/2019 Schema Refresh

    14/16

  • 8/8/2019 Schema Refresh

    15/16

    Note: The export activity should be completed as normal and without anyNote: The export activity should be completed as normal and without any

    warnings .warnings .

    Copy the export dmp and log files to the abo

    v

    e mentioned respectiv

    e databaseCopy the export dmp and log files to the abov

    e mentioned respectiv

    e databasedirectory (through ftp / scp) to the target machine.directory (through ftp / scp) to the target machine.

    We do notWe do not perform Schema Refreshes over 10 Gb.perform Schema Refreshes over 10 Gb.

    4.2 Target Schema4.2 Target Schema

    Export the schema dmp and log files into *Export the schema dmp and log files into * respective directoryrespective directory in the TARGETin the TARGETschema database directory using naming conventions for the dmp and log files. (i.e.schema database directory using naming conventions for the dmp and log files. (i.e.

    exp_DBName_Schema_ddMMMMyy.dmp ).exp_DBName_Schema_ddMMMMyy.dmp ).

    exp_DBName_Schema_ddMMMMyy.log )exp_DBName_Schema_ddMMMMyy.log )

    *Directories*Directories

    /servername/exp01/DBName (in general for all servers) /servername/exp01/DBName (in general for all servers)oraexp01/DBName (for dog* servers).oraexp01/DBName (for dog* servers).

    Drop all the tables from the TARGET schema.Drop all the tables from the TARGET schema.

    Drop all the other objects from the TARGET schemaDrop all the other objects from the TARGET schema ..

  • 8/8/2019 Schema Refresh

    16/16