Saturday 28 May 2016

Schema Refresh acvity

1. In the target database
Get the target schema metadata and privileges.
2. drop target schema.
drop user user_name cascade.
3. In the source database
Check dba_directories for the datapump directory.
4. Check datapump directory mount point has enough space or not.
note: use expdp with estimate_only to know datapunp dump size.
5. export source schema dump file to target server datapunp directory.
6. recreate target schema using target schema metadata.
7. import source schema data your target schema
impdp parfile=impdp.par


export or impport errors or warnings.
-----------------------------------
1. temparary tablespace errors.
2. index or table already exist.
3. indexes are created with warnings.
4. fine grain previliges.

=========== Get DDL of USER ===========
set long 9999999
set lines 100
set page size 0
set head off
set feedback off
SPOOL MDM_ETL_STG_ddl.sql
execute dbms_METADATA.SET_TRANSFORM_PARAM
(DBMS_METADATA.SESSION_TRANSFORM,  'SQLTERMINATOR',true);
select (case
        when ((select count(*)
               from dba_users
               where username = 'MDM_ETL_STG') > 0)
        then dbms_metadata.get_ddl ('USER', 'MDM_ETL_STG')
        else to_clob (' -- Note: User not found!')
        end ) Extracted_DDL from dual
UNION ALL
select (case
        when ((select count(*)
               from dba_ts_quotas
               where username = 'MDM_ETL_STG') > 0)
        then dbms_metadata.get_granted_ddl( 'TABLESPACE_QUOTA', 'MDM_ETL_STG')
        else to_clob (' -- Note: No TS Quotas found!')
        end ) from dual
UNION ALL
select (case
        when ((select count(*)
               from dba_role_privs
               where grantee = 'MDM_ETL_STG') > 0)
        then dbms_metadata.get_granted_ddl ('ROLE_GRANT', 'MDM_ETL_STG')
        else to_clob (' -- Note: No granted Roles found!')
        end ) from dual
UNION ALL
select (case
        when ((select count(*)
               from dba_sys_privs
               where grantee = 'MDM_ETL_STG') > 0)
        then dbms_metadata.get_granted_ddl ('SYSTEM_GRANT', 'MDM_ETL_STG')
        else to_clob (' -- Note: No System Privileges found!')
        end ) from dual
UNION ALL
select (case
        when ((select count(*)
               from dba_tab_privs
               where grantee = 'MDM_ETL_STG') > 0)
        then dbms_metadata.get_granted_ddl ('OBJECT_GRANT', 'MDM_ETL_STG')
        else to_clob (' -- Note: No Object Privileges found!')
        end ) from dual
/
spool off;
 

Friday 20 May 2016

DATAPUMP (Expdp/Impdp) Help

EXPDP:
----------

Export: Release 11.2.0.4.0 - Production on Wed Jun 15 22:41:03 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

The Data Pump export utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:
   Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
You can control how Export runs by entering the 'expdp' command followed
by various parameters. To specify parameters, you use keywords:
   Format:  expdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
   Example: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
