Friday, October 21, 2011

Table fragmentation

Table frgmentation is commonly known, but nevertheless I'll drop here a line.
Assume we got filled table and then we delete some rows from it...

1. Create table and fill it:
sqlplus> create table scott.tt (id number(5), str varchar2(2000));

Table created.

sqlplus> create sequence scott.tt_seq start with 1;

Sequence created.

sqlplus> insert into scott.tt select scott.tt_seq.nextval, dbms_random.string('U', 2000) from dual connect by level <= 30000;

30000 rows created.

sqlplus> commit;

Commit complete.

2. Show some statistics:
sqlplus> exec dbms_stats.gather_table_stats('scott', 'TT');

PL/SQL procedure successfully completed.

sqlplus> select t.num_rows, s.blocks, s.bytes from dba_segments s, dba_tables t -

> where s.owner=t.owner and s.segment_name=t.table_name and -

> s.owner = 'scott' and segment_name='TT';

  NUM_ROWS     BLOCKS      BYTES

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

     29989      10240   83886080

sqlplus> set autotrace traceonly

sqlplus> select * from scott.tt;

30000 rows selected.



Execution Plan

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

Plan hash value: 481005422

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

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

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

|   0 | SELECT STATEMENT  |      | 29989 |    57M|  2218   (1)| 00:00:27 |

|   1 |  TABLE ACCESS FULL| TT   | 29989 |    57M|  2218   (1)| 00:00:27 |

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

Statistics

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

          1  recursive calls

          0  db block gets

      12108  consistent gets

       5152  physical reads

          0  redo size

   60577626  bytes sent via SQL*Net to client

      14239  bytes received via SQL*Net from client

       2001  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

      30000  rows processed



3. Now let's delete some rows from table

sqlplus> set autotrace off

sqlplus> delete from scott.tt where id < 30000;

29999 rows deleted.

sqlplus> commit;

Commit complete.

4. Show stats again
sqlplus> exec dbms_stats.gather_table_stats('scott', 'TT');

PL/SQL procedure successfully completed.

sqlplus> select t.num_rows, s.blocks, s.bytes from dba_segments s, dba_tables t -

> where s.owner=t.owner and s.segment_name=t.table_name and -

> s.owner = 'scott' and segment_name='TT';

  NUM_ROWS     BLOCKS      BYTES

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

         1      10240   83886080

sqlplus> set autotrace traceonly

sqlplus> select * from scott.tt;



Execution Plan

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

Plan hash value: 481005422



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

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

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

|   0 | SELECT STATEMENT  |      |     1 |  2004 |  2217   (1)| 00:00:27 |

|   1 |  TABLE ACCESS FULL| TT   |     1 |  2004 |  2217   (1)| 00:00:27 |

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

Statistics

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

          0  recursive calls

          0  db block gets

      10108  consistent gets

       6639  physical reads

          0  redo size

       2258  bytes sent via SQL*Net to client

        246  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed

There's 1 row in the table only, but nevetheless we made 10108 consistent reads. Why?
Because of:
1. HWM grows while insert data into table, but never falls down after delete operation (except truncate).
2. Oracle reads all the blocks in a table up to HWM while doing FTS, despite whether these blocks contains data or not.

What we should do? There're many thins to do about it. For example "shrink".
sqlplus> alter table scott.tt shrink space;

alter table scott.tt shrink space

*

ERROR at line 1:

ORA-10636: ROW MOVEMENT is not enabled



sqlplus> alter table scott.tt enable row movement;

Table altered.

sqlplus> alter table scott.tt shrink space;

Table altered.

Statistics:
sqlplus>  exec dbms_stats.gather_table_stats('scott', 'TT');

PL/SQL procedure successfully completed.

sqlplus> select * from scott.tt;



Execution Plan

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

Plan hash value: 481005422



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

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

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

|   0 | SELECT STATEMENT  |      |     1 |  2004 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS FULL| TT   |     1 |  2004 |     2   (0)| 00:00:01 |

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



Statistics

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

          1  recursive calls

          0  db block gets

          4  consistent gets

          0  physical reads

          0  redo size

       2256  bytes sent via SQL*Net to client

        246  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed



sqlplus> set autotrace off

