Monday, December 26, 2016

ASM diskgroup usage

To monitor ASM Diskgroup Usage

SET LINESIZE  145
SET PAGESIZE  9999
SET VERIFY    off
COLUMN group_name             FORMAT a20           HEAD 'Disk Group|Name'
COLUMN sector_size            FORMAT 99,999        HEAD 'Sector|Size'
COLUMN block_size             FORMAT 99,999        HEAD 'Block|Size'
COLUMN allocation_unit_size   FORMAT 999,999,999   HEAD 'Allocation|Unit Size'
COLUMN state                  FORMAT a11           HEAD 'State'
COLUMN type                   FORMAT a6            HEAD 'Type'
COLUMN total_mb               FORMAT 999,999,999   HEAD 'Total Size (MB)'
COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'
COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'



break on report on disk_group_name skip 1
compute sum label "Grand Total: " of total_mb used_mb on report


SELECT
    name                                     group_name
  , sector_size                              sector_size
  , block_size                               block_size
  , allocation_unit_size                     allocation_unit_size
  , state                                    state
  , type                                     type
  , total_mb                                 total_mb
  , (total_mb - free_mb)                     used_mb
  , ROUND((1- (free_mb / total_mb))*100, 2)  pct_used
FROM
    v$asm_diskgroup
ORDER BY
    name
/

Credits: Gavin Soorma



Monitoring using OEM

select collection_timestamp ,key_value DISK_GROUP,round(value/1024/1024,2) "Free TB",round((round(value/1024/1024,2)/7.57*100),2) "Used Space"
from
(select distinct target_name,target_type,target_guid from mgmt_targets where target_type='osm_cluster' and target_name='+ASM_xxxipcva-clus')
join (
 select distinct
  target_type,metric_name,metric_label,metric_column,column_label,short_name,metric_guid
 from mgmt_metrics
) using(target_type)
join mgmt_metrics_raw using(target_guid,metric_guid)
where key_value = 'RECO_DG' and collection_timestamp >= sysdate-0.5/24 and metric_label like '%Usage' and column_label like '%Usable Free%' --and ROWNUM <= 5
order by collection_timestamp desc ;

Wednesday, December 21, 2016

Disable logging on Oracle objects and database

ALTER TABLE tablename MODIFY PARTITION 2016dec NOLOGGING;

Alter table table_name nologging;

select table_name, logging  from dba_tables where table_name like 'test%';

select partition_name,logging from DBA_TAB_PARTITIONS where table_name='tablename';


ALTER TABLE tablename MODIFY LOB (USER_DATA) (NOCACHE NOLOGGING);


To enable force logging on db

ALTER DATABASE force logging;

ALTER TABLESPACE users FORCE LOGGING;

To disable:

ALTER DATABASE no force logging;

ALTER TABLESPACE users NO FORCE LOGGING;

Monday, December 19, 2016

Configuring DBFS on Exadata

Requirements:

Fuse, Fuse libs, Kernel Devel package, Repository database with big file tablespace

Install Fuse, Fuse libs and Kernel Devel package

Run all the steps below until directory creation on both the database nodes.

# cd /etc/yum.repos.d

Verify if you have public repository is present. If not wget it. Or else when ever you try to run install command it says nothing to do

# /usr/openv/pdde/pdopensource/bin/wget http://public-yum.oracle.com/public-yum-ol6.repo

After the above is added run the below to install fuse and kernel-devel

# yum install fuse fuse-libs kernel-devel

Once installed you will get

Setting up Install Process
Package fuse-2.9.4-1.0.1.el6.x86_64 already installed and latest version
Package fuse-libs-2.9.4-1.0.1.el6.x86_64 already installed and latest version
Package kernel-devel-2.6.32-642.11.1.el6.x86_64 already installed and latest version
Nothing to do


Optional - Dos2Unix

# sudo yum install dos2unix

Create the mount directory

# mkdir /dbfs_mnt
# chown oracle:dba /dbfs_mnt

*****************************************************************

Create Repository Database testdbfs

Create tablespace and dbfs_user

CREATE BIGFILE TABLESPACE DBFS_DATA DATAFILE '+DATA_DG' SIZE 1T AUTOEXTEND OFF NOLOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

CREATE USER DBFS_USER IDENTIFIED BY "Password" DEFAULT TABLESPACE DBFS_DATA TEMPORARY TABLESPACE TEMP;
 