USERID must be the first parameter on the command line.
------------------------------------------------------------------------------
The available keywords and their descriptions follow. Default values are listed within square brackets.
ATTACH
Attach to an existing job.
For example, ATTACH=job_name.
CLUSTER
Utilize cluster resources and distribute workers across the Oracle RAC.
Valid keyword values are: [Y] and N.
COMPRESSION
Reduce the size of a dump file.
Valid keyword values are: ALL, DATA_ONLY, [METADATA_ONLY] and NONE.
CONTENT
Specifies data to unload.
Valid keyword values are: [ALL], DATA_ONLY and METADATA_ONLY.
DATA_OPTIONS
Data layer option flags.
Valid keyword values are: XML_CLOBS.
DIRECTORY
Directory object to be used for dump and log files.
DUMPFILE
Specify list of destination dump file names [expdat.dmp].
For example, DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION
Encrypt part or all of a dump file.
Valid keyword values are: ALL, DATA_ONLY, ENCRYPTED_COLUMNS_ONLY, METADATA_ONLY and NONE.
ENCRYPTION_ALGORITHM
Specify how encryption should be done.
Valid keyword values are: [AES128], AES192 and AES256.
ENCRYPTION_MODE
Method of generating encryption key.
Valid keyword values are: DUAL, PASSWORD and [TRANSPARENT].
ENCRYPTION_PASSWORD
Password key for creating encrypted data within a dump file.
ESTIMATE
Calculate job estimates.
Valid keyword values are: [BLOCKS] and STATISTICS.
ESTIMATE_ONLY
Calculate job estimates without performing the export.
EXCLUDE
Exclude specific object types.
For example, EXCLUDE=SCHEMA:"='HR'".
FILESIZE
Specify the size of each dump file in units of bytes.
FLASHBACK_SCN
SCN used to reset session snapshot.
FLASHBACK_TIME
Time used to find the closest corresponding SCN value.
FULL
Export entire database [N].
HELP
Display Help messages [N].
INCLUDE
Include specific object types.
For example, INCLUDE=TABLE_DATA.
JOB_NAME
Name of export job to create.
LOGFILE
Specify log file name [export.log].
NETWORK_LINK
Name of remote database link to the source system.
NOLOGFILE
Do not write log file [N].
PARALLEL
Change the number of active workers for current job.
PARFILE
Specify parameter file name.
QUERY
Predicate clause used to export a subset of a table.
For example, QUERY=employees:"WHERE department_id > 10".
REMAP_DATA
Specify a data conversion function.
For example, REMAP_DATA=EMP.EMPNO:REMAPPKG.EMPNO.
REUSE_DUMPFILES
Overwrite destination dump file if it exists [N].
SAMPLE
Percentage of data to be exported.
SCHEMAS
List of schemas to export [login schema].
SERVICE_NAME
Name of an active Service and associated resource group to constrain Oracle RAC resources.
SOURCE_EDITION
Edition to be used for extracting metadata.
STATUS
Frequency (secs) job status is to be monitored where
the default [0] will show new status when available.
TABLES
Identifies a list of tables to export.
For example, TABLES=HR.EMPLOYEES,SH.SALES:SALES_1995.
TABLESPACES
Identifies a list of tablespaces to export.
TRANSPORTABLE
Specify whether transportable method can be used.
Valid keyword values are: ALWAYS and [NEVER].
TRANSPORT_FULL_CHECK
Verify storage segments of all tables [N].
TRANSPORT_TABLESPACES
List of tablespaces from which metadata will be unloaded.
VERSION
Version of objects to export.
Valid keyword values are: [COMPATIBLE], LATEST or any valid database version.
------------------------------------------------------------------------------
The following commands are valid while in interactive mode.
Note: abbreviations are allowed.
ADD_FILE
Add dumpfile to dumpfile set.
CONTINUE_CLIENT
Return to logging mode. Job will be restarted if idle.
EXIT_CLIENT
Quit client session and leave job running.
FILESIZE
Default filesize (bytes) for subsequent ADD_FILE commands.
HELP
Summarize interactive commands.
KILL_JOB
Detach and delete job.
PARALLEL
Change the number of active workers for current job.
REUSE_DUMPFILES
Overwrite destination dump file if it exists [N].
START_JOB
Start or resume current job.
Valid keyword values are: SKIP_CURRENT.
STATUS
Frequency (secs) job status is to be monitored where
the default [0] will show new status when available.
STOP_JOB
Orderly shutdown of job execution and exits the client.
Valid keyword values are: IMMEDIATE.




IMPDP
---------


Import: Release 11.2.0.4.0 - Production on Wed Jun 15 22:41:31 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

The Data Pump Import utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:
     Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
You can control how Import runs by entering the 'impdp' command followed
by various parameters. To specify parameters, you use keywords:
     Format:  impdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
