Wednesday, November 17, 2010

Materialized View

+++++++++++++++++++++++++++++++++++++
MVIEW refresh Status on MASTER Site :
+++++++++++++++++++++++++++++++++++++
set pages 1000
set linesize 180
col SNAPSHOT_SITE for a30
select r.name, r.snapshot_site, l.current_snapshots
from dba_registered_snapshots r, dba_snapshot_logs l
where r.snapshot_id = l.snapshot_id and l.master in (select master
from dba_snapshot_logs) ;
CLEAR COLUMNS


Show all materialized and resfresh times
========================================
set lines 100 pages 999
col last_refresh format a20
select owner
, mview_name
, to_char(last_refresh_date, 'dd/mm/yy hh24:mi') last_refresh
from dba_mviews
order by owner, last_refresh
/

Manually start a refresh
===========================

execute dbms_mview.refresh ('');

List all materialized view logs
=================================
select log_owner, log_table from dba_mview_logs;

Tuesday, February 23, 2010

RMAN Performance Tuning Diagnostics

RMAN Performance Tuning Diagnostics [ID 311068.1]



PURPOSE
-------

Provide diagnostic reference for collecting RMAN backup
performance diagnostic information.

SCOPE & APPLICATION
-------------------

You should have some skills in database performance evaluation.

RMAN Performance Tuning Diagnostics
-----------------------------

Collecting performance information regarding RMAN backup
performance problems, bottlenecks come from somewhere. Not all tracing
shown here is required. It is up to you to determine which will help
you better define and isolate your performance issue. Collecting the
right information can help to quickly identify and resolve any Oracle
bottlenecks and provide evidence when it a 3rd party issue.

What should be collected?

1. RMAN debug output
2. Channel debug=5 trace=1 or 5 output trace files.
3. STATSPACK reports
4. If the CPU and slow sql (rather than IO) is the issue, the 10046 trace
and tkprof.
5. The resulting trace can be used with tkprof to get the explain plan
6. Collecting data from v$backup_async_io
7. Backup to tape is slow, how to determine if it's an Oracle or a media issue?

Prerequisites:

Make sure timed_statistics = true for all performance testing.
Always set the NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS' to get precision
time in the RMAN output.


1. RMAN debug output
This will always provide information to help the issue if RMAN is at fault.
Oracle will produce a useful error as sqlcode= or rc= in the debug. If you
do not see any errors and the channel released due to errors it is likely
the failure occurred outside of RMAN and failed in Oracle (channels) or the
device output used for backup.

2. Channel debug=5 trace=5 output trace files.
trace 1 - general trace info for skg and sbt
trace 5 - verbose channel tracing of skg and sbt calls

CONFIGURE CHANNEL DEVICE TYPE DISK DEBUG=5 TRACE 1;
or
CONFIGURE CHANNEL DEVICE TYPE SBT PARMS "ENV=(....) DEBUG=5 TRACE 5;
Trace is only useful for tape backup and restore tracing.

Example debug=5 output:
-----------------------

krbbpc: 04/29/2005 18:03:02: backup piece 1 started,
outfname=test2_ts_STXDB01Q_2agj3kam_T20050429_s74_s74_p1

-- cut to reduce output --

krbbpc: 04/29/2005 18:03:12: backup piece 1 finished,
handle=test2_ts_STXDB01Q_2agj3kam_T20050429_s74_s74_p1
elapsed time: 0:10
performance statistics:
count of waits for each file:
38: /odb/stx02/oradata07/stxdb01q/ts_impwrctr1_data_f1.dbf
output file throughput graph:
samples taken at 1 second intervals
bytes/second: min=131072, max=13107200, mean=4915200, stddev=4586958


3. STATSPACK reports
Statspack reports should be generated for the time during the backups to
capture the top wait events, the top sql, and pl/sql consuming the
resources. You can quickly see if the RMAN sql is taking the system resources
or is competing for resources. The reports should be at level 10 and split
into 15 minute intervals. This example shows a backup spending 80% of the
time waiting for sbtwrite2. So Oracle is waiting on tape IO.

Example output:
--------------

Top 5 Timed Events
~~~~~~~~~~~~~~~~~~ % Total
Event Waits Time (s) Ela Time
-------------------------------------------- ------------ ----------- --------
sbtwrite2 1,002 22 80.68
DFS lock handle 121 1 4.00
CPU time 1 3.60
control file sequential read 1,290 1 3.26
process startup 2 1 3.07

More can be determined from statspack and/or AWR output reports. The first main
indicator to look for bottlenecks are the top waits events.

Common Issue:
-------------

sbtwrite2 --> waiting for tape
sbtbackup --> waiting for tape
CPU Time --> sql or pl/sql to compile or runtime loop issue
IO Done --> waiting for IO slaves