grant create session, resource, create view, dbfs_role to dbfs;

$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus dbfs_user/dbfs_user

-- Here dbfs_Data is tablespace name and oracle is the folder name that will be created inside dbfs_mnt directory

@$ORACLE_HOME/rdbms/admin/dbfs_create_filesystem dbfs_data oracle


*****************************************************************
Run on Both nodes

Configure Shared Libraries
# echo "/usr/local/lib" >> /etc/ld.so.conf.d/usr_local_lib.conf
# cd /usr/local/lib
# ln -s $ORACLE_HOME/lib/libclntsh.so.11.1
# ln -s $ORACLE_HOME/lib/libnnz11.so
# locate libfuse.so
# ln -s /lib64/libfuse.so.2 libfuse.so
# ldconfig
# ldconfig -p | grep fuse
# ln -s $ORACLE_HOME/bin/dbfs_client /sbin/mount.dbfs

# echo user_allow_other > /etc/fuse.conf
# chmod 644 /etc/fuse.conf

*****************************************************************

Download and modify mount-dbfs.zip from oracle website (Configuring DBFS on Oracle Exadata Database Machine (Doc ID 1054431.1)

Copy this zip to tmp folder on one of the server

# unzip mount-dbfs-20160215.zip
Archive:  mount-dbfs-20160215.zip
  inflating: mount-dbfs.conf
  inflating: mount-dbfs.sh
# dos2unix mount-dbfs.conf
dos2unix: converting file mount-dbfs.conf to UNIX format ...
# dos2unix mount-dbfs.sh
dos2unix: converting file mount-dbfs.sh to UNIX format ...

You will have two files

1)mount-dbfs.sh
2)mount-dbfs.conf

We need to modify following values in conf file and leave the others as-is

DBNAME=testdbfs

MOUNT_POINT=/dbfs_mnt

DBFS_USER=dbfs_user

ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1

GRID_HOME=/u01/app/11.2.0.4/grid

DBFS_PASSWD=Password

Once modified we need to copy these files to their respective locations on both nodes

using of dcli command here will copy to both nodes. So you dont need  to repeat the same

Create a group called dbs_group in root home directory and include the 2 nodes
# cat dbs_group
10.111.11.111
10.111.11.222

# dcli -g ~/dbs_group -l root -d /u01/app/11.2.0.4/grid/crs/script/ -f /tmp/mount-dbfs.sh
# dcli -g ~/dbs_group -l root chown oracle:dba /u01/app/11.2.0.4/grid/crs/script/mount-dbfs.sh
# dcli -g ~/dbs_group -l root chmod 750 /u01/app/11.2.0.4/grid/crs/script/mount-dbfs.sh
# dcli -g ~/dbs_group -l root -d /etc/oracle -f /tmp/mount-dbfs.conf
# dcli -g ~/dbs_group -l root chmod 640 /etc/oracle/mount-dbfs.conf

Once copied verify all the locations and check permissions.

Now test the functionality to see if mounts are starting properly
$ cd $GRID_HOME/crs/scripts/
$ ./mount-dbfs.sh start
$ ./mount-dbfs.sh status
$ ./mount-dbfs.sh stop

When you start you can verify if the mount is up by checking df -kh . This should list the new mount
Once verified now its time to add to cluster
*****************************************************************
Create a shell script on one of the nodes and run it
$ vi add-dbfs-resource.sh
##### start script add-dbfs-resource.sh
#!/bin/bash
ACTION_SCRIPT=/u01/app/11.2.0.4/grid/crs/script/mount-dbfs.sh
RESNAME=dbfs_mnt
DBNAME=testdbfs
DBNAMEL=`echo $DBNAME | tr A-Z a-z`
ORACLE_HOME=/u01/app/11.2.0.4/grid
PATH=$ORACLE_HOME/bin:$PATH
export PATH ORACLE_HOME
crsctl add resource $RESNAME \
  -type local_resource \
  -attr "ACTION_SCRIPT=$ACTION_SCRIPT, \
         CHECK_INTERVAL=30,RESTART_ATTEMPTS=10, \
         START_DEPENDENCIES='hard(ora.$DBNAMEL.db)pullup(ora.$DBNAMEL.db)',\
         STOP_DEPENDENCIES='hard(ora.$DBNAMEL.db)',\
         SCRIPT_TIMEOUT=300"