USERID must be the first parameter on the command line.
------------------------------------------------------------------------------
The available keywords and their descriptions follow. Default values are listed within square brackets.
ATTACH
Attach to an existing job.
For example, ATTACH=job_name.
CLUSTER
Utilize cluster resources and distribute workers across the Oracle RAC.
Valid keyword values are: [Y] and N.
CONTENT
Specifies data to load.
Valid keywords are: [ALL], DATA_ONLY and METADATA_ONLY.
DATA_OPTIONS
Data layer option flags.
Valid keywords are: SKIP_CONSTRAINT_ERRORS.
DIRECTORY
Directory object to be used for dump, log and SQL files.
DUMPFILE
List of dump files to import from [expdat.dmp].
For example, DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD
Password key for accessing encrypted data within a dump file.
Not valid for network import jobs.
ESTIMATE
Calculate job estimates.
Valid keywords are: [BLOCKS] and STATISTICS.
EXCLUDE
Exclude specific object types.
For example, EXCLUDE=SCHEMA:"='HR'".
FLASHBACK_SCN
SCN used to reset session snapshot.
FLASHBACK_TIME
Time used to find the closest corresponding SCN value.
FULL
Import everything from source [Y].
HELP
Display help messages [N].
INCLUDE
Include specific object types.
For example, INCLUDE=TABLE_DATA.
JOB_NAME
Name of import job to create.
LOGFILE
Log file name [import.log].
NETWORK_LINK
Name of remote database link to the source system.
NOLOGFILE
Do not write log file [N].
PARALLEL
Change the number of active workers for current job.
PARFILE
Specify parameter file.
PARTITION_OPTIONS
Specify how partitions should be transformed.
Valid keywords are: DEPARTITION, MERGE and [NONE].
QUERY
Predicate clause used to import a subset of a table.
For example, QUERY=employees:"WHERE department_id > 10".
REMAP_DATA
Specify a data conversion function.
For example, REMAP_DATA=EMP.EMPNO:REMAPPKG.EMPNO.
REMAP_DATAFILE
Redefine data file references in all DDL statements.
REMAP_SCHEMA
Objects from one schema are loaded into another schema.
REMAP_TABLE
Table names are remapped to another table.
For example, REMAP_TABLE=HR.EMPLOYEES:EMPS.
REMAP_TABLESPACE
Tablespace objects are remapped to another tablespace.
REUSE_DATAFILES
Tablespace will be initialized if it already exists [N].
SCHEMAS
List of schemas to import.
SERVICE_NAME
Name of an active Service and associated resource group to constrain Oracle RAC resources.
SKIP_UNUSABLE_INDEXES
Skip indexes that were set to the Index Unusable state.
SOURCE_EDITION
Edition to be used for extracting metadata.
SQLFILE
Write all the SQL DDL to a specified file.
STATUS
Frequency (secs) job status is to be monitored where
the default [0] will show new status when available.
STREAMS_CONFIGURATION
Enable the loading of Streams metadata
TABLE_EXISTS_ACTION
Action to take if imported object already exists.
Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.
TABLES
Identifies a list of tables to import.
For example, TABLES=HR.EMPLOYEES,SH.SALES:SALES_1995.
TABLESPACES
Identifies a list of tablespaces to import.
TARGET_EDITION
Edition to be used for loading metadata.
TRANSFORM
Metadata transform to apply to applicable objects.
Valid keywords are: OID, PCTSPACE, SEGMENT_ATTRIBUTES and STORAGE.
TRANSPORTABLE
Options for choosing transportable data movement.
Valid keywords are: ALWAYS and [NEVER].
Only valid in NETWORK_LINK mode import operations.
TRANSPORT_DATAFILES
List of data files to be imported by transportable mode.
TRANSPORT_FULL_CHECK
Verify storage segments of all tables [N].
TRANSPORT_TABLESPACES
List of tablespaces from which metadata will be loaded.
Only valid in NETWORK_LINK mode import operations.
VERSION
Version of objects to import.
Valid keywords are: [COMPATIBLE], LATEST or any valid database version.
Only valid for NETWORK_LINK and SQLFILE.
------------------------------------------------------------------------------
The following commands are valid while in interactive mode.
Note: abbreviations are allowed.
CONTINUE_CLIENT
Return to logging mode. Job will be restarted if idle.
EXIT_CLIENT
Quit client session and leave job running.
HELP
Summarize interactive commands.
KILL_JOB
Detach and delete job.
PARALLEL
Change the number of active workers for current job.
START_JOB
Start or resume current job.
Valid keywords are: SKIP_CURRENT.
STATUS
Frequency (secs) job status is to be monitored where
the default [0] will show new status when available.
STOP_JOB
Orderly shutdown of job execution and exits the client.
Valid keywords are: IMMEDIATE.
 

Wednesday 18 May 2016

Database binaries cloning

From One Server To Other
 
1. Check the oracle home to clone
2. Check the oracle home size
3. Create the directory tree on the remote server and change ownership to oracle
4. On source execute tar command to copy over the network the ORACLE_HOME
directories to the target server
4. Once the tar finishes to copy on the target oracle home check the total size
5. Using the Perl script you can link soft links given in the directory
$ORACLE_HOME/clone/bin
6. First I need to detach the inventory because the server was itself a clone of the source.
 perl clone.pl