4. If the CPU and slow sql (rather than IO) is the issue, the 10046 event trace
and tkprof. In the RMAN script add the sql 10046 event:

RMAN> sql "alter session set event ''10046 trace name context, level 12''";

Usually, slower performance sql will be related to the catalog, the 10046 trace
is best performed on the catalog database unless you are specifically looking
at sql performance in the target database. If there is a catalog in use, make
sure to review note:247611.1 "Known RMAN Performance Problems". This
provides new indexes and other workarounds that can be used to remedy known
issues for a variety of performance problems.


5. The resulting trace can be used with tkprof to get the explain plan
and cost of the sql execution.

- tkprof tracefile outfile [explain=user/password] [options...]
- TKPROF filename_source filename_output EXPLAIN=[username/password]
SYS=[YES/No] TABLE=[tablename]
$ tkprof ora_xxxx.trc tkprof.out explain=use/pwd sys=yes table=table_name

We always want sys=yes because the target is backed up by SYS AS SYSDBA so all
commands will run under the sys schema.

TABLE
Specifies the schema and name of the table into which TKPROF temporarily places
execution plans before writing them to the output file. If the specified table
already exists, TKProf deletes its rows then uses it for the EXPLAIN PLAN
command. If this table does not exist, TKProf creates, uses, then drops it.
This parameter is ignored if the EXPLAIN parameter isn't used.

6. Collecting data from V$BACKUP_ASYNC_IO

Determine how much time Oracle took to open the file to backup then close. In
this example the backup of datafile "/data17/mds_sm_odr_apr2004_tab01.dbf"
took 1 hour and 28 minutes. The archivelogs from sequence# 45411 until sequence#
45420 were all placed in a single backup that completed in 11 seconds. See Note:237083.1.

Example output
--------------

V$BACKUP_ASYNC_IO:

FNAME OPEN CLOSE H:MM
------------------------------------ -------------------- -------------------- ----
/data17/mds_sm_odr_apr2004_tab01.dbf 23-MAR-2005 02:53:52 23-MAR-2005 04:21:49 1:28
/arch/mdsp_arch1_45415_518895446.log 23-MAR-2005 04:01:19 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45417_518895446.log 23-MAR-2005 04:01:19 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45412_518895446.log 23-MAR-2005 04:01:19 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45418_518895446.log 23-MAR-2005 04:01:19 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45420_518895446.log 23-MAR-2005 04:01:19 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45419_518895446.log 23-MAR-2005 04:01:21 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45416_518895446.log 23-MAR-2005 04:01:21 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45414_518895446.log 23-MAR-2005 04:01:21 23-MAR-2005 04:09:53 :08
/arch/mdsp_arch1_45411_518895446.log 23-MAR-2005 04:09:53 23-MAR-2005 04:11:58 :02
/arch/mdsp_arch1_45413_518895446.log 23-MAR-2005 04:09:53 23-MAR-2005 04:11:58 :02
rigg1rac_1_1 23-MAR-2005 04:01:19 23-MAR-2005 04:12:05 :11


7. Backup to tape is slow, how to determine if it's an Oracle or a media issue?
Backup a tablespace that represents a good amount of data. But make sure
there is enough room to write to local disk also.
a. backup tablespace to tape # Time to tape?
RMAN> run {
allocate channel t1 device type 'sbt_tape'
parms 'SBT_LIBRARY='
debug=5 TRACE 2;
backup tablespace ;
}

b. backup tablespace to disk api # Time to disk?
RMAN> run {
allocate channel t1 device type 'sbt_tape'
parms 'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=/path/backup)'
debug=5 TRACE 2;
backup tablespace ;
}

c. backup validate tablespace # Time to just read the data no output
RMAN> backup validate tablespace ;

With the debugging on the channels you can compare the difference in time it
takes to read the data during validate and to backup the same data to disk and
tape using the same sbt calls that are used by RMAN in either case.

Oracle9i-->

CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS
'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=/path/backup)' debug=5 TRACE 2;

allocate channel t1 device type 'sbt_tape' parms
'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=/path/backup)' debug=5 TRACE 2;

REFERENCES
==========

Note.94224.1 FAQ- Statspack Complete Reference
Note 237083.1 Using V$BACKUP_ASYNC_IO / V$BACKUP_SYNC_IO to Monitor RMAN Performance
Note 247611.1 "Known RMAN Performance Problems".

transpor the tablespace to different platform

------------------------------------------------------------------------------------------------
How t0 move tablespaces across platforms using Transportable Tablespaces with RMAN [ID 371556.1]

-------------------------------------------------------------------------------------------------

Modified 14-JUL-2009 Type HOWTO Status PUBLISHED