##### end script add-dbfs-resource.sh

Run it as Oracle user

$ add-dbfs-resource.sh

Now verify using to see if the mount shows up in resources

crsctl status res -t

To start the mounts

crsctl start resource dbfs_mnt

To stop the mounts

crsctl stop resource dbfs_mnt -f

*****************************************************************

Note: When stopping make sure no session is open and pointing to the folder. If you are inside the folder and try to unmount you get error saying Busy.

If you try to stop the database when mounts are online you will get error as there is dependencies. To shut down we need to specify force option

After eveything is mounted the filesystem permissions will be changed back to root:root

srvctl start database -d testdbfs -f

You can also unmount using following

fusermount -u /dbfs_mnt

To force

umount -l  /dbfs_mnt
fusermount -uz /dbfs_mnt

*****************************************************************
To drop filesystem

@dbfs_drop_filesystem.sql oracle

*****************************************************************
Testing mounts if working properly

$ # Connection prompts for password and holds session.
$ dbfs_client dbfs_user@testdbfs /dbfs_mnt

$ # Connection retrieves password from file and releases session.
echo Password > pw.f
$ nohup dbfs_client dbfs_user@testdbfs /dbfs_mnt  < pw.f &
*****************************************************************

For debugging

Please refer to
http://www.hhutzler.de/blog/debugging-prolbems-when-mounting-a-dbfs/

$ means oracle user
# means root user




Friday, December 16, 2016

Run SQL statements in background UNIX

To run sql statements in background

Copy all the sql statements to a file name test.sql on the unix server

Then run the following using nohup

nohup sqlplus / as sysdba @test.sql &

or

nohup sqlplus USERNAME/password@DBNAME @test.sql &


view output in nohup.out

Tuesday, November 15, 2016

Converting physical standby database to snapshot standby

Converting physical standby database to snapshot standby

All the following steps to be executed on standby database only..


Set the size for recovery area.

Alter system set db_recovery_file_dest_size=100G;

Set Flash recovery area.

Alter system set db_recovery_file_dest='+RECO_DG'

Stop managed recovery if it is active.
 
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Bring the physical standby database to mount stage.

Startup mount;

Convert physical standby database to snapshot standby database.

ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;

Shutdown Immediate;

Startup;

select open_mode,database_role from v$database;

OPEN_MODE  DATABASE_ROLE
---------- ----------------
READ WRITE SNAPSHOT STANDBY


Converting Snapshot standby database to physical standby


Shutdown Immediate;

Startup mount;

ALTER DATABASE CONVERT TO PHYSICAL STANDBY;

Shutdown immediate;

Startup mount;

select open_mode,database_role from v$database;

OPEN_MODE  DATABASE_ROLE
---------- ----------------
MOUNTED    PHYSICAL STANDBY

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;


Note: During this time archivelogs are getting shipped to standby from primary


Convert Physical standby database to active standby for testing

To convert physical standby database to primary for testing scenarios


Step 1 - In Standby database

Set up a flash recovery area.

If Flash Recovery Area ( FRA ) is not configured in the standby then enable it and make sure to give enough space for to FRA

ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=500G;
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST='+RECO_DG';

Cancel Redo Apply and create a guaranteed restore point.

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
CREATE RESTORE POINT testing GUARANTEE FLASHBACK DATABASE;

To Confirim the details of restore point and its scn and time stamp run

 select NAME,SCN,TIME from v$restore_point;

NAME                                                               SCN                    TIME
--------------------------------------------------     -------------    ------------------------------
TESTING     2254478210    11-JUN-16 01.10.21.000000000 P


Step 2 - In Primary Database

ALTER SYSTEM ARCHIVE LOG CURRENT;

Optional - Defer log archive destinations pointing to the standby that will be activated.

--ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=DEFER;

Step 3 - In Standby database

Activate the physical standby database:

ALTER DATABASE ACTIVATE STANDBY DATABASE;

Once its done you can check the controlfile status will be changed from Standby to Current

select CONTROLFILE_TYPE from v$database;

CONTROL
-------
CURRENT


Then open the database.

ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE;
ALTER DATABASE OPEN;

Revert the active standby database back to Physical standby database


Mount the database.
Flashback the database to restore point.

STARTUP MOUNT;

