O baza de date standby este o copie exactă a unei baze de date operaționale aflata la distanță (sau locală), gata de a fi utilizate pentru backup, replicare, recuperarea după dezastru și raportare, pentru a numi câteva aplicații.
O baza de date standby este mult superioară unei copii de rezervă normală, deoarece este disponibilă imediat în caz de dezastru.
Pentru a restaura o copie de rezervă este nevoie de timp, iar în timpul restaurării sistemul nu este disponibil. Cu o baza de date de standby nu este nimic de restaurat, în caz de dezastru, baza de date standby este întotdeauna disponibila. Este posibil pentru a comuta aplicații pe la baza de date standby într-o chestiune de minute pentru a permite continuitatea afacerii.

Mai jos sunt pașii pentru a realiza o bază de date standby:

Pasul 1: Backup-ul bazei de date care să includă backup-ul fișierelor de date, arhivele de loguri și controlfile-ul pentru standby
Pasul 2: Mutarea backup-ului pe serverul de standby
Pasul 3: Faceți modificările corespunzătoare în fișierele parametrilor bazei de date primare și de standby
Pasul 4: Se restaurează și recuperează baza de date standby
Pasul 5: Punem baza de date standby în modul recuperare

Exemplu creare bază de date de standby:

Abreviere:

orcl – sid-ul bazei de producție
stdby – sid-ul bazei de standby
prod – mașina care rulează baza de producție
standby – mașina care rulează baza de standby

Pregătirea bazei de date primară pentru crearea bazei de date standby

pe standby:

$ mkdir /u01/oracle/oradata/stdby/
$ mkdir /u01/oracle/oradata/stdby/flash


pe producție:
- copiem fișierul de parole si ii schimbam denumirea in orapwstdby
- verificam daca baza este in mod arhivare

$ scp $ORACLE_HOME/dbs/orapworcl standby:$ORACLE_HOME/dbs/

$export ORACLE_SID=stdby

$ sq / as sysdba

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

SQL> SELECT LOG_MODE FROM SYS.V$DATABASE;

LOG_MODE
------------
NOARCHIVELOG

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

Total System Global Area  626327552 bytes
Fixed Size                  2230952 bytes
Variable Size             478152024 bytes
Database Buffers          142606336 bytes
Redo Buffers                3338240 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter system set db_recovery_file_dest_size=3G scope=both;

System altered.

SQL> alter system set DB_RECOVERY_FILE_DEST='/u01/oracle/oradata/orcl/flash' scope=both;

System altered.

SQL> alter database open;

Database altered.

SQL> exit


Facem un backup al bazei de date primară, orcl, care sa includă backup-ul fișierelor de date și arhivele de loguri pentru standby

$ rman target /

RMAN> run
2>  {
3>  allocate channel c1 type disk;
4>  backup database plus archivelog;
5>  }

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=33 device type=DISK

Starting backup at 15-OCT-12
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=77 RECID=1 STAMP=796728679
channel c1: starting piece 1 at 15-OCT-12
channel c1: finished piece 1 at 15-OCT-12
piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/04nnq7b7_1_1 tag=TAG20121015T093119 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-12

Starting backup at 15-OCT-12
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/orcl/users01.dbf
channel c1: starting piece 1 at 15-OCT-12
channel c1: finished piece 1 at 15-OCT-12
piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/05nnq7b9_1_1 tag=TAG20121015T093121 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:46
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 15-OCT-12
channel c1: finished piece 1 at 15-OCT-12
piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/06nnq7cn_1_1 tag=TAG20121015T093121 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-12

Starting backup at 15-OCT-12
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=78 RECID=2 STAMP=796728730
channel c1: starting piece 1 at 15-OCT-12
channel c1: finished piece 1 at 15-OCT-12
piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/07nnq7cr_1_1 tag=TAG20121015T093211 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-12
released channel: c1

Backup spfile

RMAN> backup spfile format '/u01/oracle/product/11.2.0/dbhome/dbs/spfile_%d_%s_%T_dbid%I.rman';

Starting backup at 15-OCT-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 15-OCT-12
channel ORA_DISK_1: finished piece 1 at 15-OCT-12
piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/spfile_ORCL_9_20121015_dbid1322094847.rman tag=TAG20121015T105125 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-12

Backup controlfile

RMAN> backup current controlfile for standby;

Starting backup at 15-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 15-OCT-12
channel ORA_DISK_1: finished piece 1 at 15-OCT-12
piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/spfile_ORCL_10_20121015_dbid1322094847.rman tag=TAG20121015T121947 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-12

Copiem id-ul bazei de date (îl vom folosi pe baza de standby)

$ sq / as sysdba

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

SQL>
SQL> select dbid from v$database;

DBID
----------
1322094847

Copiem toate fișierele de backup pe mașina standby, dupa care, pe standby:

$ export ORACLE_SID=stdby
$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Oct 15 10:29:17 2012

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount;

connected to target database (not started)
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/oracle/product/11.2.0/dbhome/dbs/initstdby.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area     158662656 bytes

Fixed Size                     2226456 bytes
Variable Size                 92276456 bytes
Database Buffers              58720256 bytes
Redo Buffers                   5439488 bytes

RMAN> set dbid=1322094847;

executing command: SET DBID

Restauram spfile-ul din backup-ul bazei de producție:

RMAN>  restore spfile FROM '/u01/oracle/product/11.2.0/dbhome/dbs/spfile_ORCL_10_20121015_dbid1322094847.rman';

Starting restore at 15-OCT-12
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/oracle/product/11.2.0/dbhome/dbs/spfile_ORCL_10_20121015_dbid1322094847.rman
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 15-OCT-12