sqlplus> select t.num_rows, s.blocks, s.bytes from dba_segments s, dba_tables t

  2  where s.owner=t.owner and s.segment_name=t.table_name and

  3  s.owner = 'scott' and segment_name='TT';

  NUM_ROWS     BLOCKS      BYTES

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

         1          8      65536

Now we did only 4 block reads.


Along with "shrink" there're other methods:
1. CTAS
2. alter table ... move
3. exp, truncate, imp
4. dbms_redefinition



Tuesday, August 30, 2011

Reinstate after failover due to lost of current redo log

I'd say that the most catastrofic situation is the lost of current redo log file group.
If we don't use Data Guard, then all thing we can do is incomplete recover, of cause if we have made backup.
However if we use Data Guard with Real-Time Log Apply - it's OK. All we need to do is Failover to standby database.
After we have database repaired, we may wish to return it to Data Guard as standby.
In this post I'll try to show lost of current redo log, failover, and getting back failed database to Data Guard
as new standby database and then as primary. So at the end we get back our databasesc as it was no corrupted redo.

As in my previouse posts we're on:
AIX 5.3
Oracle 10.2.0.5 EE
primary host - prod2
standby host - ilstal
primary database - T
standby database - TSTB
on both database I use Flash Recovery Area, Flashback, Data Guard with Real-Time Log-Apply

1. For the first I want to get current redo log file damaged. Let's make it!
prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Aug 30 16:14:18 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select group#, status from v$log;

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT

SQL> !cat /dev/null > /oracle/oradata/T/redo03.log

SQL> insert into scott.t values('record maden after current redo have damaged');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from scott.t;

A
--------------------------------------------------------------------------------
record maden after current redo have damaged

SQL> alter system archive log current;
alter system archive log current
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel

-- at this point database is aborted
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Let's look in the alert...

prod2 $ tail /oracle/admin/T/bdump/alert_T.log
Errors in file /oracle/admin/T/bdump/t_lgwr_762024.trc:
ORA-00316: Message 316 not found; No message file for product=RDBMS, facility=ORA; arguments: [3] [1] [0]
ORA-00312: Message 312 not found; No message file for product=RDBMS, facility=ORA; arguments: [3] [1] [/oracle/oradata/T/redo03.log]
Tue Aug 30 16:15:08 EEST 2011
Errors in file /oracle/admin/T/bdump/t_lgwr_762024.trc:
ORA-00316: Message 316 not found; No message file for product=RDBMS, facility=ORA; arguments: [3] [1] [0]
ORA-00312: Message 312 not found; No message file for product=RDBMS, facility=ORA; arguments: [3] [1] [/oracle/oradata/T/redo03.log]
Tue Aug 30 16:15:08 EEST 2011
LGWR: terminating instance due to error 316
Instance terminated by LGWR, pid = 762024
Great!We screwed up current redo! :)

2. Now we have failover to standby database. Go to standby host (ilstal):

ilstal $ dgmgrl sys/password@TSTB
DGMGRL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> failover to 'TSTB';
Performing failover NOW, please wait...
Failover succeeded, new primary is "TSTB"
DGMGRL>

3. What now? Now we need to know SCN to what we have to flashback our failed database.
It might be SCN just before damaged redo log.  Let's check it. Go on prod2:

prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Aug 30 16:20:41 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area  612368384 bytes
Fixed Size                  2098312 bytes
Variable Size             171969400 bytes
Database Buffers          432013312 bytes
Redo Buffers                6287360 bytes
Database mounted.
SQL> select group#, status, FIRST_CHANGE# from v$log;

    GROUP# STATUS           FIRST_CHANGE#
---------- ---------------- -------------
         1 UNUSED                       0
         3 CURRENT                 950891
         2 INACTIVE                950812

-- SCN we need is 950891 - 2 =  950889
SQL> flashback database to scn 950889;

Flashback complete.

-- clear failed redo group

SQL> alter database clear logfile group 3;

Database altered.

4. Let's now go to standby host and get our flailed database back to Data Guard as standby database

ilstal $ dgmgrl sys/password@TSTB

DGMGRL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> show configuration;

Configuration
  Name:                DG_T
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    T    - Physical standby database (disabled)
    TSTB - Primary database

Current status for "DG_T":
SUCCESS

DGMGRL> show database 'T';

Database
  Name:            T
  Role:            PHYSICAL STANDBY
  Enabled:         NO
  Intended State:  ONLINE
  Instance(s):
    T

