Thursday, July 14, 2011

Creating Dataguard with Rman

Dataguard By Rman On Same Directory Structure
ON PRIMARY DATABASE ENABLE ARCHIVE LOG
à   SQL> alter database FORCE logging
1à SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2à SQL> startup mount
ORACLE instance started.

Total System Global Area  247463936 bytes
Fixed Size                  1218748 bytes
Variable Size              79693636 bytes
Database Buffers          159383552 bytes
Redo Buffers                7168000 bytes
Database mounted.

à SQL> alter database archivelog;
Database altered.

à SQL> alter database open;

 à Do Oracle 10g software only installation on Standby site

SETUP TNSNAMES.ORA ON PRIMARY DB
PRIM =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = tamirpm)
    )
  )

stby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = tamirpm)
    )
  )


SETUP TNSNAMES.ORA ON STANDBY
PRIM =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = tamirpm)
    )
  )

STBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = tamirpm)
    )
  )

SETUP INITIALIZATION PARAMETER

The fetch archive log (FAL) client and server resolve gaps detected in the range of archived redo log files generated at the primary database and received at the physical standby database.

The FAL client requests the transfer of archived redo log files automatically.
The FAL server services the FAL requests coming from the FAL client.

Alter system set FAL_SERVER=STBY scope=both sid=’*’;

Alter system set FAL_CLIENT=PRIM scope=both;

Alter system set standby_file_management=auto scope=both;

à Alter system set LOG_ARCHIVE_DEST_1='LOCATION=/opt/oracle/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES)' scope=both;
OR
Alter system set LOG_ARCHIVE_DEST_1='LOCATION=/opt/oracle/archive' scope=both;

à ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=STBY LGWR SYNC AFFIRM' scope=both;

Reference Oracle® Data Guard Concepts and Administration 10g Release 2 (10.2) B14239-05

Specifying Synchronous or Asynchronous Network Transmission
The LGWR process synchronously writes to the local online redo log files at the same time it transmits redo data to the remote destination:

The SYNC attribute performs all network I/O synchronously, in conjunction with each write operation to the online redo log file, and waits for the network I/O to complete. 
 This is the default network transmission setting.

Specifying the SYNC attribute on the LOG_ARCHIVE_DEST_n parameter is optional, because this is the default for LGWR archival processing.


The ASYNC attribute performs all network I/O asynchronously and control is returned to the executing application or user immediately, without waiting for the network I/O to complete.

When the LGWR and ASYNC attributes are specified, the log writer process writes to the local online redo log file, while the network server (LNSn) processes (one for each destination) asynchronously transmit the redo to remote destinations. The LGWR process continues processing the next request without waiting for the LNS network I/O to complete.
If redo transport services transmit redo data to multiple remote destinations, the LNSn processes (one for each destination) initiate the network I/O to all of the destinations in parallel.

ADD THE STANDBY REDOLOG FILE AT PRIMARY SITE ONLY FOR SWITCH OVER

ALTER DATABASE ADD STANDBY LOGFILE GROUP 11 ('/opt/oracle/db/oradata/tamirpm/stlog11.rdo') SIZE 50M;

ALTER DATABASE ADD STANDBY LOGFILE GROUP 12 ('/opt/oracle/db/oradata/tamirpm/stlog12.rdo') SIZE 50M;

ALTER DATABASE ADD STANDBY LOGFILE GROUP 13 ('/opt/oracle/db/oradata/tamirpm/stlog13.rdo') SIZE 50M;

à SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------
        11          0          0 YES UNASSIGNED
        12          0          0 YES UNASSIGNED
        13          0          0 YES UNASSIGNED



COPY THE PASSWORD FILE, SPFILE, LISTENER files FROM PRIMARY TO STANBY SERVER

[oracle@rhel4 ~]$ scp -p /opt/oracle/db/dbs/inittamirpm.ora 192.168.1.11:/opt/oracle/db/dbs/

[oracle@rhel4 ~]$ scp -p /opt/oracle/db/dbs/PWDoratamirpm 192.168.1.11:/opt/oracle/db/dbs/

[oracle@rhel4 ~]$ scp -p /opt/oracle/db/network/admin/listner.ora 192.168.1.11:/opt/oracle/db/network/admin/

CREATE A FOLDER FOR RMAN BACKUP ON BOTH MACHINES

[root@rhel4 oracle]# mkdir bkup
[root@rhel4 oracle]# chown -R oracle.dba bkup
[root@rhel4 oracle]# chmod -R 775 bkup