Starting with Oracle Database 10g, you can transport tablespaces across
platforms. In this note there is a step by step guide about how to do it
with ASM datafiles and with OS filesystem datafiles.


Supported platforms
====================

You can query the V$TRANSPORTABLE_PLATFORM view to see the platforms that are
supported and to determine each platform's endian format (byte ordering).

SQL> select name, platform_id,platform_name from v$database;

NAME PLATFORM_ID PLATFORM_NAME
--------- ----------- ------------------------------
JK-ASSOC 13 Linux 64-bit for AMD


-------------------------------------------------------------------------------------------------
col platform_name for a30
set pages 100
SELECT PLATFORM_ID, PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM; -------------------------------------------------------------------------------------------------

SQL> COLUMN PLATFORM_NAME FORMAT A32
SQL> SELECT * FROM V$TRANSPORTABLE_PLATFORM;

PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- -------------------------------- --------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
10 Linux IA (32-bit) Little
6 AIX-Based Systems (64-bit) Big
3 HP-UX (64-bit) Big
5 HP Tru64 UNIX Little
4 HP-UX IA (64-bit) Big
11 Linux IA (64-bit) Little
15 HP Open VMS Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
13 Linux 64-bit for AMD Little
16 Apple Mac OS Big
12 Microsoft Windows 64-bit for AMD Little
17 Solaris Operating System (x86) Little


If the source platform and the target platform are of different endianness,
then an additional step must be done on either the source or target platform
to convert the tablespace being transported to the target format.
If they are of the same endianness, then no conversion is necessary and
tablespaces can be transported as if they were on the same platform.


Limitations on Transportable Tablespace Use
==============================================

1. The source and target database must use the same character set and national
character set.

2. You cannot transport a tablespace to a target database in which a tablespace
with the same name already exists. However, you can rename either the
tablespace to be transported or the destination tablespace before the
transport operation.

3. Objects with underlying objects (such as materialized views) or contained
objects (such as partitioned tables) are not transportable unless all of
the underlying or contained objects are in the tablespace set.
* Review Table "Objects Exported and Imported in Each Mode" from the
Oracle Database Utilities documentation, there are several object
types that are not exported in tablespace mode.

* If you use spatial indexes, then:
- be aware that TTS across different endian platforms are not supported
for spatial indexes in 10gR1 and 10gR2; such a limitation has been
released in 11g
- specific Spatial packages must be run before exporting and after
transportation, please see Oracle Spatial documentation.

4. Beginning with Oracle Database 10g Release 2, you can transport tablespaces
that contain XMLTypes, but you must use the IMP and EXP utilities,
not Data Pump. When using EXP, ensure that the CONSTRAINTS and TRIGGERS
parameters are set to Y (the default).

The following query returns a list of tablespaces that contain XMLTypes:

select distinct p.tablespace_name
from dba_tablespaces p, dba_xml_tables x, dba_users u, all_all_tables t
where t.table_name=x.table_name and
t.tablespace_name=p.tablespace_name and
x.owner=u.username

Transporting tablespaces with XMLTypes has the following limitations:

a.The target database must have XML DB installed.
b.Schemas referenced by XMLType tables cannot be the XML DB standard
schemas.
c.Schemas referenced by XMLType tables cannot have cyclic dependencies.
d.Any row level security on XMLType tables is lost upon import.
e.If the schema for a transported XMLType table is not present in the
target database, it is imported and registered.
If the schema already exists in the target databasean error is returned
unless the ignore=y option is set.

5. Advanced Queues Transportable tablespaces do not support 8.0-compatible
advanced queues with multiple recipients.

6. You cannot transport the SYSTEM tablespace or objects owned by the user SYS.

7. Opaque Types Types(such as RAW, BFILE, and the AnyTypes) can be transported, but
but they are not converted as part of the cross-platform transport operation.
Their actual structure is known only to the application, so the application
must address any endianness issues after these types are moved to the new
platform.

8. Floating-Point Numbers BINARY_FLOAT and BINARY_DOUBLE types are transportable
using Data Pump but not the original export utility, EXP.



Transportable tablespace EXP/IMP of ASM files
=============================================

* Using RMAN CONVERT
....................

There is no direct way to exp/imp ASM files as transportable tablespace.
However, the funcationality can be done via RMAN.

You must follow this steps:

1. Prepare for exporting the tablespace.

* Check that the tablespace will be seft contained:
SQL>execute sys.dbms_tts.transport_set_check('TBS1,TBS2', true);
SQL> select * from sys.transport_set_violations;
==>These violations must be resolved before the tablespaces
can be transported

* The tablespaces need to be in READ ONLY mode in order to successfully
run a transport tablespace export.

SQL> ALTER TABLESPACE TBS1 READ ONLY;
SQL> ALTER TABLESPACE TBS2 READ ONLY;