Current status for "T":
Error: ORA-16661: the standby database needs to be reinstated

-- It means we need to reinstate our failed (and now flashed back) primary database, other words we can return it to Data Guard as new standby database.

5. So let's reinstate.

DGMGRL> reinstate database 'T';
Reinstating database "T", please wait...
Reinstatement of database "T" succeeded
DGMGRL>
DGMGRL> show configuration;

Configuration
  Name:                DG_T
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    T    - Physical standby database
    TSTB - Primary database

Current status for "DG_T":
SUCCESS
DGMGRL> enable database 'T';
Enabled.

6. Now we can make thing as it was no failed redo log

DGMGRL> switchover to 'T';
Performing switchover NOW, please wait...
Operation requires shutdown of instance "TSTB" on database "TSTB"
Shutting down instance "TSTB"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "T" on database "T"
Shutting down instance "T"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "TSTB" on database "TSTB"
Starting instance "TSTB"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "T" on database "T"
Starting instance "T"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "T"
DGMGRL> show configuration;

Configuration
  Name:                DG_T
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    T    - Primary database
    TSTB - Physical standby database

Current status for "DG_T":
SUCCESS

DGMGRL> show database 'T';

Database
  Name:            T
  Role:            PRIMARY
  Enabled:         YES
  Intended State:  ONLINE
  Instance(s):
    T

Current status for "T":
SUCCESS

DGMGRL> show database 'TSTB';

Database
  Name:            TSTB
  Role:            PHYSICAL STANDBY
  Enabled:         YES
  Intended State:  ONLINE
  Instance(s):
    TSTB

Current status for "TSTB":
SUCCESS

DGMGRL>

7. Check if we have no lost data.
prod2 $ echo $ORACLE_SID
T
prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 17 08:01:12 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from scott.t;

A
--------------------------------------------------------------------------------
record maden after current redo have damaged

That's all!


Friday, August 19, 2011

Oracle net switchover

Oracle net switchover

The core thing of making users automaticaly switch to new primary database after switchover
operation is dbms_service package. With it we can create new service, delete it, start and stop it.
The second thing is db_role_change trigger, which fire after role transition occured. And the last
thing is configuration of clients tnsnames.

1. Let's create service on the primary database to wich applications are connected.
In our example I give it name 'T4U'.
prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Пт Авг 19 15:54:18 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> exec DBMS_SERVICE.CREATE_SERVICE('T4U','T4U');

PL/SQL procedure successfully completed.

2. Now we have to create after db_role_change trigger

SQL> create or replace trigger role_changed_service after db_role_change on database
  2  declare
  3    dbrole varchar2(16);
  4  begin
  5    select database_role into dbrole from v$database;
  6    if dbrole = 'PRIMARY' then dbms_service.start_service('T4U');
  7    else dbms_service.stop_service('T4U');
  8    end if;
  9  end;
 10  /

Trigger created.

SQL> exit

3. Configure oracle net on the client's side
tnsnames.ora:
T =
  (DESCRIPTION =
    (FAILOVER = ON)
    (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST = prod2.mmk.local)(PORT = 1521))
       (ADDRESS = (PROTOCOL = TCP)(HOST = ilstal.mmk.local)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = T4U.MMK.LOCAL)
    )
    (FAILOVER_MODE =
      (TYPE = SELECT)
      (METHOD = BASIC)
      (RETRIES = 100)
      (DELAY = 1)
    )
  )


4. Now let's switchover
prod2 $ dgmgrl sys/password@T
DGMGRL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> switchover to 'TSTB';
Performing switchover NOW, please wait...
Operation requires shutdown of instance "T" on database "T"
Shutting down instance "T"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "TSTB" on database "TSTB"
Shutting down instance "TSTB"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "T" on database "T"
Starting instance "T"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "TSTB" on database "TSTB"
Starting instance "TSTB"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "TSTB"
DGMGRL> show configuration;

Configuration
  Name:                DG_T
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    T    - Physical standby database
    TSTB - Primary database

Current status for "DG_T":
SUCCESS

5. Check if standby host aware of 'T4U' service
prod2 $ lsnrctl services | grep T4U
Service "T4U.MMK.LOCAL" has 1 instance(s).
prod2 $