Make Directory on standby server

Bdump , Udump, cdump, archive , oradata/SID

[root@rhel4 oracle]# mkdir bkup
[root@rhel4 oracle]# chown -R oracle.dba bkup
[root@rhel4 oracle]# chmod -R 775 bkup

TAKE A BACKUP ON PRIMARY DB
[oracle@rhel4 bin]$ ./rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Feb 11 15:22:25 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: TAMIRPM (DBID=3686906617)
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/opt/oracle/bkup/%d_%F.rman';
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT  '/opt/oracle/bkup/bk%d_%s_%p.rman';
       Backup the current production database to create a standby database:
RMAN>
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset  database format '/opt/oracle/bkup/D%U';
backup current controlfile for standby format '
/opt/oracle/bkup/C%U';
sql 'alter system archive log current';
}

OR

RMAN> Backup as compressed backupset  database include current controlfile for standby;
SQL> alter system archive log current;

Move backup & last 3 archived logs from primary to standby server

[oracle@rhel4 ~]$ scp -p /opt/oracle/bkup/* 192.168.1.11:/opt/oracle/bkup/
oracle@192.168.1.11's password:
bkTAMIRPM_1_1.rman                                                               100% 4026KB   3.9MB/s   00:01
bkTAMIRPM_2_1.rman                                                               100%  569MB   2.4MB/s   03:57
bkTAMIRPM_3_1.rman                                                               100% 6976KB   2.3MB/s   00:03
bkTAMIRPM_4_1.rman                                                               100%   20KB  20.0KB/s   00:00
[oracle@rhel4 ~]$


Create password file on standby server if not moved from source Db and start standby DB to nomount;
Note Password should be same as primary server DB

orapwd file='/opt/oracle/db/dbs/orapwtamirpm' password=oracle entries=5

sqlplus connect / as sysdba

sql> startup nomount

Connect to Rman on standby server

Note enter service name of Primary site.

RMAN target sys/oracle@prim auxiliary sys/oracle@stby

RMAN> duplicate target database for standby nofilenamecheck dorecover;

We will now put our DB into managed recovery mode. This starts the redo apply service.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
Now Switch the logfile on Primary Site
Alter system switch logfile;

Now let’s see if our logs get applied on the standby server.
From the standby db issue:

SQL> select sequence#, applied, status from v$archived_log;
SEQUENCE#
----------
22

Select Group#, status from v$standby_log;
Set the data protection mode.
To specify a data protection mode, issue the

SQL> ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE {PROTECTION | AVAILABILITY | PERFORMANCE}
ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY;
Confirm the configuration is operating in the new protection mode.
Query the V$DATABASE view to confirm the Data Guard configuration is operating in
the new protection mode. For example:

SQL> SELECT PROTECTION_MODE, PROTECTION_LEVEL FROM V$DATABASE;

PROTECTION_MODE PROTECTION_LEVEL
--------------------- ---------------------
MAXIMUM AVAILABILITY MAXIMUM AVAILABILIT
To display the list of archived redo log files that are on the standby system,
query the V$ARCHIVED_LOG view on the standby database:

SQL> SELECT NAME FROM V$ARCHIVED_LOG;
NAME
--------------------------------------------------------------------------------
/arc_dest/log_1_771.arc
/arc_dest/log_1_772.arc
/arc_dest/log_1_773.arc
/arc_dest/log_1_774.arc
Table 5–2 Minimum Requirements for Data Protection Modes


Maximum Protection
Maximum Availability
Maximum Performance

Redo archival process
LGWR
LGWR
LGWR or ARCH
Network transmission
mode
SYNC
SYNC
SYNC or ASYNC when using
LGWR process. SYNC if using
ARCH process
Disk write option
AFFIRM
AFFIRM
AFFIRM or NoAFFRIM
Standby redo log required?
Yes
Yes
No, but it is recommended




On a physical standby database
To determine if there is an archive gap on your physical standby database, query the V$ARCHIVE_GAP view as shown in the following example:

SQL> SELECT * FROM V$ARCHIVE_GAP;

THREAD#     LOW_SEQUENCE#     HIGH_SEQUENCE#
----------- -------------     --------------
1                 7           10

The output from the previous example indicates your physical standby database is currently missing log files from sequence 7 to sequence 10 for thread 1. After you identify the gap, issue the following SQL statement on the primary database to locate the archived redo log files on your primary database (assuming the local archive destination on the primary database is LOG_ARCHIVE_DEST_1):

SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE THREAD#=1 AND DEST_ID=1 AND
2> SEQUENCE# BETWEEN 7 AND 10;
NAME
--------------------------------------------------------------------------------
/primary/thread1_dest/arcr_1_7.arc
/primary/thread1_dest/arcr_1_8.arc

Copy these log files to your physical standby database and register them using the  ALTER DATABASE REGISTER LOGFILE statement on your physical standby

database. For example:
SQL> ALTER DATABASE REGISTER LOGFILE
'/physical_standby1/thread1_dest/arcr_1_7.arc';
SQL> ALTER DATABASE REGISTER LOGFILE
'/physical_standby1/thread1_dest/arcr_1_8.arc';

After you register these log files on the physical standby database, you can restart Redo Apply.


Monitoring Log File Archival Information

Step 1 Determine the status of redo log files.
Enter the following query on the primary database to determine the status of all online redo log files:

SQL> SELECT THREAD#, SEQUENCE#, ARCHIVED, STATUS FROM V$LOG order by 1,2;

SQL> SELECT THREAD#, SEQUENCE#,applied, STATUS FROM V$ARCHIVED_LOG order by 1, 2;

Step 2 Determine the most recent archived redo log file.
Enter the following query on the primary database to determine recently archived thread and sequence number:

SQL> SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

Step 3 Determine the most recent archived redo log file at each destination.
Enter the following query on the primary database to determine which archived redo log file was most recently transmitted to each of the archiving destinations:

SQL> SELECT DESTINATION, STATUS, ARCHIVED_THREAD#, ARCHIVED_SEQ#
2> FROM V$ARCHIVE_DEST_STATUS
3> WHERE STATUS <> 'DEFERRED' AND STATUS <> 'INACTIVE';


DESTINATION          STATUS ARCHIVED_THREAD# ARCHIVED_SEQ#
------------------ ------ ---------------- -------------
/private1/prmy/lad   VALID               1             947
standby1             VALID               1             947


The most recently written archived redo log file should be the same for each archive destination listed. If it is not, a status other than VALID might identify an error encountered during the archival operation to that destination.

Step 4 Find out if archived redo log files have been received.
You can issue a query at the primary database to find out if an archived redo log file was not received at a particular site. Each destination has an ID number associated with it. You can query the DEST_ID column of the V$ARCHIVE_DEST fixed view on the primary database to identify each destination’s ID number. Assume the current local destination is 1, and one of the remote standby destination IDs is 2. To identify which log files are missing at the standby destination, issue the following query:

SQL> SELECT LOCAL.THREAD#, LOCAL.SEQUENCE# FROM
2> (SELECT THREAD#, SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=1)
3> LOCAL WHERE
4> LOCAL.SEQUENCE# NOT IN
5> (SELECT SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND
6> THREAD# = LOCAL.THREAD#);


Monitoring the Performance of Redo Transport Services

SQL> select error from V$archive_dest;

Recover Database after all control files are lost


Shutdown the database if it’s not shutdown yet.

>Shutdown abort

You Must know the all datafile location or you have TRACE of Controlfile.


Note: how to create trace of control file
> alter database backup control file to trace

A text trace file will be create to udump directory

Or

> alter database backup controlfile to 'e:\tmp\ctrl.ctl';


> Startup nomount;



> RECOVER DATABASE
======================================================================
> ALTER DATABASE OPEN;
=======================================================================

> ALTER TABLESPACE TEMP ADD TEMPFILE 'D:\oracle\product\10.2.0\orcl\TEMP01.DBF'
     SIZE 29360128  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
=========================================================================
> ALTER TABLESPACE TEMP ADD TEMPFILE 'D:\oracle\product\10.2.0\orcl\TEMP01.DBF'
     SIZE 29360128  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
========================================================================


steps for "Oracle (Real Time) Downstream".

These steps are tested in the following 2 scenarios:

* Source Database 10gR2/Downstream Database 10gR2
* Source Database 10gR2/Downstream Database 11gR2
=====================================
Database 1==Primary Database=="ORCL1"
=====================================
-----------------------------Start Step 1----------------------------------------------------
conn /as sysdba
CREATE TABLESPACE streams_tbs DATAFILE '/oracle/10g/oradata/orcl1/strm01.dbf' SIZE 100M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
CREATE USER strmadmin IDENTIFIED BY strmadmin
DEFAULT TABLESPACE streams_tbs
QUOTA UNLIMITED ON streams_tbs;
GRANT DBA TO strmadmin;
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'strmadmin',
grant_privileges => true);
END;
SELECT * FROM dba_streams_administrator;
-----------------------------End Step 1----------------------------------------------------
-----------------------------Start Step 3--------------------------------------------------
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=SPFILE;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE="ORCL1" LGWR SYNC NOREGISTER
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=ORCL1'
SCOPE=BOTH;

ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCL1)' SCOPE=BOTH;

ALTER SYSTEM SET log_archive_dest_1='LOCATION=/u01/app2/dest_1';
ALTER SYSTEM SET log_archive_dest_state_1 = 'ENABLE' SCOPE=BOTH;
ALTER SYSTEM SET log_archive_format = 'ORCL_%t_%s_%r.arc';
shutdown immediate
startup mount
alter database archivelog;
alter database open;
-----------------------------End Step 3----------------------------------------------------
-----------------------------Start Step 5----------------------------------------------------
ALTER SYSTEM ARCHIVE LOG CURRENT;
-----------------------------Stop Step 5----------------------------------------------------
-----------------------------Start Step 7----------------------------------------------------
conn system/oracle
!mkdir /u01/schema_export
!chmod 777 /u01/schema_export
create or replace directory schema_export as '/u01/schema_export';
!expdp system/oracle SCHEMAS=SCOTT DUMPFILE=schema_export:schema.dmp LOGFILE=schema_export:schema.log
-----------------------------Stop Step 7----------------------------------------------------
====================================
Database 2==Downstream Site=="ORCL2"
====================================
-----------------------------Start Step 2----------------------------------------------------
conn /as sysdba
CREATE TABLESPACE streams_tbs DATAFILE '/oracle/10g/oradata/orcl2/strm01.dbf'SIZE 100M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
CREATE USER strmadmin IDENTIFIED BY strmadmin
DEFAULT TABLESPACE streams_tbs
QUOTA UNLIMITED ON streams_tbs;
GRANT DBA TO strmadmin;
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'strmadmin',
grant_privileges => true);
END;
SELECT * FROM dba_streams_administrator;
exec DBMS_LOGMNR_D.SET_TABLESPACE ('streams_tbs');
conn strmadmin/strmadmin
create database link ostrm connect to strmadmin identified by strmadmin using 'orcl1';
select * from dual@ostrm;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=spfile;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='LOCATION=/oracle/arch2/dest_2/
VALID_FOR=(STANDBY_LOGFILE,PRIMARY_ROLE)'
SCOPE=spfile;

ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl1,orcl2)' SCOPE=BOTH;
conn /as sysdba
ALTER DATABASE ADD STANDBY LOGFILE GROUP 4
('/oracle/10g/oradata/orcl2/slog4.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 5
('/oracle/10g/oradata/orcl2/slog5.rdo') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 6
('/oracle/10g/oradata/orcl2/slog6.rdo') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 7
('/oracle/10g/oradata/orcl2/slog7.rdo') SIZE 50M;

SELECT GROUP#, THREAD#, SEQUENCE#, ARCHIVED, STATUS FROM V$STANDBY_LOG;
conn /as sysdba
ALTER SYSTEM SET log_archive_dest_1='LOCATION=/u01/app2/dest_1' SCOPE=BOTH;
ALTER SYSTEM SET log_archive_dest_state_1 = 'ENABLE' SCOPE=BOTH;
ALTER SYSTEM SET log_archive_format = 'ORCL1_%t_%s_%r.arc' SCOPE=SPFILE;

shutdown immediate
startup mount
alter database archivelog;
alter database open;

ALTER SYSTEM SET log_archive_max_processes=5 SCOPE=BOTH;
-----------------------------End Step 2----------------------------------------------------
-----------------------------Start Step 4----------------------------------------------------
conn strmadmin/strmadmin
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE(
queue_table => 'strmadmin.DS_QT',
queue_name => 'strmadmin.DS_Q',
queue_user => 'STRMADMIN');
END;
/
select name, queue_table from user_queues;
conn strmadmin/strmadmin
BEGIN
DBMS_APPLY_ADM.CREATE_APPLY(
queue_name => 'DS_Q',
apply_name => 'DS_A',
apply_captured => TRUE
);
END;
/
SELECT apply_name, status, queue_name FROM DBA_APPLY;
SELECT parameter, value, set_by_user
FROM DBA_APPLY_PARAMETERS
WHERE apply_name = 'DS_A';
conn strmadmin/strmadmin
BEGIN
DBMS_CAPTURE_ADM.CREATE_CAPTURE(
queue_name => 'DS_Q',
capture_name => 'DS_C',
rule_set_name => NULL,
start_scn => NULL,
source_database => 'ostrm',
use_database_link => true, -- For administrative purposes.
first_scn => NULL,
logfile_assignment => 'implicit'); -- capture process accepts redo data implicitly from Source.
END;
/
SELECT capture_name, status from dba_capture;
SELECT parameter, value, set_by_user FROM DBA_CAPTURE_PARAMETERS;
conn strmadmin/strmadmin
BEGIN
DBMS_CAPTURE_ADM.SET_PARAMETER(
capture_name => 'DS_C',
parameter => 'downstream_real_time_mine',
value => 'y');
END;
/
-----------------------------End Step 4----------------------------------------------------
-----------------------------Start Step 6----------------------------------------------------
--check that the status of one/more of the standby logs has changed from UNASSIGNED to ACTIVE:
SELECT GROUP#, THREAD#, SEQUENCE#, ARCHIVED, STATUS FROM V$STANDBY_LOG;
conn strmadmin/strmadmin
BEGIN
DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'scott',
streams_type => 'capture',
streams_name => 'ds_c',
queue_name => 'ds_q',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'ORCL1',
inclusion_rule => TRUE);
END;
/
/*
Check the created rules
*/
SELECT rule_name, rule_condition
FROM DBA_STREAMS_SCHEMA_RULES
WHERE streams_name = 'DS_C'
AND streams_type = 'CAPTURE';
-----------------------------Stop Step 6----------------------------------------------------
-----------------------------Start Step 8----------------------------------------------------
conn system/oracle
!mkdir /u01/schema_import
!chmod 777 /u01/schema_import
create or replace directory schema_import as '/u01/schema_import';
-- copy the dump file schema.dmp from '/u01/schema_export' on source site to '/u01/schema_import' on downstream site.
!impdp system/oracle SCHEMAS=SCOTT DIRECTORY=schema_import DUMPFILE=schema.dmp
/*
select * from DBA_APPLY_INSTANTIATED_OBJECTS;
select * from DBA_APPLY_INSTANTIATED_SCHEMAS;
*/
conn strmadmin/strmadmin
exec DBMS_APPLY_ADM.START_APPLY(apply_name => 'DS_A');
select apply_name, status from dba_apply;
conn strmadmin/strmadmin
exec DBMS_CAPTURE_ADM.START_CAPTURE(capture_name => 'DS_C');
select capture_name, status from dba_capture;
-----------------------------Stop Step 8----------------------------------------------------
=====================CHECKING STREAMS PROPER FUNCTIONING==========================
Perform some DMLs on Primary/Source with scott user. Check each DML reflection on Downstream site.
==================================================================================

