Wednesday, 28 March 2012

Transporting Tablespaces


Transporting Tablespaces:

These steps are illustrated more fully in the example that follows, where it is assumed the following datafiles and tablespaces exist:
Tablespace
Datafile:
ica_sales_1
/u01/oracle/oradata/ica_salesdb/ica_sales_101.dbf
ica_sales_2
/u01/oracle/oradata/ica_salesdb/ica_sales_201.dbf

Step 1: Determine if Platforms are Supported and Endianness
This step is only necessary if you are transporting the tablespace set to a platform different from the source platform. If ica_sales_1 and ica_sales_2 were being transported to a different platform, you can execute the following query on both platforms to determine if the platforms are supported and their endian formats:
SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
     FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
     WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;

The following is the query result from the source platform:
PLATFORM_NAME             ENDIAN_FORMAT
------------------------- --------------
Solaris[tm] OE (32-bit)   Big

The following is the result from the target platform:
PLATFORM_NAME             ENDIAN_FORMAT
------------------------- --------------
Microsoft Windows NT      Little

You can see that the endian formats are different and thus a conversion is necessary for transporting the tablespace set.
Step 2: Pick a Self-Contained Set of Tablespaces
There may be logical or physical dependencies between objects in the transportable set and those outside of the set. You can only transport a set of tablespaces that is self-contained. That is it should not have tables with foreign keys referring to primary key of tables which are in other tablespaces. It should not have tables with some partitions in other tablespaces. To find out whether the tablespace is self contained do the following
EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('ica_sales_1,ica_sales_2', TRUE);

After executing the above give the following query to see whether  any violations are there.
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;

VIOLATIONS
---------------------------------------------------------------------------
Constraint DEPT_FK between table SAMI.EMP in tablespace ICA_SALES_1 and table
SAMI.DEPT in tablespace OTHER
Partitioned table SAMI.SALES is partially contained in the transportable set

These violations must be resolved before ica_sales_1 and ica_sales_2 are transportable
Step 3: Generate a Transportable Tablespace Set
After ensuring you have a self-contained set of tablespaces that you want to transport, generate a transportable tablespace set by performing the following actions:
Make all tablespaces in the set you are copying read-only.
SQL> ALTER TABLESPACE ica_sales_1 READ ONLY;
Tablespace altered.
SQL> ALTER TABLESPACE ica_sales_2 READ ONLY;
Tablespace altered.
Invoke the Export utility on the host system and specify which tablespaces are in the transportable set.
SQL> HOST
$ exp system/password FILE=/u01/oracle/expdat.dmp
TRANSPORT_TABLESPACES = ica_sales_1,ica_sales_2 log=/ u01/oracle/expdat.log
If ica_sales_1 and ica_sales_2 are being transported to a different platform, and the endianness of the platforms is different, and if you want to convert before transporting the tablespace set, then convert the datafiles composing the ica_sales_1 and ica_sales_2 tablespaces. You have to use RMAN utility to convert datafiles
$ RMAN TARGET /
Recovery Manager: Release 10.1.0.0.0
Copyright (c) 1995, 2003, Oracle Corporation.  All rights reserved.

 
connected to target database: ica_salesdb (DBID=3295731590)
Convert the datafiles into a temporary location on the source platform. In this example, assume that the temporary location, directory /temp, has already been created. The converted datafiles are assigned names by the system.
RMAN> CONVERT TABLESPACE ica_sales_1,ica_sales_2 
       TO PLATFORM 'Microsoft Windows NT' FORMAT '/temp/%U';

Starting backup at 08-APR-03
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00005 name=/u01/oracle/oradata/ica_salesdb/ica_sales_101.dbf
converted datafile=/temp/data_D-10_I-3295731590_TS-ADMIN_TBS_FNO-5_05ek24v5
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00004 name=/u01/oracle/oradata/ica_salesdb/ica_sales_101.dbf
converted datafile=/temp/data_D-10_I-3295731590_TS-EXAMPLE_FNO-4_06ek24vl
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:45
Finished backup at 08-APR-07
Step 4: Transport the Tablespace Set
Transport both the datafiles and the export file of the tablespaces to a place accessible to the target database. You can use any facility for copying flat files (for example, an operating system copy utility, ftp, the DBMS_FILE_TRANSFER package, or publishing on CDs).
Step 5: Plug In the Tablespace Set
Plug in the tablespaces and integrate the structural information using the Import utility, imp:
IMP system/password FILE=expdat.dmp
  DATAFILES=/ica_salesdb/ica_sales_101.dbf,/ica_salesdb/ica_sales_201.dbf
   REMAP_SCHEMA=(smith:sami) REMAP_SCHEMA=(williams:john)