6. Well it's the time to try connect from client's side
C:\Users\bas>sqlplus system/pasword@T

SQL*Plus: Release 10.2.0.5.0 - Production on Fri Aug 19 16:10:45 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


GLOBAL_NAME
--------------------------------------------------------------------------------
system@T

system@T>

That's all.

Wednesday, August 17, 2011

Standby database in read/write mode on Oracle 10.2


Developers always desire the most actual with production data in their developer's database.
Let me show how it could be achieved with Oracle Data Guard.

As in my previous post:
primary host - prod2
standby host - ilstal
primary database - T
standby database - TSTB
The both nods running Oracle 10.2.0.5 on AIX 5.3
Flashback is turned on on both databases, primary and standby.



1. I created for testing purpose table scott.t

prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 17 10:12:09 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> desc scott.t;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 A                                                  VARCHAR2(100)

SQL> select * from scott.t;

no rows selected

SQL> insert into scott.t values('record inserted into primary database');

1 row created.

SQL> commit;

Commit complete.

2. Now we have to disable standby database (TSTB) from Data Guard
prod2 $ dgmgrl sys/password@T
DGMGRL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> show configuration;

Configuration
  Name:                DG_T
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    T    - Primary database
    TSTB - Physical standby database

Current status for "DG_T":
SUCCESS

DGMGRL> disable database 'TSTB';
Disabled.
DGMGRL> exit

3. Important step. We want to make our standby database as primary opened for read/write operations during working day.
But at the same time we want to be able to put this database back into standby role. The core thing is Flashback Restore Point.
ilstal $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 17 09:41:51 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  612368384 bytes
Fixed Size                  2098312 bytes
Variable Size             167775096 bytes
Database Buffers          436207616 bytes
Redo Buffers                6287360 bytes
Database mounted.
SQL>
-- here we create guarantee restore point and give it name "stdb_became_rwdb"
SQL> create restore point stdb_became_rwdb guarantee flashback database;

Restore point created.

SQL>

SQL> ALTER DATABASE ACTIVATE STANDBY DATABASE;

Database altered.

-- open for read/write
SQL> alter database open;     

Database altered.

SQL>

-- test our developer's database, make some DML-s
SQL> select * from scott.t;  

A
--------------------------------------------------------------------------------
record inserted into primary database

SQL> update scott.t set a = 'record updated in the standby database';

1 row updated.

SQL> commit;

Commit complete.

SQL> insert into scott.t values('record inserted into standby database');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from scott.t;

A
--------------------------------------------------------------------------------
record inserted into standby database
record updated in the standby database


Here let me show that our production primary database (T) works fine
prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 17 09:51:43 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> insert into scott.t values('another record inserted into primary database');

1 row created.

SQL> select * from scott.t;

A
--------------------------------------------------------------------------------
another record inserted into primary database
record inserted into primary database


4. Now assume that working day ending... and we need to put our developer's database (TSTB) back to standby role for main production database (T)
ilstal $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 17 09:49:57 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

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

Total System Global Area  612368384 bytes
Fixed Size                  2098312 bytes
Variable Size             167775096 bytes
Database Buffers          436207616 bytes
Redo Buffers                6287360 bytes
Database mounted.

-- remember restore point we have created?
-- Here we back database into time before it has become developer's database
SQL> flashback database to restore point stdb_became_rwdb;

Flashback complete.

SQL> alter database convert to physical standby;

Database altered.

SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  612368384 bytes
Fixed Size                  2098312 bytes
Variable Size             167775096 bytes
Database Buffers          436207616 bytes
Redo Buffers                6287360 bytes
Database mounted.
SQL>

prod2 $ dgmgrl sys/password@T
DGMGRL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> enable database 'TSTB';
Enabled.
DGMGRL> show database 'TSTB';

Database
  Name:            TSTB
  Role:            PHYSICAL STANDBY
  Enabled:         YES
  Intended State:  ONLINE
  Instance(s):
    TSTB

Current status for "TSTB":
SUCCESS

DGMGRL>

Let's check that primary database have only its data.
prod2 $ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 17 10:01:16 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from scott.t;

A
--------------------------------------------------------------------------------
another record inserted into primary database
record inserted into primary database

SQL>

Thursday, August 4, 2011

Oracle Data Guard step-by-step