ORACLE_BASE=/u02/app/oracle
ORACLE_HOME=/u02/app/oracle/11.2.0
ORACLE_HOME_NAME=XXXX
OS_DBA_GRP=oracle 
OS_OPER_GRP=dba
7. Once the inventory was detached from the old server version I can run the cloning procedure
8. The last step is to execute as root the root.sh script:
9. Check the Cloned Home
10. Post Clone Checkups
 
How To Clone A Database Home From One Server To Other
 
1. Check the oracle home to clone
[oracle@lnx1 dbhome_1]$ opatch lsinv
 
2. Check the oracle home size
[oracle@lnx1 ~]$ cd /oracle/app/product/11.2.0/dbhome_1
[oracle@lnx1 dbhome_1]$
[oracle@lnx1 dbhome_1]$ du -h . | tail -1
4.5G
 
3. Create the directory tree on the remote server and change ownership to oracle
 [oracle@lnx2 ~]$ su -
Password:
[root@lnx2 ~]# mkdir -p /oracle/app/product/11.2.0/dbhome_1
[root@lnx2 ~]# chown -R oracle:dba /oracle
 
4. On source execute tar command to copy over the network the oracle_home
directories to the target server
[oracle@lnx1 ~]$ cd /oracle/app/product/11.2.0/dbhome_1
[oracle@lnx1 dbhome_1]$ tar cvf - . | ( ssh lnx2 "cd /oracle/app/product/11.2.0/dbhome_1 ; tar xvf -" )
Once the tar finishes to copy on the target oracle home check the total size
 
[oracle@lnx2 ~]$ cd /oracle/app/product/11.2.0/dbhome_1
[oracle@lnx2 dbhome_1]$ du -h . | tail -1
4.5G
 
5. Using the OUI to finish the cloning process
First I need to detach the inventory because the server was itself a clone of the
source
[oracle@lnx2 ~]$ cd /oracle/app/product/11.2.0/dbhome_1/oui/bin
 
6. [oracle@lnx2 bin]$
./runInstaller -detachHome
ORACLE_HOME="/oracle/app/product/11.2.0/dbhome_1"
Starting Oracle Universal Installer...
How To Clone A Database Home
From One Server To Other
Checking swap space: must be greater than 500 MB.   Actual 1992 MB        Passed
The inventory pointer is located at /etc/oraInst.loc
The inventory is located at /home/oracle/oraInventory
'DetachHome' was successful.
Once the inventory was detached from the old server version I can run the
cloning procedure:
 
7. [oracle@lnx2 bin]$
./runInstaller -clone -silent -ignorePreReq
ORACLE_HOME="/oracle/app/product/11.2.0/dbhome_1" ORACLE_HOME_NAME="dbhome_11gR2"
ORACLE_BASE="/oracle/app" OSDBA_GROUP=dba OSOPER_GROUP=dba
Starting Oracle Universal Installer...
Checking swap space: must be greater than 500 MB.   Actual 1992 MB        Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2010-11-05_11-28-15AM. Please
wait ...[oracle@lnx2 bin]$ Oracle Universal Installer, Version 11.2.0.1.0 Production
Copyright (C) 1999, 2009, Oracle. All rights reserved.
You can find the log of this install session at:
 /home/oracle/oraInventory/logs/cloneActions2010-11-05_11-28-15AM.log
.................................................................................................... 100% Done.
Installation in progress (Friday, November 5, 2010 11:28:48 AM PDT)
..............................................................................                                                      78% Done.
Install successful
Linking in progress (Friday, November 5, 2010 11:29:21 AM PDT)
Link successful
Setup in progress (Friday, November 5, 2010 11:31:59 AM PDT)
Setup successful
End of install phases.(Friday, November 5, 2010 11:35:50 AM PDT)
Starting to execute configuration assistants
Configuration assistant "Oracle Configuration Manager Clone" succeeded
WARNING:
The following configuration scripts need to be executed as the "root" user.
/oracle/app/product/11.2.0/dbhome_1/root.sh
To execute the configuration scripts:
        1. Open a terminal window
        2. Log in as "root"
        3. Run the scripts
The cloning of dbhome_11gR2 was successful.
Please check '/home/oracle/oraInventory/logs/cloneActions2010-11-05_11-28-15AM.log' for more details.
The last step is to execute as root the root.sh script:
 