The REMAP_SCHEMA parameter changes the ownership of database objects. If you do not specify REMAP_SCHEMA, all database objects (such as tables and indexes) are created in the same user schema as in the source database, and those users must already exist in the target database. If they do not exist, then the import utility returns an error. In this example, objects in the tablespace set owned by smith in the source database will be owned by sami in the target database after the tablespace set is plugged in. Similarly, objects owned by williams in the source database will be owned by john in the target database. In this case, the target database is not required to have userssmith and williams, but must have users sami and john.
After this statement executes successfully, all tablespaces in the set being copied remain in read-only mode. Check the import logs to ensure that no error has occurred.
Now, put the tablespaces into read/write mode as follows:
ALTER TABLESPACE ica_sales_1 READ WRITE;
ALTER TABLESPACE ica_sales_2 READ WRITE;

Tuesday, 13 March 2012

Upgradation from 10gr2 to 11gr2



-First check the instance name:
  SQL> select instance_name from v$instance;

  INSTANCE_NAME
  ----------------
  oradb

-and check banner also:
  SQL> select * from v$version;

  BANNER
  ----------------------------------------------------------------
  Oracle Database 10g Enterprise Edition Release 10.2.0.5.0
  PL/SQL Release 10.2.0.5.0 - Production
  CORE 10.2.0.5.0 Production
  TNS for Linux: Version 10.2.0.5.0 - Production
  NLSRTL Version 10.2.0.5.0 - Production

-first check pre-upgradescript:

Get the latest version of utlu1nmi.sql
– Download it
– Note:884522.1

  SQL> @utlu112i.sql  // 10g
  Oracle Database 11.2 Pre-Upgrade Information Tool 11-23-2010 10:03:59
  Script Version: 11.2.0.2.0 Build: 001
  .
  **********************************************************************
  Database:
  **********************************************************************
  --> name: ORADB
  --> version: 10.2.0.5.0
  --> compatible: 10.2.0.5.0
  --> blocksize: 8192
  --> platform: Linux x86 64-bit
  --> timezone file: V4
  .
  **********************************************************************
  Tablespaces: [make adjustments in the current environment]
  **********************************************************************
  --> SYSTEM tablespace is adequate for the upgrade.
  .... minimum required size: 693 MB
  --> UNDOTBS1 tablespace is adequate for the upgrade.
  .... minimum required size: 467 MB
  --> SYSAUX tablespace is adequate for the upgrade.
  .... minimum required size: 481 MB
  --> TEMP tablespace is adequate for the upgrade.
  .... minimum required size: 61 MB
  .
  **********************************************************************
  Flashback: OFF
  **********************************************************************
  **********************************************************************
  Update Parameters: [Update Oracle Database 11.2 init.ora or spfile]
  Note: Pre-upgrade tool was run on a lower version 64-bit database.
  **********************************************************************
  --> If Target Oracle is 32-Bit, refer here for Update Parameters:
  -- No update parameter changes are required.
  .

  --> If Target Oracle is 64-Bit, refer here for Update Parameters:
  -- No update parameter changes are required.
  .
  **********************************************************************
  Renamed Parameters: [Update Oracle Database 11.2 init.ora or spfile]
  **********************************************************************
  -- No renamed parameters found. No changes are required.
  .
  **********************************************************************
  Obsolete/Deprecated Parameters: [Update Oracle Database 11.2 init.ora or spfile]
  **********************************************************************
  --> background_dump_dest 11.1 DEPRECATED replaced by "diagnostic_dest"
  --> user_dump_dest 11.1 DEPRECATED replaced by "diagnostic_dest"
  .

  **********************************************************************
  Components: [The following database components will be upgraded or installed]
  **********************************************************************
  --> Oracle Catalog Views [upgrade] VALID
  --> Oracle Packages and Types [upgrade] VALID
  --> JServer JAVA Virtual Machine [upgrade] VALID
  --> Oracle XDK for Java [upgrade] VALID
  --> Oracle Workspace Manager [upgrade] VALID
  --> OLAP Analytic Workspace [upgrade] VALID
  --> OLAP Catalog [upgrade] VALID
  --> EM Repository [upgrade] VALID
  --> Oracle Text [upgrade] VALID
  --> Oracle XML Database [upgrade] VALID
  --> Oracle Java Packages [upgrade] VALID
  --> Oracle interMedia [upgrade] VALID
  --> Spatial [upgrade] VALID
  --> Data Mining [upgrade] VALID
  --> Expression Filter [upgrade] VALID
  --> Rule Manager [upgrade] VALID
  --> Oracle OLAP API [upgrade] VALID
  .
  **********************************************************************
  Miscellaneous Warnings
  **********************************************************************
  WARNING: --> Database is using a timezone file older than version 14.
  .... After the release migration, it is recommended that DBMS_DST package
  .... be used to upgrade the 10.2.0.5.0 database timezone version
  .... to the latest version which comes with the new release.
  WARNING: --> EM Database Control Repository exists in the database.
  .... Direct downgrade of EM Database Control is not supported. Refer to the
  .... Upgrade Guide for instructions to save the EM data prior to upgrade.
  WARNING: --> Your recycle bin is turned on and currently contains no objects.
  .... Because it is REQUIRED that the recycle bin be empty prior to upgrading
  .... and your recycle bin is turned on, you may need to execute the command:
  PURGE DBA_RECYCLEBIN
  .... prior to executing your upgrade to confirm the recycle bin is empty.
  .
  **********************************************************************
  Recommendations
  **********************************************************************
  Oracle recommends gathering dictionary statistics prior to
  upgrading the database.