2. Export the metadata.

* Using the original export utility
exp userid=\'sys/sys as sysdba\' file=tbs_exp.dmp log=tba_exp.log
transport_tablespace=y tablespaces=TBS1,TBS2

* Using datapump exp

CREATE OR REPLACE DIRECTORY dpump_dir AS '/tmp/subdir' ;
GRANT READ,WRITE ON DIRECTORY dpump_dir TO system;

expdp system/password DUMPFILE=expdat.dmp DIRECTORY=dpump_dir
TRANSPORT_TABLESPACES = TBS1,TBS2

If you want to perform a transport tablespace operation with a strict
containment check, use the TRANSPORT_FULL_CHECK parameter:

expdp system/password DUMPFILE=expdat.dmp DIRECTORY = dpump_dir
TRANSPORT_TABLESPACES= TBS1,TBS2 TRANSPORT_FULL_CHECK=Y

If the tablespace set being transported is not self-contained, then the
export will fail.



3. Use V$TRANSPORTABLE_PLATFORM to find the exact platform name of
target database. You can execute the following query on target platform
instance:

SELECT tp.platform_id,substr(d.PLATFORM_NAME,2,30), ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;


4. Generate an OS file from the ASM, with target platform format

RMAN> CONVERT TABLESPACE TBS1
TO PLATFORM 'HP-UX (64-bit)' FORMAT '/tmp/%U';
RMAN> CONVERT TABLESPACE TBS2
TO PLATFORM 'HP-UX (64-bit)' FORMAT '/tmp/%U';

5. Copy the generated file to target server if different from source, with
ftp or cp


6. Import the transportable tablespace

* Using the original import utility

imp userid=\'sys/sys as sysdba\' file=tbs_exp.dmp log=tba_imp.log
transport_tablespace=y datafiles='/tmp/....','/tmp/...'

* Using datapump

CREATE OR REPLACE DIRECTORY dpump_dir AS '/tmp/subdir' ;
GRANT READ,WRITE ON DIRECTORY dpump_dir TO system;

impdp system/password DUMPFILE=expdat.dmp DIRECTORY=dpump_dir
TRANSPORT_DATAFILES='/tmp/....','/tmp/...'
REMAP_SCHEMA=(source:target) REMAP_SCHEMA=(source_sch2:target_schema_sch2)

You can use REMAP_SCHEMA if you want to change the ownership of the
transported database objects.

7. Put the tablespaces in read/write mode:

SQL> ALTER TABLESPACE TBS1 READ WRITE;
SQL> ALTER TABLESPACE TBS2 READ WRITE;

If you want to transport the datafiles from ASM area to filesystem, you have
finished after the above steps. But if you want to transport tablespaces
between two ASM areas you must continue.

8. Copy the datafile '/tmp/....dbf' into the ASM area using rman:

rman nocatalog target /
RMAN> backup as copy datafile '/tmp/....dbf' format '+DGROUPA';

# where +DGROUPA is the name of the ASM diskgroup

9. Switch the datafile to the copy.
If the 10g database is open you need to offline the datafile first

SQL> alter database datafile '/tmp/....dbf' offline;
Switch to the copy:
rman nocatalog target /
RMAN> switch datafile '/tmp/....dbf' to copy;

# Note down the name of the copy created in the +DGROUPA diskgroup
# ex. '+DGROUPA/s101/datafile/tts.270.5'

10. Put the datafile online again, we need to recover it first

SQL> recover datafile '+DGROUPA/s101/datafile/tts.270.5';
SQL> alter database datafile '+DGROUPA/s101/datafile/tts.270.5' online;

11. Check if datafile is indeed part of the ASM area and online:

SQL> select name, status from v$datafile;

Output should be:

+DGROUPA/s101/datafile/tts.270.5 ONLINE


* Using DBMS_FILE_TRANSFER
..........................

You can also use DBMS_FILE_TRANSFER to copy datafiles from one ASM disk group
to another, even on another host. Starting with 10g release 2 you can also use
DBMS_FILE_TRANSFER also to copy datafiles from ASM to filesystem and to
filesystem to ASM.

We can use the PUT_FILE Procedure

This procedure reads a local file or ASM and contacts a remote database
to create a copy of the file in the remote file system. The file that
is copied is the source file, and the new file that results from the copy
is the destination file.
The destination file is not closed until the procedure completes successfully.

Syntax:

DBMS_FILE_TRANSFER.PUT_FILE(
source_directory_object IN VARCHAR2,
source_file_name IN VARCHAR2,
destination_directory_object IN VARCHAR2,
destination_file_name IN VARCHAR2,
destination_database IN VARCHAR2);