Generăm pfile din spfile-ul restaurat

$ sq / as sysdba

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

SQL> create pfile from spfile;

File created.

Edităm pfile-ul astfel încât sa corespundă bazei de standby:

$nano /u01/oracle/product/11.2.0/dbhome/dbs/initstdby.ora

stdby.__db_cache_size=117440512
stdby.__java_pool_size=29360128
stdby.__large_pool_size=4194304
stdby.__oracle_base='/u01/oracle'#ORACLE_BASE set from environment
stdby.__pga_aggregate_target=29360128
stdby.__sga_target=285212672
stdby.__shared_io_pool_size=0
stdby.__shared_pool_size=121634816
stdby.__streams_pool_size=4194304
*.compatible='11.2.0.0.0'
*.control_files='/u01/oracle/oradata/stdby/control01.ctl','/u01/oracle/oradata/stdby/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest_size=3221225472
*.db_recovery_file_dest='/u01/oracle/oradata/stdby/flash'
*.diagnostic_dest='/u01/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_2='SERVICE=stdby'
*.memory_target=314572800
*.nls_language='AMERICAN'
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
db_unique_name='stdby'
instance_name='stdby'
db_file_name_convert='/u01/oracle/oradata/orcl/','/u01/oracle/oradata/stdby/','/u01/oracle/oradata/orcl/','/u01/oracle/oradata/stdby/'
log_file_name_convert='/u01/oracle/oradata/orcl/','/u01/oracle/oradata/stdby/'
standby_archive_dest='/u01/oracle/oradata/stdby/flash'

Generam un alt spfile din pfile-ul editat

SQL> create spfile from pfile;

Editam tnsnames.ora astfel încât sa conțină serviciile orcl și stdby

$nano $ORACLE_HOME/network/admin/tnsnames.ora

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = productie)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

stdby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stdby)

Restauram backup-ul bazei de date orcl in noua baza stdby:

RMAN> restore standby controlfile from '/u01/oracle/product/11.2.0/dbhome/dbs/08nnq7el_1_1';

Starting restore at 15-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output file name=/u01/oracle/oradata/stdby/control01.ctl
output file name=/u01/oracle/oradata/stdby/control02.ctl
Finished restore at 15-OCT-12

RMAN>  sql 'alter database mount standby database';

sql statement: alter database mount standby database
released channel: ORA_DISK_1

RMAN>  restore database;

Starting restore at 15-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK

skipping datafile 4; already restored to file /u02/oracle/oradata/stdby/users01.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/oracle/oradata/stdby/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/oracle/oradata/stdby/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/oracle/oradata/stdby/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u01/oracle/product/11.2.0/dbhome/dbs/05nnq7b9_1_1
channel ORA_DISK_1: piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/05nnq7b9_1_1 tag=TAG20121015T093121
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:55
Finished restore at 15-OCT-12

După restaurare încearcăm să identificăm secvența ultimului archivelog, la care i se adaugă 1 înainte de a face recuperarea. În exemplul de mai jos ultimul archivelog are secventa 78 la care am adăugat 1, astfel devine 79 și am recuperat până la secvența 79.

RMAN>  list backup of archivelog all;

List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
3       3.14M      DISK        00:00:01     15-OCT-12
BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20121015T093119
Piece Name: /u01/oracle/product/11.2.0/dbhome/dbs/04nnq7b7_1_1

List of Archived Logs in backup set 3
Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
---- ------- ---------- --------- ---------- ---------
1    77      969001     10-OCT-12 971596     15-OCT-12

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
6       8.50K      DISK        00:00:00     15-OCT-12
BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20121015T093211
Piece Name: /u01/oracle/product/11.2.0/dbhome/dbs/07nnq7cr_1_1

List of Archived Logs in backup set 6
Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
---- ------- ---------- --------- ---------- ---------
1    78      971596     15-OCT-12 971631     15-OCT-12

RMAN> recover database until sequence 79;

Starting recover at 15-OCT-12
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=78
channel ORA_DISK_1: reading from backup piece /u01/oracle/product/11.2.0/dbhome/dbs/07nnq7cr_1_1
channel ORA_DISK_1: piece handle=/u01/oracle/product/11.2.0/dbhome/dbs/07nnq7cr_1_1 tag=TAG20121015T093211
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u02/oracle/oradata/stdby/flash/STDBY/archivelog/2012_10_15/o1_mf_1_78_87qrc9s9_.arc thread=1 sequence=78
channel default: deleting archived log(s)
archived log file name=/u02/oracle/oradata/stdby/flash/STDBY/archivelog/2012_10_15/o1_mf_1_78_87qrc9s9_.arc RECID=1 STAMP=796741913
Oracle Error:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u02/oracle/oradata/stdby/system01.dbf'

media recovery complete, elapsed time: 00:00:01
Finished recover at 15-OCT-12

RMAN>  exit

Recovery Manager complete.
[oracle@OracleDB ~]$ sq / as sysdba

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

SQL> alter database recover managed standby database disconnect from session;

Database altered.

putem verifica ca funcționează dacă ne uităm în alertlog si vedem urmatoarele linii:

Completed: alter database recover managed standby database disconnect from session
Media Recovery Log /u02/oracle/oradata/stdby/flash/1_79_794314111.dbf
Media Recovery Log /u02/oracle/oradata/stdby/flash/1_80_794314111.dbf
Media Recovery Log /u02/oracle/oradata/stdby/flash/1_81_794314111.dbf
Media Recovery Waiting for thread 1 sequence 82 (in transit)

Lasă un răspuns

Completează mai jos detaliile despre tine sau dă clic pe un icon pentru autentificare:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s