To gather dictionary statistics execute the following command
while connected as SYSDBA:

  EXECUTE dbms_stats.gather_dictionary_stats;
**********************************************************************
Oracle recommends reviewing any defined events prior to upgrading.

V$SYSTEM_PARAMETER2 displays information about the initialization parameters that are currently in effect for the instance,
with each list parameter value appearing as a row in the view. A new session inherits parameter values from the instance-wide values.



To view existing non-default events execute the following commands
while connected AS SYSDBA:
Events:
   SELECT (translate(value,chr(13)||chr(10),' ')) FROM sys.v$parameter2 WHERE UPPER(name) ='EVENT' AND isdefault='FALSE'

Trace Events:
   SELECT (translate(value,chr(13)||chr(10),' ')) from sys.v$parameter2 WHERE UPPER(name) = '_TRACE_EVENTS' AND isdefault='FALSE'

Changes will need to be made in the init.ora or spfile.
**********************************************************************


-Need speed for upgrading, so truncate AUD$ table and gather dictionary statistics
   SQL> truncate table SYS.AUD$ drop storage;
   Table truncated.


   SQL> exec DBMS_STATS.GATHER_DICTIONARY_STATS;



- Start to upgrade:
   SQL> shutdown immediate;
   Database closed.
   Database dismounted.
   ORACLE instance shut down

take a cold bkup for fall back plan