Listing Chained Rows of Tables and Clusters

 

You can look at the chained and migrated rows of a table or cluster using the ANALYZE statement with the LIST CHAINED ROWS clause. The results of this statement are stored in a specified table created explicitly to accept the information returned by the LIST CHAINED ROWS clause. These results are useful in determining whether you have enough room for updates to rows.


Creating a CHAINED_ROWS Table

To create the table to accept data returned by an ANALYZE...LIST CHAINED ROWS statement, execute the UTLCHAIN.SQL or UTLCHN1.SQL script. These scripts are provided by the database. They create a table named CHAINED_ROWS in the schema of the user submitting the script.
Note:
Your choice of script to execute for creating the CHAINED_ROWS table is dependent upon the compatibility level of your database and the type of table you are analyzing. See the Oracle Database SQL Language Reference for more information.
After a CHAINED_ROWS table is created, you specify it in the INTO clause of the ANALYZE statement. For example, the following statement inserts rows containing information about the chained rows in the emp_dept cluster into the CHAINED_ROWS table:
ANALYZE CLUSTER emp_dept LIST CHAINED ROWS INTO CHAINED_ROWS;
See Also:


Eliminating Migrated or Chained Rows in a Table

You can use the information in the CHAINED_ROWS table to reduce or eliminate migrated and chained rows in an existing table. Use the following procedure.
  1. Use the ANALYZE statement to collect information about migrated and chained rows.
    ANALYZE TABLE order_hist LIST CHAINED ROWS;
  2. Query the output table:
    SELECT *
    FROM CHAINED_ROWS
    WHERE TABLE_NAME = 'ORDER_HIST';

    OWNER_NAME TABLE_NAME CLUST... HEAD_ROWID TIMESTAMP
    ---------- ---------- -----... ------------------ ---------
    SCOTT ORDER_HIST ... AAAAluAAHAAAAA1AAA 04-MAR-96
    SCOTT ORDER_HIST ... AAAAluAAHAAAAA1AAB 04-MAR-96
    SCOTT ORDER_HIST ... AAAAluAAHAAAAA1AAC 04-MAR-96
    The output lists all rows that are either migrated or chained.
  3. If the output table shows that you have many migrated or chained rows, then you can eliminate migrated rows by continuing through the following steps:
  4. Create an intermediate table with the same columns as the existing table to hold the migrated and chained rows:
    CREATE TABLE int_order_hist
    AS SELECT *
    FROM order_hist
    WHERE ROWID IN
    (SELECT HEAD_ROWID
    FROM CHAINED_ROWS
    WHERE TABLE_NAME = 'ORDER_HIST');
  5. Delete the migrated and chained rows from the existing table:
    DELETE FROM order_hist
    WHERE ROWID IN
    (SELECT HEAD_ROWID
    FROM CHAINED_ROWS
    WHERE TABLE_NAME = 'ORDER_HIST');
  6. Insert the rows of the intermediate table into the existing table:
    INSERT INTO order_hist
    SELECT *
    FROM int_order_hist;
  7. Drop the intermediate table:
    DROP TABLE int_order_history;
  8. Delete the information collected in step 1 from the output table:
    DELETE FROM CHAINED_ROWS
    WHERE TABLE_NAME = 'ORDER_HIST';
  9. Use the ANALYZE statement again, and query the output table.