Where:
source_directory_object ->The directory object from which the file is copied
at the local source site. This directory object must
exist at the source site.
source_file_name ->The name of the file that is copied from the local
file system. This file must exist in the local file
system in the directory associated with the source
directory object.
destination_directory_object -> The directory object into which the file is
placed at the destination site. This directory object
must exist in the remote file system.
destination_file_name ->The name of the file placed in the remote file system
A file with the same name must not exist in the
destination directory in the remote file system.
destination_database ->The name of a database link to the remote database
to which the file is copied.


If we want to use DBMS_FILE_TRANSFER.PUT_FILE to transfer the file from source
to destination host, the steps 3,4,5 should be changed by the following.

1) Create a directory at target database host, and give permissions to
local user.
This is the directory object into which the file is placed at the
destination site, it must exist in the remote file system.

CREATE OR REPLACE DIRECTORY target_dir AS '+DGROUPA' ;
GRANT WRITE ON DIRECTORY target_dir TO "USER";

2) Create a directory at source database host. The directory object from which
the file is copied at the local source site. This directory object must
exist at the source site.

CREATE OR REPLACE DIRECTORY source_dir AS '+DGROUPS/subdir' ;
GRANT READ,WRITE ON DIRECTORY source_dir TO "USER";
CREATE OR REPLACE DIRECTORY source_dir_1 AS '+DGROUPS/subdir/subdir_2' ;

3) Create a dblink to connect to target database host:

CREATE DATABASE LINK DBS2 CONNECT TO IDENTIFIED BY
USING 'target_connect';

Where target_connect is the connect string for target database and USER
is the user that we are going to use to transfer the datafiles.

4) Connect to source instance:

dbs1 => Connect string to source database
dbs2 => dblink to target database
a1.dat => Filename at source database
a4.dat => Filename at target database


CONNECT user/password@dbs1

-- - put a1.dat to a4.dat (using dbs2 dblink)
-- - level 2 sub dir to parent dir
-- - user has read privs on source_dir_1 at dbs1 and write on target_dir
-- - in dbs2
BEGIN
DBMS_FILE_TRANSFER.PUT_FILE ( 'source_dir_1' , 'a1.dat' ,
'target_dir' , 'a4.dat' ,
'dbs2' ) ;
END ;



Transportable tablespace EXP/IMP with OS files
=============================================


* Using RMAN CONVERT

1. Prepare for export of the tablespace.

* Check that the tablespace will be seft contained:
SQL> execute sys.dbms_tts.transport_set_check('TBS1,TBS2', true);
SQL> select * from sys.transport_set_violations;
==>These violations must be resolved before the tablespaces
can be transported

* The tablespaces need to be in READ ONLY mode in order to successfully
run a transport tablespace export.

SQL> ALTER TABLESPACE TBS1 READ ONLY;
SQL> ALTER TABLESPACE TBS2 READ ONLY;



2. Export the metadata.
* Using the original export utility

exp userid=\'sys/sys as sysdba\' file=tbs_exp.dmp log=tba_exp.log
transport_tablespace=y tablespaces=TBS1,TBS2

* Using datapump exp

CREATE OR REPLACE DIRECTORY dpump_dir AS '/tmp/subdir' ;
GRANT READ,WRITE ON DIRECTORY dpump_dir TO system;
expdp system/password DUMPFILE=expdat.dmp DIRECTORY=dpump_dir
TRANSPORT_TABLESPACES = TBS1,TBS2

If you want to perform a transport tablespace operation with a strict
containment check, use the TRANSPORT_FULL_CHECK parameter:

expdp system/password DUMPFILE=expdat.dmp DIRECTORY = dpump_dir
TRANSPORT_TABLESPACES= TBS1,TBS2 TRANSPORT_FULL_CHECK=Y

If the tablespace set being transported is not self-contained then the
export will fail.

3. Use V$TRANSPORTABLE_PLATFORM to determine the endianness of each platform.
You can execute the following query on each platform instance:

SELECT tp.platform_id,substr(d.PLATFORM_NAME,2,30), ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;


4. If you see that the endian formats are different and then a conversion is
necessary for transporting the tablespace set.

RMAN> convert tablespace TBS1
to platform="Linux IA (32-bit)" FORMAT '/tmp/%U';

RMAN> convert tablespace TBS2
to platform="Linux IA (32-bit)" FORMAT '/tmp/%U';

then copy the datafiles with ftp or copy

4. Import the transportable tablespace

* Using the original import utility

imp userid=\'sys/sys as sysdba\' file=tbs_exp.dmp log=tba_imp.log
transport_tablespace=y datafiles='/tmp/....','/tmp/...'

* Using datapump

CREATE OR REPLACE DIRECTORY dpump_dir AS '/tmp/subdir' ;
GRANT READ,WRITE ON DIRECTORY dpump_dir TO system;

