Você está na página 1de 12

Data Guard Practical Demo

============================

primary side
------------

sql>select name, database_role, controlfile_type from v$database;

name databse_role control


----------------------------------------
PRD primary current

sql>archive log list;


enabled

sql> select name from v$datafile;

sql>select name from v$controlfile;

sql>select member from v$logfile;

sql>shut immediate;

sql>exit
go to prd directory

]$cd /home/prd

prd]$ls
prd]$mkdir dg

prd]$cp *.dbf *.log dg

prd]$cd dg
dg]$ls
everything fine
go to dbs direcory
dbs]$vi initprd.ora
-------------------------------------------------

inactive log_archive_dest=/home/prd/arch
i.e #log_archive_dest=/home/prd/arch
log_archive_dest_1='location=/home/prd/arch'
log_archive_dest_2='service=to_standby'
standby_file_management=auto
:wq
------------------------------------------------------
dbs]$orapwd file=orapwprd password=sys
Take backup of parameter file and the password file
dbs]$cp initprd.ora orapwprd /home/prd/dg/
go to dg directory and check it whether the paramter file and
password file is exist or not
]$cd /home/prd/dg
dg]$ls
initprd.ora orapwprd and .dbf and .log files exist
dg]$cd

]$sqlplus '/as sysdba'

sql>startup mount;

Take backup of controlfile

sql>alter database create standby controlfile


as '/home/prd/dg/stdcont.ctl';

database altered

go to dg directory and checkit


dg]$ls
initprd.ora orapwprd and .dbf ,.log and stdcont.ctl

Transfer all files to primary server to standby database server

dg]$cd
]$ pwd
/home
In standby database /home folder
create prd folder
and transfer all files into /home/prd folder

dg]$scp * 192.168.100.2:/home/prd
-----------------------------------------------------
note:
if any error comes check network
]$vi /home/.ssh/known_hosts
------------------------------------------
here we have to keep target hostname
-------------------------------------------
-------------------------------------------------------
enter password: oracle (os password)

dg]$

in the standby databse

go to dbs directory and check it


why because dbs directory must contain parameter file and the
password file i.e initprd.ora and orapwprd

dbs]$ls
nothing

go to prd directory in the standby database server.


prd]$mv initprd.ora orapwprd $ORACLE_HOME/dbs

goto dbs and check it in the standby database server.


dbs]$initprd.ora
---------------------------------------------------------
db_name=prd

control_files=/home/prd/stdcont.ctl
user_dump_dest=/home/prd/udump
core_dump_dest=/home/prd/cdump
background_dump_dest=/home/prd/bdump
#comment the below lines bcz we will get from primary database server
#log_archive_dest=/home/prd/arch
#log_archive_dest_1='location=/home/prd/arch'
#log_archive_dest_2='service=to_standby'
#standby_file_management=auto
standby_archive_dest=/home/prd/arch

----------------------------------------------------
go to prd directory

prd]$mkdir bdump udump cdump

prd]$cd
]$cd $ORACLE_HOME/network/admin

admin]$netca
listenername is LISTENER
PORT: 1521 all default

admin]$vi listener.ora

-------------------------------------------------------------
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = prd
(ORACLE_HOME = /home/oracle/product/10.2.0/db_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.100.2)(PORT=1521)
)
)

NOTE: HERE the ip address of the standby ip is 192.168.100.2

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

admin]$lsnrctl start

listener started

configrue tnsnames.ora on the primary database server


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

]$cd $ORACLE_HOME/network/admin

admin]$netca

service name: prd

tcp
hostname: 192.168.100.2
port: 1521
no test

Netservice name : to_standby


finish
admin]$vi tnsnames.ora
----------------------------------------------------------------------
TO_STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prd)
)
)
----------------------------------------------------------------------

admin]$tnsping to_standby
working fine

In stand by database

]$sqlplus '/as sysdba'

sql>startup nomount;
sql>alter database mount standby database;

database altered

sql> select name, database_role, controlfile_type from v$database;

Name Database_role control


------------------------------------------------------------
PRD PHYSICAL stand by STANDBY

-------------------------------------------------------------
sql>alter database recover managed standby database;
(Here it will stay like that only)

go to primary side
---------------------
]$sqlplus '/as sysdba'
This is in mount stage
----------------------------------------------------------------------
Note:
How do we know whether it is in mounted stage or not ?
use the following query
sql> select status from v$database;

mounted
------------------------------------------------------------------------
sql>alter database open;

sql>show parameter log_archiv_dest

You will see all the values

for checking purpose generate some archive logs in the primary


database
sql>alter system switch logfile;
sql>/

sql>/

How to check it in standby database;

--------------------------------------
In stand by database
]$cd /home/prd/arch

arch]$ls
archives are generating
----------------------------------------------------------
Note:
go to /home/prd/arch
check it is whether is generating or not
yes generating

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

go to prmary side:
---------------------

sql>select * from all_users;


7 users

create one user

sql>grant connect,resource to amit identified by amit;

sql>conn amit/amit;

create one table and insert some data

sql>conn /as sysdba

sql>show user;
SYS

checking purpose primary side

sql>alter system switch lofile;


system altered
sql>/
sql>/

goto standby databse side

sql>alter database recover managed standby database;


like this only
ctrl + c ( it will come out)

sql>alter database open read only;


database altered

sql>select * from all_users;


7 rows selected

sql>conn amit/amit;
connected

sql>select * from tab;


test

sql>select * from test;


u will see the data
DONE

standbyside
--------------
again how to put in recover mode

sql>conn /as sysdba


sql>shut immediate;
sql>startup nomount;
sql>alter database mount standby database;
database altered

sql>alter database recover managed standby database;

It will stay like that only

we can do dml and ddl or any operations.


go to primary side

sql>select * from all_usrs;

sql>drop user amit cascade;


user dropped

sql>grnat connect,resource to ravi identified by ravi;


sql>conn ravi/ravi;
create a table and insert data

sql>conn /as sysdba

sql>show user;

SYS

sql>alter system switch logfile;


sql>/
sql>/
sql>/

goto standby database side


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

sql>alter database recover managed standby database;


staying like this
ctrl + c ( to stop mrp process)
or
open other treminal
]$sqlplus '/as sysdba'
]$export ORACLE_SID=PRD
]$sqlplus '/as sysdba'

sql>alter database recover managed standby database cancel;


database altered
sql>alter database recover managed standby database;
Then it will come out

sql> alter database open read only;

sql>select * from all_usrs;

user dropped and user created.

done second time

stand by side
----------------
sql>shut immediate;
sql>starup nomount;

sql>alter database mount standby database;


database altered

sql>alter database recover managed standby database;

just waiting like this

----------------------------@@@@@@@@@@____________________

If some thing happened to primary server then how to make


standby database as primary server.

in standby database mode

]$lsnrctl stop

sql>alter database recover managed standby database;


ctrl+ c (for come out)

sql>alter database recover managed standby database finish;


database altered

sql>select name, database_role, controlfile_type from v$database;

Name Database_role control


-----------------------------------------------------------------
prd physical standby standby

sql>alter database commit to switchover to primary;

sql>select name, database_role, controlfile_type from v$database;

Name Database_role control


----------------------------------------------------------------------
prd PRIMARY CURRENT

-------------------done--------------

Checking whether it is working fine or not


sql>shut immediate;

sql>startup;

sql>

Done

Você também pode gostar