8. [root@lnx2 ~]# /oracle/app/product/11.2.0/dbhome_1/root.sh
Check /oracle/app/product/11.2.0/dbhome_1/install/root_lnx2_2010-11-05_11-39-06.log for the output of
root script
How To Clone A Database Home
From One Server To Other
Check the Cloned Home
[oracle@lnx2 ~]$ opatch lsinv
Invoking OPatch 11.2.0.1.3
Oracle Interim Patch Installer version 11.2.0.1.3
Copyright (c) 2010, Oracle Corporation.  All rights reserved.
Oracle Home           : /oracle/app/product/11.2.0/dbhome_1
Central Inventory : /home/oracle/oraInventory
   from               : /etc/oraInst.loc
OPatch version        : 11.2.0.1.3
OUI version           : 11.2.0.1.0
OUI location          : /oracle/app/product/11.2.0/dbhome_1/oui
Log file location : /oracle/app/product/11.2.0/dbhome_1/
cfgtoollogs/opatch/opatch2010-11-05_11-46-19AM.log
Patch history file: /oracle/app/product/11.2.0/dbhome_1/
cfgtoollogs/opatch/opatch_history.txt
Lsinventory Output file location : /oracle/app/product/11.2.0/dbhome_1/
cfgtoollogs/opatch/lsinv/lsinventory2010-
11-05_11-46-19AM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1):
Oracle Database 11g                                                      11.2.0.1.0
There are 1 products installed in this Oracle Home.
Interim patches (1) :
Patch  9952216          : applied on Fri Nov 05 07:13:34 PDT 2010
Unique Patch ID:  12825033
   Created on 13 Sep 2010, 04:55:09 hrs PST8PDT
   Bugs fixed:
         9068088, 9363384, 8865718, 8898852, 8801119, 9054253, 8725286, 8974548
         9093300, 8909984, 8755082, 8780372, 9952216, 8664189, 8769569, 7519406
         9471411, 9302343, 8822531, 7705591, 8650719, 9637033, 8883722, 8639114
         8723477, 8729793, 8919682, 8856478, 9001453, 8733749, 8565708, 8735201
         8684517, 8870559, 8773383, 8981059, 8812705, 9488887, 8813366, 9242411
         8822832, 8897784, 8760714, 8775569, 8671349, 8898589, 9714832, 8642202
         9011088, 9369797, 9170608, 9165206, 8834636, 8891037, 8431487, 8570322
         8685253, 8872096, 8718952, 8799099, 9032717, 9399090, 9713537, 9546223
         8588519, 8783738, 8834425, 9454385, 8856497, 8890026, 8721315, 8818175
         8674263, 9145541, 8720447, 9272086, 9467635, 9010222, 9102860, 9197917
         8991997, 8661168, 8803762, 8769239, 9654983, 8546356, 8706590, 8778277
         9058865, 8815639, 9971778, 9971779, 9027691, 9454036, 9454037, 9454038
         9255542, 8761974, 9275072, 8496830, 8702892, 8818983, 8475069, 8875671
         9328668, 8891929, 8798317, 8782959, 9971780, 8774868, 8820324, 8544696
         8702535, 9406607, 9952260, 8268775, 9036013, 9363145, 8933870, 8405205
         9467727, 8822365, 9676419, 8761260, 8790767, 8795418, 8913269, 8717461
         8861700, 9531984, 8607693, 8330783, 8780281, 8784929, 8780711, 9341448
         9015983, 8828328, 9119194, 8832205, 8665189, 8717031, 9482399, 9676420
         9399991, 8821286, 8633358, 9321701, 9231605, 9655013, 8796511, 9167285
         8782971, 8756598, 9390484, 8703064, 9066116, 9007102, 9461782, 9382101
         8505803, 9352237, 8753903, 9216806, 8918433, 9057443, 8790561, 8795792
         8733225, 9067282, 8928276, 8837736, 9210925
How To Clone A Database Home
From One Server To Other
--------------------------------------------------------------------------------
OPatch succeeded.
Post Clone Checkups
It may be needed to update $ORACLE_HOME/dbs,  $ORACLE_HOME/network/admin files to make them match
the new server.
$ORACLE_HOME/perl/bin/perl clone.pl ORACLE_BASE="/u01/app/oracle/" ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
OSDBA_GROUP=dba OSOPER_GROUP=oper -defaultHomeName

Optimizer Access Paths using Indexes

Introduction In this tutorial you will use the Optimizer Access Paths for the following cases (scenarios): Case 1: With and Without Index Ca...