-Copy spfile + orapw from Old home -> New home.
   $ cp /u01/app/oracle/product/10.2.0/db_1/dbs/*oradb* /u01/app/oracle/product/11.2.0/dbhome_2/dbs/



-Use New home to startup upgrade
   $export sid of 10g
   $ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_2
   $export path
 
 
   SQL> connect / as sysdba
   Connected to an idle instance.

   SQL> startup upgrade;
   ORACLE instance started.

   Total System Global Area 676433920 bytes
   Fixed Size 2229560 bytes
   Variable Size 192940744 bytes
   Database Buffers 473956352 bytes
   Redo Buffers 7307264 bytes
   Database mounted.
   Database opened.




------------- donot execute this this will give an error, try this after catupgr.sql script    --------------------------------------------------------------------
-Run "catrelod.sql" script reloads the appropriate version of all of the database components in the downgraded database
   SQL> SPOOL reload.log

   SQL> @?/rdbms/admin/catrelod.sql   ///do not execute

   .
   .
.
   COMP_NAME STATUS VERSION
   ----------------------------------- ----------- ----------
   Oracle Database Packages and Types VALID 10.2.0.5.0
   Oracle Database Catalog Views VALID 10.2.0.5.0
   JServer JAVA Virtual Machine VALID 10.2.0.5.0
   Oracle XDK VALID 10.2.0.5.0
   Oracle Database Java Packages VALID 10.2.0.5.0
   Oracle Text VALID 10.2.0.5.0
   Oracle XML Database VALID 10.2.0.5.0
   Oracle Workspace Manager VALID 10.2.0.5.0
   Oracle Data Mining VALID 10.2.0.5.0
   OLAP Analytic Workspace VALID 10.2.0.5.0
   OLAP Catalog VALID 10.2.0.5.0
   Oracle OLAP API VALID 10.2.0.5.0
   Oracle interMedia VALID 10.2.0.5.0
 .
 .
 .





 
   SQL> spool upgrade.log
 

   SQL> set echo on
 

   SQL> set termout on



   SQL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql



   SQL> spool off


-Check error in spool file and startup again
   SQL> startup
   ORACLE instance started.

   Total System Global Area 676433920 bytes
   Fixed Size 2229560 bytes
   Variable Size 331352776 bytes
   Database Buffers 335544320 bytes
   Redo Buffers 7307264 bytes
   Database mounted.
   Database opened.



--This is post upgrade script: only necessary when upgrading from = 10.1
   SQL> @$ORACLE_HOME/rdbms/admin/catuppst.sql



--Generate fixed object stats
   SQL> exec dbms_stats.gather_fixed_objects_stats;
 
   PL/SQL procedure successfully completed.





--Recompile
   SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
   



--During recompilation: check number of invalid objects
   SQL> SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);






--During recompilation: check number of invalid objects
   SQL> SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);





--Compare invalid objects scripts
   SQL> @$ORACLE_HOME/rdbms/admin/utluiobj.sql





--Create pfile from spfile and modify some parameters
   SQL> create pfile='/tmp/pfile' from spfile;

   File created.






--Adjust time zone data
   SQL> startup upgrade
   ORACLE instance started.

   Total System Global Area 676433920 bytes
   Fixed Size 2229560 bytes
   Variable Size 192940744 bytes
   Database Buffers 473956352 bytes
   Redo Buffers 7307264 bytes
   Database mounted.
   Database opened.








   SQL> exec dbms_dst.begin_upgrade(new_version => 11);

   PL/SQL procedure successfully completed.

   SQL> shutdown immediate;
   Database closed.
   Database dismounted.
   ORACLE instance shut down.

   SQL> startup
   ORACLE instance started.

   Total System Global Area 676433920 bytes
   Fixed Size 2229560 bytes
   Variable Size 192940744 bytes
   Database Buffers 473956352 bytes
   Redo Buffers 7307264 bytes
   Database mounted.
   Database opened.

   SQL> set serveroutput on;
   SQL> declare num_of_failures number;
  begin
  dbms_dst.upgrade_database(num_of_failures);
  dbms_output.put_line(num_of_failures);
  dbms_dst.end_upgrade(num_of_failures);
  dbms_output.put_line(num_of_failures);
end;
/

-  Check
-- Check Oracle Version
   SQL> select instance_name from v$instance;

   INSTANCE_NAME
   ----------------
   oradb

   SQL> select * from v$version;

  BANNER
  --------------------------------------------------------------------------------
  Oracle Database 11g Enterprise Edition Release 11.2.0.2.0
  PL/SQL Release 11.2.0.2.0 - Production
  CORE 11.2.0.2.0 Production
  TNS for Linux: Version 11.2.0.2.0 - Production
  NLSRTL Version 11.2.0.2.0 - Production
  then copy/check listener and etc (from Old home to New home)




  SQL> show parameter compatible

  NAME TYPE VALUE
  ------------------------------------ ----------- ------------------------------
   compatible string 10.2.0.5.0

Regards,
Trinadh











APEX Schema installaation





1) shared pool size should be more than 100 Mb.

if not follow the below process...

sho parameter shared

ALTER SYSTEM SET SHARED_POOL_SIZE='100M' SCOPE=spfile;

You should restart the db

startup;

2) XDB schema should be installed.

if not follow the below process....

connect to the db to  sys DBA

show user

user should be sys then

select comp_name "Component" from dba_registry;

if not exist in the repository

then execute the below script to install XDB

@?/rdbms/admin/catqm.sql password_NAME Tablespace_name temporarytablespace

select comp_name "Component" from dba_registry;

3) CONTEXT schema should be installed.

connect to the db to  sys DBA

show user

user should be sys then

select comp_name "Component" from dba_registry;

if not exist in the repository

then execute the below script to install CONTEXT

@?/ctx/admin/catctx.sql password_NAME Tablespace_name temporarytablespace

select comp_name "Component" from dba_registry;

If all the above have installed sucessfully then proceed with APEX installation

4) DoWNload the latest APEX version from the below link

http://www.oracle.com/technology/products/database/application_express/download.html

After that copy the downloaded file to server (Any location)

unzip apex_4.2.0.zip

it wil create one directory called APEX

go to APEX direcory

sqlplus sys/SYS_password as sysdba

@apexins  tablespace_apex tablespace_files tablespace_temp images

Example: @apexins SYSAUX SYSAUX TEMP /i/

it will create FLOWS_040000,FLOWS_FILES and APEX_PUBLIC_USER three schemas.

then check the invalid objects in db, aswell as in the newly created schemas and compile them if you found any invalid objects.

select comp_name "Component" from dba_registry;

then to change the ADMIN password exicute the below script by connecting to sysdba

go to APEX direcory

sqlplus sys/SYS_password as sysdba

@apxconf

it will promt to change the password as well as HTTP server port.

defualt the port wil be 8080.




Regards,
Trinadh

Tablespace check Script


set pages 500
set lines 1000
select  a.tablespace_name,A.Allocated,nvl(B.Freespace,0)
Freespace,A.Allocated-nvl(B.Freespace,0)
Used_Space,round(b.freespace/a.allocated*100) "% Free",
CASE WHEN A.Allocated<= 50 then 5 WHEN A.Allocated<= 100
then 20 WHEN A.Allocated<= 250 then 50 WHEN A.Allocated<= 500 then 100
WHEN A.Allocated<= 1024 then 200 WHEN A.Allocated>= 20480
and A.Allocated<= 30720 then 4096 WHEN A.Allocated>= 30702
then 6144 ELSE round(a.allocated*.2) END THRESHOLD,
CASE WHEN A.Allocated<= 50 then round(b.freespace-5)
WHEN A.Allocated<= 100 then round(b.freespace-20) WHEN A.Allocated<= 250
then round(b.freespace-50) WHEN A.Allocated<= 500
then round(b.freespace-100) WHEN A.Allocated<= 1024
then round(b.freespace-200) WHEN A.Allocated>= 20480
and A.Allocated<= 30720 then round(b.freespace-4096)
WHEN A.Allocated>= 30702 then round(b.freespace-6144)
ELSE round(b.freespace-(a.allocated*.2)) END "if-ve_thn<thres"
from
(select tablespace_name ,sum(bytes)/1024/1024 Allocated
from dba_data_files group by tablespace_name) A ,
(select tablespace_name,sum(bytes)/1024/1024 Freespace
from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name (+);

Regards,
Trinadh

How to use SQLT tool in Oracle 11g


How to install:

1.  # cd sqlt/install
2.  # sqlplus / as sysdba
3.  SQL> START sqcreate.sql
During the installation you will be asked to enter values for these parameters:
  1. Optional Connect Identifier.
In some restricted-access systems you may need to specify a connect identifier like @PROD. If a connect identifier is not needed, enter nothing and just hit the "Enter" key.
  1. SQLTXPLAIN password.
Case sensitive in most systems.
  1. SQLTXPLAIN Default Tablespace.
Select from a list of available permanent tablespaces which one should be used by SQLTXPLAIN for the SQLT repository. It must have more than 50MB of free space.
  1. SQLTXPLAIN Temporary Tablespace.
Select from a list of available temporary tablespaces which one should be used by SQLTXPLAIN for volatile operations and objects.
  1. Optional Application User.
This is the user that issued the SQL statement to be analyzed. For example, if this were an EBS system specify APPS, on Siebel you would specify SIEBEL and on People Soft SYSADM. You won't be asked to enter the password for this user. You can add additional SQLT users after the tool is installed, by granting them role SQLT_USER_ROLE or by using provided script sqlt/install/sqguser.sql
  1. Licensed Oracle Pack. (T, D or N)
You can specify T for Oracle Tuning, D for Oracle Diagnostic or N for none. If T or D is selected, SQLT may include licensed content within the diagnostics files it produces. Default is T. If N is selected, SQLT installs with limited functionality.


XTRACT Method
Use this method if you know the SQL_ID or the HASH_VALUE of the SQL to be analyzed, else use XECUTE. The SQL_ID can be found on an AWR report, and the HASH_VALUE on any SQL Trace.
# cd sqlt/run
# sqlplus apps
SQL> START sqltxtract.sql [SQL_ID]|[HASH_VALUE]
SQL> START sqltxtract.sql 0w6uydn50g8cx
SQL> START sqltxtract.sql 2524255098

XTRXEC Method

# cd sqlt/run
# sqlplus apps
SQL> START sqltxtrxec.sql [SQL_ID]|[HASH_VALUE]
SQL> START sqltxtrxec.sql 0w6uydn50g8cx
SQL> START sqltxtrxec.sql 2524255098

XPLAIN Method

# cd sqlt
# sqlplus apps
SQL> START [path]sqltxplain.sql [path]filename
SQL> START run/sqltxplain.sql input/sample/sql1.sql


Wishes

Hi every one

regards,
Trinadh