Any rows that appear in the output table are chained. You can eliminate chained rows only by increasing your data block size. It might not be possible to avoid chaining in all situations. Chaining is often unavoidable with tables that have a LONG column or large CHAR or VARCHAR2 columns.

9i Statspack install steps and Creating Report Steps


9i Installing the Statspack

Installation of the Oracle Statspack tool is a relatively simple process. The following is a step-by-step guide to the process of installing Oracle Statspack on a UNIX system.

  1. Navigate to the $ORACLE_HOME/rdbms/admin directory as follows:
  2. # cd $ORACLE_HOME/rdbms/admin/
  3. Start the Statspack install script, spcreate.sql, as follows:
  4. # sqlplus "/ as sysdba" @spcreate.sql
  5. Enter a password for the PERFSTAT user when prompted.
  6. Enter the default tablespace (tools) for the PERFSTAT user when prompted.
  7. Enter the temporary tablespace (temp) for the PERFSTAT user when prompted.
  8. Exit sqlplus as follows:
  9. SQL> exit

Collecting Snapshots

Once the Oracle Statspack tool is installed, snapshots must be collected to evaluate database performance. Snapshots are moment-in-time collections of all of the database statistics that the Oracle database continuously collects. Once two snapshots are collected, they can be compared to identify the activity that occurred during the interval between the two snapshots.