ORACLE instance started.
Total System Global Area  289406976 bytes
Fixed Size                  1290208 bytes
Variable Size             159383584 bytes
Database Buffers          125829120 bytes
Redo Buffers                2904064 bytes
Database mounted.

FLASHBACK DATABASE TO RESTORE POINT testing ;


You can confirm the same by checking the controlfile status. It will be now backup controlfile

select controlfile_type from v$database;

CONTROL
--------------
BACKUP

Convert to Standby database

ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
STARTUP MOUNT;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
select controlfile_type from v$database;

CONTROL
--------------
STANDBY


In Primary database

Optional(If deferred before) - Re-enable archiving to the physical standby database:

ALTER SYSTEM ARCHIVE LOG CURRENT;
--ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

In Standby database

Drop the restore point

STARTUP FORCE MOUNT;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
DROP RESTORE POINT testing ;


Note: Archivelogs will not be shipped when the db is in read/write mode from primary. So make sure you are not deleting the archivelogs in primary until they are shipped here. If you have space constraints or archive logs are purged by a job, then flash back to restore point and do a incremental backup on primary and recover using it based on SCN.

Also during this time flashback_on parameter of database is set to NO

Wednesday, November 9, 2016

Migrating Single node Instace to two node RAC using Data Guard

Goal is to migrate single instance RAC DB to 2 Node RAC on a new server

This is to perform switch over with minimum downtime

PRIMARY(old server)
db_unique_name=test
db_name=test
instance_name=test1


Standby(new server)
db_unique_name=testdr
db_name=test
instance_name=test1,test2

Scan names, Vip names are different as this is not a server refresh

All the files are managed by oracle

datafile are stored in DATA_DG
Redologs are mirrored in DATA_DG and RECO_DG
Archive logs and backups are stored in RECO_DG


Folder structure for example (Automatically generated by oracle. No particular location specified)

primary
+DATA_DG/test/xxx.dbf      -- Just for reference

STANDBY
+DATA_DG/testdr/xxx.dbf   -- Just for reference



Run below at primary database

alter database force logging;

-- Give the primary name followed by primary unique name
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(test,testDR)' scope=both sid='*';

-- Log_archive_dest1 is set for the current database
alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=test' scope=both sid='*';

-- Log archive_dest_2 is set for standby database. This is where log shipping will be done
alter system set LOG_ARCHIVE_DEST_2='SERVICE=testDR ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=testDR' scope=both sid='*';


alter system set log_archive_max_processes=8 scope=both sid='*';

-- Server will always be the other database
alter system set fal_server=testDR scope=both sid='*';

-- Set to auto because we want all the file management to be exactly same as primary and will be managed by oracle
alter system set standby_file_management=auto scope=both sid='*';

-- Commented the below lines because i am not creating standby redo logs as i am using dataguard just to do a cut over inorder to minimize downtime. We will not be using this as a DR

-- Standby redologs are used in maximum protection and maximum security modes of dataguard. We are using maximum performance so i skipped it

-- If you have requirement to create standby redo logs change file management to Manual. Then create logs and change management to Auto.

-- I am not using db_file_name_convert and log_file_name_convert because i am not creating folders manually. These are being created by oracle when performing duplicate



--alter system set standby_file_management=manual scope=both sid='*';
--alter system set db_file_name_convert='TESTDR','TEST' scope=spfile sid='*';
--alter system set log_file_name_convert='TESTDR','TEST' scope=spfile sid='*';

--mkdir +RECO_DG/TEST/STANDBYLOG

--alter database add standby logfile thread 1 group 4 '+RECO_DG/TEST/STANDBYLOG/standby_group_04.log' size 52M;
--alter database add standby logfile thread 1 group 5 '+RECO_DG/TEST/STANDBYLOG/standby_group_05.log' size 52M;
--alter database add standby logfile thread 1 group 6 '+RECO_DG/TEST/STANDBYLOG/standby_group_06.log' size 52M;

alter system set standby_file_management=auto scope=both sid='*';

create pfile='pfile_for_standby.txt' from spfile;

Copy pfile to the new server

scp $ORACLE_HOME/dbs/pfile_for_standby.txt exadb01:$ORACLE_HOME/dbs/pfile_for_standby.txt

Copy the password file from primary server to standby 2 nodes.

scp $ORACLE_HOME/dbs/orapwtest exadb01:$ORACLE_HOME/dbs/orapwtest1
scp $ORACLE_HOME/dbs/orapwtest exadb02:$ORACLE_HOME/dbs/orapwtest2

