18 June 2018

Convert single instance database to a clustered database

Clusterize the database

oh; cd dbs
cp initDBNAME.ora initDBNAME.ora.singleinstance

create pfile='/oracle/DBNAME/121/dbs/initDBNAME.ora' from spfile;

vi initDBNAME.ora
Add:
*.cluster_database = TRUE
*.remote_listener='scanename:xxx'
DBNAME1.instance_number=1
DBNAME2.instance_number=2
DBNAME1.thread=1
DBNAME2.thread=2
DBNAME1.undo_tablespace='UNDO1'
DBNAME2.undo_tablespace='UNDO2'
If you see andy DBNAME.__ parameters, change them to DBNAME1 and DBNAME2. Example:
DBNAME1__db_cache_size=1895825408
DBNAME2__db_cache_size=1895825408
Important: Remove *.undo_tablespace parameter

create undo tablespace PUNDO1 datafile '+ORADATA3' SIZE 2G AUTOEXTEND ON MAXSIZE 5G;
create undo tablespace PUNDO2 datafile '+ORADATA3' SIZE 2G AUTOEXTEND ON MAXSIZE 5G;

Add log files for thread 2

List log files from v$logfile;

#Add as many groups as you have in thread1, with the same size.
Example:
alter database add logfile thread 2 group 31 size 200M;
alter database add logfile thread 2 group 32 size 200M;
alter database add logfile thread 2 group 33 size 200M;
...
alter database enable public thread 2;

oh; cd dbs
cp initDBNAME.ora initDBNAME1.ora
cp initDBNAME.ora initDBNAME2.ora
cp orapwDBNAME orapwDBNAME1
cp orapwDBNAME orapwDBNAME2
vi ../network/admin/tnsnames.ora
Change DBNAME now to be:
DBNAME=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = scanname)(PORT = xxxx))
    (CONNECT_DATA =  (SERVER = DEDICATED)  (SERVICE_NAME = DBNAME)  ) )

Start the new cluster database

shutdown immediate
#Start the both instance individually
export ORACLE_SID=DBNAME2
startup nomount pfile='/oracle/DBNAME/121/dbs/initDBNAME.ora'
create spfile='+ORADATA3/DBNAME/spfileDBNAME.ora' from pfile='/oracle/DBNAME/121/dbs/initDBNAME.ora';
shutdown immediate
startup pfile='/oracle/DBNAME/121/dbs/initDBNAME2.ora'

ssh to other node
export ORACLE_SID=DBNAME1
startup pfile='/oracle/DBNAME/121/dbs/initDBNAME1.ora'
!! shutdown immediate on BOTH nodes !!

srvctl add database -d DBNAME -o /oracle/DBNAME/121
srvctl add instance -d DBNAME -i DBNAME1 -n node1
srvctl add instance -d DBNAME -i DBNAME2 -n node2
srvctl modify database -d DBNAME -p '+ORADATA3/DBNAME/spfileDBNAME.ora'
srvctl config database -d DBNAME

srvctl start instance -i DBNAME2 -d DBNAME
srvctl start instance -i DBNAME1 -d DBNAME
srvctl stop database -d DBNAME
srvctl start database -d DBNAME

Voila!

Duplicate database to a diferent server

Prepare OLD database

cd $ORACLE_HOME/dbs; cp orapwDBNAME orapwDBNAME.beforemigration
orapwd file=/oracle/DBNAME/12102/dbs/orapwDBNAME sysdg=yes sysbackup=yes force=y
Stop all cronjobs on OLD server

Prepare  NEW database

Prepare all directories
oh; cd dbs
orapwd file=/oracle/DBNAME/121/dbs/orapwDBNAME sysdg=yes sysbackup=yes force=y

Update oratab

vi /etc/oratab
Add line:
DBNAME:/oracle/DBNAME/121:N
. oraenv

Create a separate listener for duplicate process

We are doing this so we don't have to touch SCAN or VIP listeners and disturb existing cluster
oh; cd network/admin
lsnrctl stop listener_duplicate

vi listener.ora
Add this:
LISTENER_DUPLICATE=
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = xxxx)) )

ADR_BASE_LISTENER_DUPLICATE = /oracle/DBNAME/saptrace
CONNECT_TIMEOUT_LISTENER_DUPLICATE = 10
TRACE_LEVEL_LISTENER_DUPLICATE = OFF

SID_LIST_LISTENER_DUPLICATE =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = DBNAME)
      (ORACLE_HOME = /oracle/DBNAME/121)
      (SID_NAME = DBNAME)  ) )

lsnrctl start listener_duplicate

Set up init.ora

Ensure these parameters are changed:
*.compatible=12.1.0.2.0
*.control_files
*.db_create_file_dest
*.db_recovery_file_dest
*.db_recovery_file_dest_size
*.db_create_online_log_dest_1
*.db_create_online_log_dest_2
*.dg_broker_start=FALSE
*.db_unique_name=DBNAME
*.log_archive_dest_1
*.log_archive_dest_state_1='ENABLE'

Set up TNS connectivity between servers

Add to tnsnames.ora on NEW server:

DBNAME_OLD=
  (DESCRIPTION =
    (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = oldhost)(PORT = xxxx) ))
    (CONNECT_DATA = (SID = DBNAME) (GLOBAL_NAME = DBNAME.WORLD)))

DBNAME=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST=servername)(PORT = xxxx))
    (CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = DBNAME)(UR = A) )
  )

LISTENER_DUPLICATE =(DESCRIPTION =(PROTOCOL = TCP)(HOST = servername)(PORT = xxxx))

Check all with:
sqlplus sys@DBNAME_OLD as sysdba
sqlplus sys@DBNAME as sysdba
tnsping listener_duplicate

Startup nomount NEW database

startup nomount pfile='/oracle/DBNAME/121/dbs/initDBNAME.ora';
create spfile from pfile='/oracle/DBNAME/121/dbs/initDBNAME.ora';

Startup mount OLD database

We are doing this so we don't have to do recovery on the NEW db
STARTUP MOUNT;

Duplicate

#No need to allocate channels as we are going directly over the network
rman AUXILIARY sys@DBNAME target sys@DBNAME_OLD
RUN
{
DUPLICATE TARGET DATABASE TO DBNAME FROM ACTIVE DATABASE;
}

Check the health of the database before commencing.

Standby Catchup with incremental SCN backup

If standby is considerably lagging behind production, “roll it forward” using the incremental backup.

DR

DGMGRL> edit database 'DBNAMEDR_A' set state='APPLY-OFF';

Find both SCNs from 2 queries below and take the lower one. Most of the blog posts refer just to the current_scn, but file header SCN could be lower than current_scn, so you have to check both. The reason they are different is that datafile header is checkpoint-ed from time to time, while current_scn is updated continuously. Actually, current_scn is mostly higher than fhscn.

 In this example, you would take 5716576040, not 5716599640.
select current_scn from v$database;
-----------
 5716599640
select min(fhscn) from x$kcvfh;
-----------
 5716576040

Primary

rman target /
backup incremental from scn 5716576040 database format '/backup/DBNAME_inc%U' tag 'incremental backup';

DR

rman target /
catalog start with '/backup/DBNAME_inc';
recover database noredo;

DGMGRL> edit database 'DBNAMEDR_A' set state='APPLY-ON';

This is a simple scenario, which assumes no new datafile have been created on the primary since the given SCN.



This page is powered by Blogger. Isn't yours?