Snapshots can be collected a various levels, each increasing level collecting a greater amount of information about the database. As the levels go higher, each level is inclusive of the information collected at the levels below it.

Table A-1 Levels of Statistics
Level
 Information Collected
0
General Performance Statistics
5
Addition Data: SQL Statements
6
Addition Data: SQL Plans and SQL Plan Usage
7
Addition Data: Segment Level Statistics
10
Addition Data: Parent and Child Latches
 

To collect statistics

  1. Connect to the database as the PERFSTAT user as follows:
  2. sqlplus perfstat/<password>
  3. Create a snapshot with the statspack package as follows:
  4. SQL> execute statspack.snap(i_snap_level=>7);
  5. Exit SQLPLUS as follows:
  6. SQL> exit

Generating Reports

Oracle Statspack comes with a comprehensive reporting script called spreport.sql. When this script is run, it outputs a list of available snapshots, asks the user for two snapshot IDs and a name for the report, and then outputs a text report of the results.

To run a Statspack report.

  1. Navigate to the $ORACLE_HOME/rdbms/admin directory as follows:
  2. # cd $ORACLE_HOME/rdbms/admin/
  3. Run the standard Statspack report as follows:
  4. # sqlplus perfstat/<password> @spreport
    • Enter a beginning snapshot ID.
    • Enter an ending snapshot ID.
    • Enter a name for the report or accept the default.
    • Exit SQLPLUS as follows:
    • SQL> exit
       


      Zaman Ahmed Tatari
      DATABASE ADMINISTRATOR
      OCP 9i/10g(DBA/Developer Track) 
      KASB BANK LIMITED
      Cell #: 92-300-2542241