impdp system/password DUMPFILE=expdat.dmp DIRECTORY=dpump_dir
TRANSPORT_DATAFILES='/tmp/....','/tmp/...'
REMAP_SCHEMA=(source:target)
REMAP_SCHEMA=(source_sch2:target_schema_sch2)

You can use REMAP_SCHEMA if you want to change the ownership of the
transported database objects.

5. Put the tablespaces in read/write mode:

SQL> ALTER TABLESPACE TBS1 READ WRITE;
SQL> ALTER TABLESPACE TBS2 READ WRITE;


* Using DBMS_FILE_TRANSFER

You can also use DBMS_FILE_TRANSFER to copy datafiles to another host. You
need to follow the same steps specified above for ASM files.
But if the endian formats are different then you must use the RMAN convert
after transfering the files.

This is an example of usage:

RMAN> CONVERT DATAFILE
'/hq/finance/work/tru/tbs_31.f',
'/hq/finance/work/tru/tbs_32.f',
'/hq/finance/work/tru/tbs_41.f'
TO PLATFORM="Solaris[tm] OE (32-bit)"
FROM PLATFORM="HP TRu64 UNIX"
DB_FILE_NAME_CONVERT=
"/hq/finance/work/tru/", "/hq/finance/dbs/tru"
PARALLELISM=5;

Then the same example showing destination being an +ASM diskgroup:

RMAN> CONVERT DATAFILE
'/hq/finance/work/tru/tbs_31.f',
'/hq/finance/work/tru/tbs_32.f',
'/hq/finance/work/tru/tbs_41.f'
TO PLATFORM="Solaris[tm] OE (32-bit)"
FROM PLATFORM="HP TRu64 UNIX"
DB_FILE_NAME_CONVERT=
"/hq/finance/work/tru/", "+diskgroup"
PARALLELISM=5;

Related



--------------------------------------------------------------------------------

Sunday, November 16, 2008

Regular scripts for Oracle DBA

select prev_hash_value from v$session where sid='&sid;
SQL> select prev_hash_value from v$session where sid='466'
select sql_text from v$sqlarea where hash_value='&hash_value'
SQL>select sql_text from v$sqlarea where hash_value='590983'now kill the holders session;select * from v$lock where block=1;
select username ,status,logon_time,process,osuser,sid,serial#,sql_hash_value from v$session where status='ACTIVE' order by logon_time;

+++++++++++++++++Session WAIT's :+++++++++++++++++
set pages 1000
set linesize 180
col username for a10
col module for a10
col event for a30
select a.sid, b.username, substr(b.module,1,10) Module, a.event, a.p1, substr(a.p1raw,1,25) p1raw, a.p2, a.p3, a.state, a.wait_time from v$session_wait a, v$session b where a.event not in ('SQL*Net message from client','wakeup time manager','pipe get','rdbms ipc message','smon timer','pmon timer','null event','jobq slave wait')
and a.sid=b.sid;
++++++++++++++++++++SQL TEXT for SID :++++++++++++++++++++
select sql_text,HASH_VALUE from v$sqltext t, v$session s where t.address = s.sql_addressand s.sid = &1 order by piece/CLEAR COLUMNS
+++++++++++++++++++LOCK DETAIL :+++++++++++++++++++
select * from v$lock where block=1;
+++++++++++++++++LOCK Details :+++++++++++++++++
col ORACLE_USERNAME for a13
col OS_USER_NAME for a10
col object_name for a40
PROMPT "PRESSS ENTER FOR ALL SIDs"
select a.ORACLE_USERNAME,a.OS_USER_NAME,a.SESSION_ID,b.object_name,c.NAME "RBS NAME",decode(a.LOCKED_MODE,1,'No Lock',2,'Row Share',3,'Row Excl',4,'Share',5,'Shr Row Excl',6,'Exclusive',null) "LOCK MODE",d.modulefrom v$locked_object a,dba_objects b,v$rollname c,v$session d where a.OBJECT_ID=b.object_idand a.XIDUSN=c.USNand a.session_id=d.sidand a.SESSION_ID like '%&sid%'order by session_id
+++++++++++++++++++++++long running query:+++++++++++++++++++++++
SELECT to_char(start_time,'hh24:mi:ss') stime,message,( sofar/totalwork)* 100 percent FROM v$session_longops where sid ='&1'SELECT sid,SQL_ID,to_char(start_time,'hh24:mi:ss') stime,message,( sofar/totalwork)* 100 percent FROM v$session_longops where message like '%WIP%';
For RMAN :
===========
SELECT sid, serial#, context, sofar, totalwork, round(sofar/totalwork*100,2) "% Complete" FROM v$session_longops WHERE opname LIKE 'RMAN%' AND opname NOT LIKE '%aggregate%' AND totalwork != 0 AND sofar <> totalwork;