*********************************************************************************

Perform Below at STANDBY

Node1
Create a listener using db home. This one is used just for connecting to db as auxiliary during rman duplicate. This is because some times we get service blocked in listener status  if we use standard listener

Just create on one node. This can be stopped or removed after duplication is done.

LISTENER_TEMP=
      (DESCRIPTION=
       (ADDRESS_LIST=
        (ADDRESS= (PROTOCOL=TCP)(HOST=exadb01)(PORT=1525))
      )
     )

SID_LIST_LISTENER_TEMP =
    (SID_LIST=
     (SID_DESC=
     (SID_NAME=test1)
     (ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1)
     )
    )

Once the listener is created start it and perform the below at each standby node


Node 1
mkdir -p /u01/app/oracle/admin/test/adump
mkdir -p /u01/app/oracle/diag/rdbms/testdr/test1
cd /u01/app/oracle/diag/rdbms/testdr/test1
mkdir trace cdump


Node 2
mkdir -p /u01/app/oracle/admin/test/adump
mkdir -p /u01/app/oracle/diag/rdbms/testdr/test2
cd /u01/app/oracle/diag/rdbms/testdr/test2
mkdir trace cdump


Edit pfile node1 at standby and change the following

*.audit_file_dest='/u01/app/oracle/admin/test/adump'

-- Just give diskgroups name here because rman duplicate will create the files automatically in the disk groups. After everything is done you need to modify this to reflect new files.
*.control_files='+DATA_DG','+RECO_DG'


*.db_unique_name='testdr'

-- Server will always be the other database
*.fal_server='test'

--Log_archive_dest1 is set for the current database
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=testdr'

--Log_archive_dest2 is set for the standby database
*.log_archive_dest_2='SERVICE=test ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=test'

*.remote_listener='exadb-scan:1521'

-- I am not using db_file_name_convert and log_file_name_convert because i am not creating folders manually. These are being created by oracle when performing duplicate
--*.log_file_name_convert='test','testdr'
--*.db_file_name_convert='test','testdr'

Modify tns and add testdr entries and test entries.. these entries should be in all tns files both in primary and standby



test =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = proddb-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test)
    )
  )

testDR =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = exadb01.hke.local)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = testdr)
 (SID = test1)
    )
  )

testDR1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = exadb01.hke.local)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = testdr)
      (SID = test1)
    )
  )

testDR2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = exadb02.hke.local)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = testdr)
      (SID = test2)
    )
  )

TEMP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = exadb01.hke.local)(PORT = 1525))
    (CONNECT_DATA =
      (SID = test1)
    )
  )


On standby run the following

Note: Set proper environment settings before you do the below. instance names are case sensitive. Export the db with instance number before starting the db.

Also remove any parameters related to interconnect

sql > startup nomount pfile='/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/pfile_for_standby.txt';


On primary run the following


rman target sys/welcome1@test auxiliary sys/welcome1@TEMP

duplicate target database for standby from active database dorecover;

I am using active duplicate here. Using this we can skip the tedious process of taking backup of primary and copying it to standby and doing duplicate.

Using active duplicate directly copies everything from current running database to the new one.

*****
This might have impact on your network. So please check before performing this.

***** 
I am migrating these db's from exadata x4 to exadata x6. And the network link is faster. So i was able to complete duplication of a 7TB database very quickly.

Once this is done and database is in up state. The spfile will be completely messed up because while performing active clone it creates an spfile from memory.

So for future to keep the parameter file clean use the old pfile txt that we copied the beginning

On standby perform the below


Shutdown immediate;

Now edit the controlfile parameter to point to the newly created controlfiles because the parameterfile that we currently have doesnt contain exact controlfile location.

*.control_files='+DATA_DG/testdr/controlfile/current.411.926159161','+RECO_DG/testdr/controlfile/current.5242.926159161'

add the following parameters as well as copy the instance 1 parameters and rename it to instance 2

cluster_database=TRUE
test1.undo_tablespace='UNDOTBS1'
test2.undo_tablespace='UNDOTBS2'
test1.instance_number=1
test2.instance_number=2
test1.thread=1
test2.thread=2


On standby node 1



startup nomount pfile='/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/pfile_for_standby.txt';


create spfile='+data_dg/testdr/parameterfile/spfiletest.ora' from pfile='/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/pfile_for_standby.txt';