Ok.
Here I'm at last!
And 1st my post applies to Oracle Data Guard. I intend to show how to create Data Guard Configuration with Oracle Recovery Manager (RMAN), slightly passing through Database Flash Recovery Area (FRA), Oracle Flashback feature, Recovery Catalog.
The main goal of this post - give step-by-step instruction for building up Data Guard. Just to start it and give it to work.
Why am I using recovery manager (RMAN) in this example? Because without it we'd have to shutdown primary database to create cold backup and up standby database from this cold backup.
All steps bellow are screen-shots of terminal (Putty). If there's no place to fit all steps in one screen-shot I splitted it in several ones.
At the beginning I have to describe environment:
- primary host - IBM570p5, AIX 5.3
- primary host name - prod2.mmk.local
- primary database SID - T
- standby host - IBM520p6, AIX 5.3
- standby host name - ilstal.mmk.local
- standby database SID - TSTB
- database version on both hosts - Oracle 10.2.0.5.3
- recovery catalog SID - CAT
- domain - MMK.LOCAL 
So let's start :)

Step 0 :) SQL*Net
The first of all we need to configure sql*net for our purpose. I'd say that it's the most annoying point of Data Guard Configuration steps.
We planning to use Data Guard Manager (dgmgrl). It's easy just to give command switchover and wait while Data Guard Manager complete role transition between primary and standby database. To give Data Guard Manager ability to shutdown and startup database in new role we need to register instance in listener staticaly (by put entries in SID_LIST clause in listener.ora). Moreover, we need to give GLOBAL_DBNAME in listener.ora following the format db_unique_name_DGMGRL.db_domain. It's important! I see many times when Data Guard Manager couldn't complete operation because of errors in listener.ora.
tnsnames.ora (primary host)

listener.ora (primary host)

tnsnames.ora (standby host)

listener.ora (standby host)


Step 1
I suggest to configure Flash Recovery Area (FRA), put database in archivelog mode and turn on Flashback feature. If you have it configured already, you can pass this step.

Step 2
At this step we configure Recovery Manager (RMAN). But we are sat up Flash Recovery Area at the Step 1, so RMAN uses db_recovery_file_dest as backup destination. And all we have to configure is snapshot control file. It's not necessary for our main goal (creating Data Guard), but I think it useful to put snapshot of controlfile to Flash Recovery Area along with other RMAN backupsets.
We're using recovery catalog, so we need to connect not only to primary database but to catalog database also, and the 1st thing we need to do after connect - is register our database in recovery catalog.

Step 3
Now let's make backup.

Step 4
Now we have to create backup of control file for standby (standby control file)

Step 5
At the Step 6 we'll need to transfer backup, we've created at the Step 3, 4 to standby host. For convenience let's tar our backup.

Step 6
Now let's create on standby host:
- directory structure for standby database
- copy created tar archive (file t.tar) of our primary database backup to standby host
- copy spfileT.ora and orapwT files to standby host

Step 7
Here on standby host we:
- untar t.tar at Flash Recovery Area destination
- rename spfileT.ora to spfileTSTB.ora
- rename orapwT to orapwTSTB

Step 8
 Now create pfile, just for speed up editing standby database parameter.

Step 9
The 1st screen at this step shows pfile of primary database. The second screen shows edited pfile (initTSTB.ora) ready for use by standby database. Changed and added parameters are highlighted with yellow color.
initT.ora


initTSTB.ora
Step 10
Now we create spfile from pfile and sart standby instance.


Step 11
Go to primary host (prod2) and connect RMAN to primary database (target), recovery catalog and auxiliary database (standby database).


Step 12
Now we duplicate primary database to standby host as standby database. (I have to split screens into 3 to show this step)


Step 13
Now we have mounted standby database, but to get ability to turn on real time log apply we have to add standby log file. It's recommended to add more standby log file than online redo log. Oracle recommend use formula (number of logfile groups + 1) * number of instances. In our case we have (3 online redo log + 1) * 1 instance = 4 standby log files. So let's add 4 standby log files. It's a good idea to add standby log files on the primary and standby database at once, so we don't need to add it while role transition back to primary database.


Step 14
Now it's time to turn on data guard broker.


Step 15
Creating data guard configuration

Step 16
Now the time to enable configuration! It's the most shivering step (at least for me :) After a while... let's check...