For perticular SID :
=====================
SELECT sid, serial#, context, sofar, totalwork, round(sofar/totalwork*100,2) "% Complete" FROM v$session_longops WHERE sid='&1' AND totalwork != 0 AND sofar <> totalwork

For All Sessions :
=============
SELECT sid, serial#, context, sofar, totalwork, round(sofar/totalwork*100,2) "% Complete" FROM v$session_longops WHERE totalwork != 0 AND sofar <> totalwork

+++++++++++++++++++++++++++
Rollback Segments Usage :
+++++++++++++++++++++++++++
select a.sid, a.username, a.osuser, b.USED_UBLK "UNDO BLOCKS", c.Name "UNDO NAME"from v$session a, v$transaction b, v$rollname cwhere a.saddr = b.ses_addr and b.XIDUSN = c.USN ;
++++++++++++++++++++++++++++++++
Find Unix Process ID from SID:
++++++++++++++++++++++++++++++++
set pages 1000
set linesize 190
col username for a10
select a.PID "Ora PID",a.SPID "Server PID",a.LATCHWAIT,b.Program,b.Username,b.Osuser,b.Process "Clinet Process"from v$process a,v$session b where a.addr=b.paddr and b.sid=&1

++++++++++++++++++++++++++++++++
Find SID from Unix Process ID :
++++++++++++++++++++++++++++++++
undefine unixprocessid
set pages 5000
set verify offset feed on
set long 20000
set pages 5000
SELECT b.osuser,
b.username,
a.pid,
a.spid,
c.sql_text,
b.saddr,
b.sid,
b.serial#,
to_char(b.logon_time,'DD-MON-YY HH24:MI:SS') "LOGON_TIME",
b.username,
b.program,
b.process client,
a.spid server
FROM v$sqlarea c,v$session b,v$process a
WHERE a.spid = '&1'
AND b.paddr = a.addr
AND b.sql_hash_value = c.hash_value(+)
AND b.sql_address = c.address(+) ;

ps aux head
ps -ef sort +3 tail -10

++++++++++++++++++++++
SORT Segment Usage :
++++++++++++++++++++++
select rpad(sid,5,' ')as sid,username,rpad(program,15,' ') as prgm,rpad(blocks*16384/(1024*1024)' MB ',10,' ') as tempsize, segtype from v$session,v$sort_usage where saddr=session_addr order by blocks ;

SELECT s.sid, s.serial#, s.username, u.tablespace, u.contents, u.extents, u.blocksFROM v$session s, v$sort_usage u WHERE s.saddr=u.session_addr
/
CLEAR COLUMNS

column TABLESPACE_NAME format a10
column USERNAME format a10
prompt Total Temp spaceprompt
=======================================
select sum(bytes/1024/1024) Tot_MB,tablespace_name from v$temp_extent_mapgroup by tablespace_nameorder by tablespace_name/ prompt Used Temp spaceprompt =======================================
select (bytes_used/1024/1024) USED_MB,tablespace_name from v$temp_extent_poolorder by tablespace_name
/
prompt Actual user who is using sort segment

prompt =====================================
SELECT s.username,s.sid, u.tablespace, u.contents, u.extents, u.blocks,u.segtypeFROM v$session s, v$sort_usage uWHERE s.saddr=u.session_addr;

prompt Actual usage of sort segment
prompt ============================
select TABLESPACE_NAME,TOTAL_BLOCKS,USED_BLOCKS,FREE_BLOCKS from v$sort_segment;

prompt extent info for sort segement
prompt =============================
SELECT tablespace_name, extent_size, total_extents, used_extents, free_extents, max_used_size FROM v$sort_segment;

prompt sort ratio
prompt ==========
select ((mem.value)/(mem.value+disk.value)) "Sort Ratio"from v$sysstat mem, v$sysstat diskwhere mem.name = 'sorts (memory)' and disk.name = 'sorts (disk)';

prompt temp tablepsace actual usage ratio
prompt ==================================
select (b.value/a.value)*100 temp_use_ratio from(select sum(bytes) value from v$temp_extent_map) a,(select sum(BYTES_USED) value from v$temp_extent_pool) b;