On standby node 1


vi inittest1.ora
spfile='+data_dg/testdr/parameterfile/spfiletest.ora'


On standby node 2


vi inittest2.ora
spfile='+data_dg/testdr/parameterfile/spfiletest.ora'


*********************************************************************************
Since we dont have 2nd node for this database in primary. I will need to create redologs for the 2nd thread

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=MANUAL;


alter database add logfile thread 2 group 16 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 17 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 18 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 19 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 20 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 21 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 22 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 23 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 24 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 25 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 26 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 27 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 28 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 29 ('+DATA_DG','+RECO_DG') size 4G reuse;
alter database add logfile thread 2 group 30 ('+DATA_DG','+RECO_DG') size 4G reuse;


ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;


*********************************************************************************

Adding the 2 instances to cluster



srvctl add database -d test -o /u01/app/oracle/product/11.2.0.4/dbhome_1 -p +data_dg/testdr/parameterfile/spfiletest.ora -r physical_standby -a DATA_DG,RECO_DG
srvctl add instance -d test -i test1 -n exadb01
srvctl add instance -d test -i test2 -n exadb02
srvctl start database -d test

srvctl status database -d test

srvctl config database -d test


To change service name

alter system set service_names=test scope=both sid='*';

alter system register;

Now shut down everything

srvctl stop database -d test

*********************************************************************************

On standby Node 1


Now just start 1st instance manually without srvctl to mount state.

sql > Starup Mount


ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

To stop MRP

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

*********************************************************************************

Test dataguard functionality

Standby

--select process,status,sequence#,thread# from v$managed_standby;

select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;

PRIMARY

select thread#,max(sequence#) from v$archived_log group by thread#;

or

select max(sequence#) from v$archived_log where  resetlogs_change#=(SELECT resetlogs_change# FROM v$database)

or

SELECT sequence# || '|' ||
thread# || '|' ||
TO_CHAR(completion_time, 'DD-MON-RRRR HH24:MI:SS')
FROM v$archived_log
WHERE sequence#= (SELECT MAX(sequence#) FROM v$archived_log where resetlogs_change#=(SELECT resetlogs_change# FROM v$database))
AND thread#=1
AND resetlogs_change#=(SELECT resetlogs_change# FROM v$database)
AND dest_id=1
UNION ALL
SELECT sequence# || '|' ||
thread# || '|' ||
TO_CHAR(completion_time, 'DD-MON-RRRR HH24:MI:SS')
FROM v$archived_log
WHERE sequence#= (SELECT MAX(sequence#) FROM v$archived_log where resetlogs_change#=(SELECT resetlogs_change# FROM v$database))
AND resetlogs_change#=(SELECT resetlogs_change# FROM v$database)
AND thread#=2
AND dest_id=1;


*********************************************************************************


Note: If you no longer want to use standby db or you just did dataguard as part of migration make sure you disable force logging on current primary db

ALTER DATABASE FORCE LOGGING;
*********************************************************************************
Best practice
 alter system set log_archive_dest_2 = 'service=STDBY ARCH OPTIONAL MAX_CONNECTIONS=5 VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) db_unique_name=STDBY' scope = both ;
 But I think you should use LGWR
 alter system set log_archive_dest_2 = 'service=STDBY LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) db_unique_name=STDBY' scope = both ;

For LGWR use standby redo logs

create 5 groups of SRL
alter database add standby logfile thread 1 group 10 (' full path file name ') size 104857600 ;
alter database add standby logfile thread 1 group 11 (' full path file name ') size 104857600 ;
alter database add standby logfile thread 1 group 12 (' full path file name ') size 104857600 ;
alter database add standby logfile thread 1 group 13 (' full path file name ') size 104857600 ;
alter database add standby logfile thread 1 group 14 (' full path file name ') size 104857600 ;

Then change the redo transport
alter system set log_archive_dest_2 = 'service=STDBY ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) db_unique_name=STDBY' scope = both ;

Make sure you have enough db_Cache size on stdby

Featured Post

Apply Patch 22191577 latest GI PSU to RAC and DB homes using Opatch auto or manual steps

Patch 22191577: GRID INFRASTRUCTURE PATCH SET UPDATE 11.2.0.4.160119 (JAN2016) Unzip the patch 22191577 Unzip latest Opatch Version in or...