+++++++++++++++++++++++++++++++++++++
MVIEW refresh Status on MASTER Site :
+++++++++++++++++++++++++++++++++++++
set pages 1000
set linesize 180
col SNAPSHOT_SITE for a30
select r.name,
r.snapshot_site,
l.current_snapshots
from dba_registered_snapshots r, dba_snapshot_logs l
where r.snapshot_id = l.snapshot_id
and
l.master in (select master from dba_snapshot_logs) ;
CLEAR COLUMNS
++++++++++++++++++++++++
LOCK Session Details :
++++++++++++++++++++++++
SELECT
DECODE(request,0,'Holder: ','Waiter: ')sid sess,
id1,
id2,
lmode,
request,
type
FROM V$LOCK
WHERE (id1, id2, type) IN(SELECT id1, id2, type FROM V$LOCK WHERE request>0)ORDER BY id1, request;

TX type:6 ==> this is transaction exclusive lock
( due to update where other transaction waiting for the update of same )

++++++++++++++++++++++++++++++++++++++++++++
Query To Get the SID FROM UNIX PROCESS ID
++++++++++++++++++++++++++++++++++++++++++++
select sid, serial# from v$session where process='&1';
column schemaname format a10
heading "Oracle User"
column osuser format a15
heading "Osuser"
column module format a18
heading "Module"
column terminal format a10
heading "Terminal"
column status format a10
heading "Status"
column sid format 99999
heading "Sid"
column serial# format 9999999
heading "Serial#"
column program format a20
heading "Program"
col username format a8
SELECT p.spid,
s.osuser,
s.username,
s.sid,
s.serial#,
s.module,
s.status,
to_char(s.logon_time, 'DD-MON-YY HH24:MI:SS') logontime,
s.program,
s.LAST_CALL_ET/60 Since_Updated
FROM v$process p, v$session s WHERE s.sid= '&1'

++++++++++++++++++++++++++++++++++
Query To Check The LogOn Time
+++++++++++++++++++++++++++++++++++
select 'Sid, Serial# ' s.sid' , 's.serial#chr(10) 'Form User : ' fu.user_namechr(10) 'Machine - Terminal : ' s.machine' - ' s.terminalchr(10)'OS Process Ids : ' s.process'(Client) 'p.spid' (Server)' ' (Since)' to_char(s.logon_time,'DD-MON-YYYY HH24:MI:SS')chr(10) 'Client Program Name : 's.programchr(10) 'Action / Module : 's.action' / 's.modulechr(10) 'User Description : ' fu.descriptionchr(10)
'-----------------------------------------------------------------'
from gv$process p,gv$session s, apps.fnd_logins f, apps.fnd_user fu where p.addr = s.paddr and p.inst_id=s.inst_id and f.spid (+) = s.process and p.spid='&1' and fu.user_id (+) = f.user_id and f.end_time is null order by f.start_time;

How to take backup of dblinks & synonym etc

For Dropping objects :
select 'drop 'object_type,owner'.' object_name';' from dba_objects where owner='BPA2' and object_type!='INDEX';
select 'drop 'object_type,owner'.' object_name' cascade constraint;' from dba_objects where owner='BPA2' and object_type!='INDEX';
Taking the backup of Synonyms :
select 'create synonym 'synonym_name' for 'table_owner'.'table_name'@'db_link'; ' Create_Synonym_Script from dba_synonyms where owner=upper('&owner');
Taking the backup of Database links :
select 'conn 'owner'/&&'owner chr(10)'create database link 'rtrim(ltrim(db_link))' ''connect to 'rtrim(ltrim(username))' identified by 'rtrim(ltrim(password))' using '''''rtrim(ltrim(b.host))''''';' from dba_db_links A, sys.link$ B where A.db_link = B.name and B.ctime = A.created and owner like '&Owner' order by owner;


DB link :
select 'conn 'owner'/&&'owner chr(10)'create database link 'rtrim(ltrim(db_link))' ''connect to 'rtrim(ltrim(username))' identified by 'rtrim(ltrim(password))' using '''''rtrim(ltrim(b.host))''''';' from dba_db_links A, sys.link$ B where A.db_link = B.name and B.ctime = A.created and owner like '&Owner' order by owner;

Synonym:
select 'create synonym 'synonym_name' for 'table_owner'.'table_name'@'db_link'; '
Create_Synonym_Script from dba_synonyms where owner=upper('&owner');
select count(*),object_type,status from user_objects group by object_type,status;

Blocking session issue how to resolve them

***************** blocking session checking & blocking sql ************
select count(*) from v$Lock where block=1;
col host_name for a20
select instance_name, status , host_name from v$instance;
select count(*) from v$Lock where block=1;
select prev_hash_value from v$session where sid='&466';

select sql_text from v$sqlarea where hash_value='&hash_value';
************************* blocking session picture **************************
SQL> select sid from v$lock where block=1;
O/p give u the sid which is blocking
SQL> select prev_hash_value from v$session where sid='&466';
O/P paste sid it gives the hash_value
SQL> select sql_text from v$sqlarea where hash_value='&hash_value'
paste ths hash_value to get the sql blocking the session
*************************************************************************