Showing posts with label Dataguard. Show all posts
Showing posts with label Dataguard. Show all posts

Friday 10 October 2014

After Test-Failover, make NEW Primary Standby again

After Test-Failover, make NEW Primary Standby again

Maybe we want to test Failover, although the Primary is working fine. After the failover succeeded, we have an OLD Primary then and a NEW Primary. There is a well documented way to convert the OLD Primary into a Standby. This procedure is called Reinstate. This posting shows how to make the NEW Primary a Standby again. The OLD Primary will keep on running as Primary – with all productive users connected there still. A special case why we may want to do that is because we tested Failover to a Snapshot Standby that has no network connection to the Primary.
The initial configuration:
DGMGRL> show configuration

Configuration - myconf

  Protection Mode: MaxPerformance
  Databases:
    prima - Primary database
    physt - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
The version is still 11.2.0.1 like in the previous posting. I will now failover to physt while prima keeps running. Attention: If there is a productive service started on the NEW Primary, make sure to stop it. Else new productive connections will access the NEW Primary! We will deliberately cause a Split Brain situation here with two Primary Databases. This may cause problems in a productive environment and is not recommended.
DGMGRL> failover to physt;
Performing failover NOW, please wait...
Error: ORA-16600: not connected to target standby database for failover

Failed.
Unable to failover
DGMGRL> exit
[oracle@uhesse ~]$ dgmgrl sys/oracle@physt
DGMGRL for Linux: Version 11.2.0.1.0 - 64bit Production

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

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> failover to physt;
Performing failover NOW, please wait...
Failover succeeded, new primary is "physt"
The error above shows that we cannot failover, connected to the (still working) Primary but must connect to the Standby first. Now there are two Primary Databases:
[oracle@uhesse ~]$ sqlplus sys/oracle@physt as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 16 10:25:51 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

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

SQL> select database_role from v$database;

DATABASE_ROLE
----------------
PRIMARY

SQL> connect sys/oracle@prima as sysdba
Connected.
SQL> select database_role from v$database;

DATABASE_ROLE
----------------
PRIMARY
I want to make the NEW Primary a Standby again. Similar to a Reinstate, that needs Flashback Logs. My two Databases generate Flashback Logs, so that requirement is met.
SQL> connect sys/oracle@physt as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  313159680 bytes
Fixed Size            2212936 bytes
Variable Size          264244152 bytes
Database Buffers       41943040 bytes
Redo Buffers            4759552 bytes
Database mounted.
SQL> flashback database to before resetlogs;

Flashback complete.

SQL> alter database convert to physical standby;

Database altered.
This modified the controlfile and puts the Instance in NOMOUNT. We need to restart into MOUNT:
SQL> shutdown immediate
ORA-01507: database not mounted

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

Total System Global Area  313159680 bytes
Fixed Size            2212936 bytes
Variable Size          264244152 bytes
Database Buffers       41943040 bytes
Redo Buffers            4759552 bytes
Database mounted.
SQL> recover managed standby database using current logfile disconnect;
Media recovery complete.
SQL> select status,sequence# from v$managed_standby where process='MRP0';

STATUS          SEQUENCE#
------------ ----------
WAIT_FOR_LOG         12
We want to see here APPLYING LOG – the redo is not yet transmitted from the OLD Primary.
SQL> connect sys/oracle@prima as sysdba
Connected.
SQL> select sequence# from v$log where status='CURRENT';

 SEQUENCE#
----------
    13

SQL> alter system set log_archive_dest_2='service=physt db_unique_name=physt';

System altered.

SQL> alter system set log_archive_dest_state_2=enable;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> connect sys/oracle@physt as sysdba
Connected.
SQL> select status,sequence# from v$managed_standby where process='MRP0';

STATUS          SEQUENCE#
------------ ----------
APPLYING_LOG         15
Everything is fine now on the Database Layer: OLD Primary is still Primary, NEW Primary is again Standby, applying Redo from the OLD Primary. Only the Data Guard Broker is confused now – we need to create a new configuration:
[oracle@uhesse ~]$ dgmgrl sys/oracle@prima
DGMGRL for Linux: Version 11.2.0.1.0 - 64bit Production

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

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> show configuration;
ORA-16795: the standby database needs to be re-created

Configuration details cannot be determined by DGMGRL
[oracle@uhesse ~]$ sqlplus sys/oracle@physt as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 16 10:46:13 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

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

SQL> alter system set dg_broker_start=false;

System altered.

SQL> connect sys/oracle@prima as sysdba
Connected.
SQL> alter system set dg_broker_start=false;

System altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@uhesse ~]$ rm $ORACLE_HOME/dbs/dr*
The above deleted the Broker Config Files. Now we create a new Broker Configuration:
[oracle@uhesse ~]$ sqlplus sys/oracle@physt as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 16 10:48:22 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

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

SQL> alter system set dg_broker_start=true;

System altered.

SQL> connect sys/oracle@prima as sysdba
Connected.
SQL> alter system set dg_broker_start=true;

System altered.

[oracle@uhesse ~]$ dgmgrl sys/oracle@prima
DGMGRL for Linux: Version 11.2.0.1.0 - 64bit Production

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

Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> create configuration mycon as primary database is prima connect identifier is prima;
Configuration "mycon" created with primary database "prima"
DGMGRL> add database physt as connect identifier is physt maintained as physical;
Database "physt" added
DGMGRL> enable configuration;
Enabled.
DGMGRL> show configuration;

Configuration - mycon

  Protection Mode: MaxPerformance
  Databases:
    prima - Primary database
    physt - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
That was it

Connect Time Failover & Transparent Application Failover for Data Guard

Connect Time Failover & Transparent Application Failover for Data Guard

I was giving a 10g Data Guard course this week in Düsseldorf, demonstrating amongst others the possibility to configure Transparent Application Failover (TAF) for Data Guard. I always try to keep things as simple as seriously possible, in order to achieve an easy and good understanding of what I like to explain. Later on, things are getting complex by themselves soon enough :-)
In my simple scenario, I have one Primary Database (prima) and one Physical Standby Database (physt). After a switchover or after a failover, the primary is going to be physt. The challenge is now to get the connect from the client side to the right (primary) database. That is called Connect Time Failover and is achieved as follows:
First, we make sure that the client uses a tnsnames.ora with a connect descriptor that uses a SERVICE_NAME instead of a SID
MYAPP =
 (DESCRIPTION =
 (ADDRESS_LIST =
 (ADDRESS = (PROTOCOL = TCP)(HOST = HostA)(PORT = 1521))
 (ADDRESS = (PROTOCOL = TCP)(HOST = HostB)(PORT = 1521))
 )
 (CONNECT_DATA =
 (SERVICE_NAME = myapp)
 )
 )
HostA is the host on which prima runs, HostB has physt running.
Second, we take care that the service myapp is offered only at the right database – only on the primary.Notice that the PMON background processes of both databases must be able to communicate with the (local) listeners in order to register the service myapp. If you don’t use the listener port 1521, they can’t. You have to point to that listener port then with the initialization parameter LOCAL_LISTENER.
We create and start now the service myapp manually on the primary:
begin
 dbms_service.create_service('myapp','myapp');
end;
/
begin
 DBMS_SERVICE.START_SERVICE('myapp');
end;
/
Then we create a trigger, that ensures that this service is only offered, if the database is in the primary role:
create trigger myapptrigg after startup on database
declare
 v_role varchar(30);
begin
 select database_role into v_role from v$database;
 if v_role = 'PRIMARY' then
 DBMS_SERVICE.START_SERVICE('myapp');
 else
 DBMS_SERVICE.STOP_SERVICE('myapp');
 end if;
end;
/
The event after startup is fired, if an instance changes from status MOUNT to OPEN. If you use a logical standby, it is not fired, because the logical standby remains in status OPEN. You may use the event after db_role_change in this case. The creation of the trigger and of the service is accompanied with redo protocol (the Data Dictionary has changed) and therefore also present at physt without any additional work to do there for the DBA. With the present setup, we have already achieved Connect Time Failover: Clients can use the same connect descriptor (myapp) to get to the right (primary) database now, regardless of switchover or failover.
But sessions that are connected to prima are disconnected if a switchover or failover to physt takes place. They have got to connect again then. We can change that, so that a Runtime Failover is possible, under ideal circumstances, that failover is even completely transparent to the client and proceeds without error messages. To achieve that, you don’t have to touch the tnsnames.ora on the client side. Instead, you do the following on the primary database:
begin
 dbms_service.modify_service
 ('myapp',
 FAILOVER_METHOD => 'BASIC',
 FAILOVER_TYPE => 'SELECT',
 FAILOVER_RETRIES => 200,
 FAILOVER_DELAY => 1);
end;
/
Connections to the service myapp are now automatically failed over together with the service to the new primary. Should they have done nothing during the time of the failover/switchover, or even if they had run a select statement, they will not receive any error but only notice a short interruption (about 20 seconds, in a typical case). Only if sessions have open transactions during the failover/switchover, they will receive error messages (“transaction must roll back”) after they try commit then.
I use to demonstrate that with a select on a table with 100000 rows that starts on the primary. Then I kill the SMON of that primary and the select stops at row 30000 something, waits a couple of seconds (maximal 200, with the above settings) and then continues on the new primary after the failover, fetching exactly the 100000 rows! That is always quite impressive and shows how robust Oracle Databases – especially combined with Data Guard – are :-)

Thursday 9 October 2014

Preventing standby databases opening in Active DataGuard mode


SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

SQL>

SQL> alter database open;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY WITH APPLY


At this stage we can access all objects from the standby database without any issues. This is Active Data Guard in action.

 Alert log:

...
Physical standby database opened for read only access.
Completed: alter database open
Tue Oct 02 08:30:46 2012
Data Guard: Database open completed; restarting redo-apply ...
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE  THROUGH ALL SWITCHOVER DISCONNECT  USING CURRENT LOGFILE
Attempt to start background Managed Standby Recovery process (emrepsby)
Tue Oct 02 08:30:46 2012
MRP0 started with pid=35, OS id=20294
MRP0: Background Managed Standby Recovery process started (emrepsby)
 started logmerger process
Tue Oct 02 08:30:51 2012
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 2 slaves
...

There is the oracle hidden parameter “_Query_on_physical”. When the physical standby database is configured, this parameter is not set and the normal behaviour is expected. However when the parameter is applied to the standby database, we see the following changes;


SQL> alter system set "_query_on_physical"=false scope=spfile;

System altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-16669: instance cannot be opened because the Active Data Guard option is
disabled

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED
...
alter database open
Data Guard Broker initializing...
Data Guard: Active Data Guard is not enabled, database open not allowed
ORA-16669 signalled during: alter database open...
...

Wednesday 1 October 2014

Active Dataguard Nasıl Yapılır

İlk olarak primary veritabanı kontrol edilir.

  SQL> select status,instance_name,database_role from v$instance,v$database;
  STATUS       INSTANCE_NAME    DATABASE_ROLE
  ------------ ---------------- ----------------
  OPEN         prim             PRIMARY

  SQL> select max(sequence#) from v$archived_log;
  MAX(SEQUENCE#)
  --------------
  40

Sonrasında physical standby veritabanı kontrol edilir.

  SQL> select status,instance_name,database_role from v$database,v$instance;
  STATUS   INSTANCE_NAME DATABASE_ROLE
  -------- ------------- ---------------------
  MOUNTED  stnd          PHYSICAL STANDBY
 

SQL> select max(sequence#) from v$archived_log where applied='YES';
  MAX(SEQUENCE#)
  --------------
  40

physical standby veritabanında MRP process'i kontrol edilir.

  SQL> select process,status,sequence# from v$managed_standby;
  PROCESS   STATUS        SEQUENCE#
  --------- ------------ ----------
  ARCH      CONNECTED     0
  ARCH      CONNECTED     0
  ARCH      CONNECTED     0
  ARCH      CONNECTED     0
  RFS       IDLE          41
  RFS       IDLE          0
  RFS       IDLE          0
  RFS       IDLE          0
  MRP0      WAIT_FOR_LOG  41
  9 rows selected.

MRP process'i durdurulur, database açılır ve MRP process'i yeniden başlatılır.

  SQL> alter database recover managed standby database cancel;
  Database altered.

  SQL> alter database open;
  Database altered.

 SQL> select status,instance_name,database_role,open_mode from v$database,v$instance;
  STATUS INSTANCE_NAME  DATABASE_ROLE    OPEN_MODE
  ------ -------------- ---------------- ---------------
  OPEN   stnd           PHYSICAL STANDBY READ ONLY

 SQL> alter database recover managed standby database disconnect from session;
  Database altered.

Pyshical standby veritanında MRP process'i kontrol edilir.

  SQL> select process,status,sequence# from v$managed_standby;
  PROCESS   STATUS        SEQUENCE#
  --------- ------------ ----------
  ARCH      CONNECTED     0
  ARCH      CONNECTED     0
  ARCH      CONNECTED     0
  ARCH      CONNECTED     0
  RFS       IDLE          41
  RFS       IDLE          0
  RFS       IDLE          0
  RFS       IDLE          0
  MRP0      WAIT_FOR_LOG  41
  9 rows selected.

Data guard replikasyonu başlatma ve durdurma (Standby Veritabanında)

Data guard kurulumundan sonra standby database'de  :

 alter database recover managed standby database using current logfile disconnect from session

veya

 alter database recover managed standby database disconnect from session

çağrılabilir. Bu artık redo log'ların standby database'e uygulanmasını sağlayacaktır. İptal etmek için :


 alter database recover managed standby database cancel

komutu yeterli olacaktır.


Using Current logfile : Veritabanini otomatik olarak mount eder.
disconnect from session : Redo Apply process'i arka plandaki bir oturumda calisir.

Dataguard Broker Configuration Yaratma ve Kaldırma

Dataguard Broker Konfigürasyonu (Broker Suspend Oluyorsa vs.)
Dataguard broker konfigürasyonu 3 adımda yaratılır :

   create configuration primaryConf as primary database is PRMDB connect identifier is PRMDB

   add database STDBYDB as connect identifier is STDBYDB maintained as physical

   enable configuration


Remove ederken;

   remove configuration

komutu yeterli olmayabiliyor, bu yüzden standby ve primary veritabanlarında ORACLE_HOME\database altında bulunan ve "DR" ile başlayan "dat" dosyalarının silinmesi gerekebilir.

Enterprise Manager Reconfiguration / Recreation

cmd->emca -deconfig dbcontrol db -repos drop


SQL> alter user sysman account unlock; SQL> drop user sysman cascade;

User dropped.

SQL> drop public synonym setemviewusercontext;

Synonym dropped.

SQL> drop role mgmt_user;

Role dropped.

SQL> drop public synonym mgmt_target_blackouts;

Synonym dropped.

SQL> drop user mgmt_view;

User dropped.


cmd->emca -config dbcontrol db -repos create

Fast Start Failover Running

Öncelikle Primary database'in Flashback özelliği enable edilmelidir.

   shu immediate
   startup mount
   ALTER SYSTEM SET UNDO_RETENTION=3600 SCOPE=SPFILE;
   ALTER SYSTEM SET UNDO_MANAGEMENT='AUTO' SCOPE=SPFILE;
   ALTER DATABASE FLASHBACK ON;
   ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;
   shu immediate;
   startup

Benzer işlemler standby database'de tekrarlanmalıdır.

   shu immediate
   startup mount
   ALTER SYSTEM SET UNDO_RETENTION=3600 SCOPE=SPFILE;
   ALTER SYSTEM SET UNDO_MANAGEMENT='AUTO' SCOPE=SPFILE;
   ALTER DATABASE FLASHBACK ON;
   shu immediate;
   startup mount
   ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
   ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;

Primary Database'de :

   DGMGRL

   EDIT DATABASE PRM SET PROPERTY FastStartFailoverTarget='STDBY';
   EDIT DATABASE STDBY SET PROPERTY FastStartFailoverTarget='PRM';

synch olacaksa :
   EDIT DATABASE PRM SET PROPERTY 'LogXptMode'='SYNC';
   EDIT DATABASE STDBY SET PROPERTY 'LogXptMode'='SYNC';
   EDIT CONFIGURATION SET PROTECTION MODE AS MAXAVAILABILITY;
fast start failover enable edilir.

   enable fast_start failover

3.cü makine'de:

  dgmgrl
  connect sys/oracle@primary database
  connect sys/oracle@standby database
  start observer;
Durdurulacağı zaman :

  dgmgrl
  connect sys/oracle@primary database
  connect sys/oracle@standby database
  stop observer;

How to Open Standby Database When Primary is Lost

Startup Mount

 [oracle@rac2 ~]$ sqlplus / as sysdba
 SQL*Plus: Release 10.2.0.3.0 - Production on Wed Feb 4 19:51:12 2009
 Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
 Connected to an idle instance.
 SQL> STARTUP MOUNT
 ORACLE instance started.
 Total System Global Area 218103808 bytes
 Fixed Size 1260984 bytes
 Variable Size 184549960 bytes
 Database Buffers 29360128 bytes
 Redo Buffers 2932736 bytes
 Database mounted.

Check Status

 SQL> SELECT OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE FROM V$DATABASE;
 OPEN_MODE PROTECTION_MODE DATABASE_ROLE
 ---------- -------------------- ----------------
 MOUNTED MAXIMUM PERFORMANCE PHYSICAL STANDBY

Recover if you have logs to apply
In this example the primary is lost and I don't have more archived logs to apply:

  SQL> RECOVER STANDBY DATABASE;
  ORA-00279: change 794348 generated at 12/29/2008 12:23:02 needed for thread 1
  ORA-00289: suggestion :
  /u01/app/oracle/oradata/dgfdb/archive/1_49_633452428.dbf
  ORA-00280: change 794348 for thread 1 is in sequence #49
  Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  ORA-00308: cannot open archived log
  '/u01/app/oracle/oradata/dgfdb/archive/1_49_633452428.dbf'
  ORA-27037: unable to obtain file status
  Linux Error: 2: No such file or directory
  Additional information: 3
  SQL> !ls -l /u01/app/oracle/oradata/dgfdb/archive/
  total 31072
  -rw-r----- 1 oracle oinstall 1158656 Dec 29 11:31 1_37_633452428.dbf
  -rw-r----- 1 oracle oinstall 7385600 Dec 29 11:31 1_38_633452428.dbf
  -rw-r----- 1 oracle oinstall 4941824 Dec 29 11:31 1_39_633452428.dbf
  -rw-r----- 1 oracle oinstall 13739008 Dec 29 11:31 1_40_633452428.dbf
  -rw-r----- 1 oracle oinstall 2272256 Dec 29 11:50 1_41_633452428.dbf
  -rw-r----- 1 oracle oinstall 1024 Dec 29 11:51 1_42_633452428.dbf
  -rw-r----- 1 oracle oinstall 89088 Dec 29 11:51 1_43_633452428.dbf
  -rw-r----- 1 oracle oinstall 1847296 Dec 29 12:18 1_44_633452428.dbf
  -rw-r----- 1 oracle oinstall 135680 Dec 29 12:18 1_45_633452428.dbf
  -rw-r----- 1 oracle oinstall 67584 Dec 29 12:19 1_46_633452428.dbf
  -rw-r----- 1 oracle oinstall 34816 Dec 29 12:22 1_47_633452428.dbf
  -rw-r----- 1 oracle oinstall 2048 Dec 29 12:22 1_48_633452428.dbf

Finish the Recovery process

 SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
 Database altered.

Activate the Standby Database

 SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
 Database altered.

Check the new status

 SQL> SELECT OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE FROM V$DATABASE;
 OPEN_MODE PROTECTION_MODE DATABASE_ROLE
 ---------- -------------------- ----------------
 MOUNTED MAXIMUM PERFORMANCE PRIMARY

Open the Database

 SQL> ALTER DATABASE OPEN;
 Database altered.
 SQL> SELECT OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE FROM V$DATABASE;
 OPEN_MODE PROTECTION_MODE DATABASE_ROLE
 ---------- -------------------- ----------------
 READ WRITE MAXIMUM PERFORMANCE PRIMARY

OCI ile Veritabanına Bağlanırken Failover/Switchover Durumunda Etkilenmeme ve Load Balancing İşlemi

Fast start Failover aktif edildikte sonra, client server'a bağlanırken 2 tane data source kullanır.


1.cisi SELECT statement’I icin: (JAVA kodu)

String urlString = "jdbc:oracle:oci:@(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.11)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.10)(PORT=1521))
(FAILOVER=true)(LOAD_BALANCE=ON)
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=LBTEST)))";



2.cisi INSERT/UPDATE/DELETE statement’I icin : (JAVA kodu)

String urlString = "jdbc:oracle:oci:@(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.11)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.10)(PORT=1521))
(FAILOVER=true)(LOAD_BALANCE=OFF)
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=LBTELAYS)))";


Normal durumda : Load balance oldugu icin, select her ikisini de ulasmaya calisir. Veritabanı tarafından load balacing işlemi gerçekleştirilir.

Failover ve switchover durumunda trigger’dan (aşağıda) dolayi primary olan database calisiyor olacaktir, ona baglanacak ve islemi gerceklestirecektir.




BEGIN
 DBMS_SERVICE.CREATE_SERVICE('LBTELAYS','LBTELAYS');
 end;
 /

  BEGIN
 DBMS_SERVICE.MODIFY_SERVICE
 ('LBTELAYS',
 FAILOVER_METHOD => 'BASIC',
    FAILOVER_TYPE => 'SELECT',
    FAILOVER_RETRIES => 200,
    FAILOVER_DELAY => 45);
 END;
 /

CREATE TRIGGER CHECK_LBTELAYS_START AFTER STARTUP ON DATABASE
DECLARE
 V_ROLE VARCHAR(30);
 BEGIN
  SELECT DATABASE_ROLE INTO V_ROLE FROM V$DATABASE;
  IF V_ROLE = 'PRIMARY' THEN
   DBMS_SERVICE.START_SERVICE('LBTELAYS');
  ELSE
   DBMS_SERVICE.STOP_SERVICE('LBTELAYS');
  END IF;
 END;
/

 BEGIN
  DBMS_SERVICE.START_SERVICE('LBTELAYS');
 END;
 /

Duplicate Komutuyla Oracle Data Guard Kurulumu

Varsayımlar: Standby database'de sadece software install edilmiş yada yaratılacak servis adı orada bulunmuyor. Primary ve Standby database isimleri birbirinden farklı

Primary Database'de sql komut satırından aşağıdaki komutlar çalıştırılı;

           sqlplus sys/oracle as sysdba

          ALTER DATABASE FORCE LOGGING;
          alter database add standby logfile 'D:\app\ali.yagmur\oradata\ank\srl01.log' size 50M;
          alter database add standby logfile 'D:\app\ali.yagmur\oradata\ank\srl02.log' size 50M;
          alter database add standby logfile 'D:\app\ali.yagmur\oradata\ank\srl03.log' size 50M;
          alter database add standby logfile 'D:\app\ali.yagmur\oradata\ank\srl04.log' size 50M;
          alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST';
          alter system set log_archive_config='dg_config=(ank,anksb)';
          alter system set log_archive_dest_2='service=anksb async valid_for=(online_logfile,primary_role) db_unique_name=anksb';
          ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1=ENABLE;
          ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
          alter system set log_archive_max_processes=30;
          ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;
          alter system set STANDBY_FILE_MANAGEMENT=AUTO;

    *
          o
                + bu sonrada yapılabilir. alter system set dg_broker_start=true;

          alter system set DB_FILE_NAME_CONVERT='ank','anksb' scope=spfile;
          alter system set LOG_FILE_NAME_CONVERT='D:\app\ali.yagmur\oradata\ank', 'c:\app\oracle\oradata\anksb' scope=spfile;
          alter system set db_recovery_file_dest_size = 5G;
          shutdown immediate;
          startup mount;
          ALTER DATABASE ARCHIVELOG;
          ALTER DATABASE OPEN;

İkinci adım rman'le backup almak olacaktır.

           rman target sys/oracle
           backup database plus archivelog

Üçüncü adım listener ve tnsnames.ora dosyalarının düzenlenmesi olacaktır.

Listener.ora / Primary (Eklenecekler)

   (SID_DESC =
     (GLOBAL_DBNAME = ank)
     (ORACLE_HOME = D:\app\ali.yagmur\product\11.2.0\dbhome_1)
     (SID_NAME = ank)
   )
   (SID_DESC =
     (GLOBAL_DBNAME = ank_DGMRL)
     (ORACLE_HOME = D:\app\ali.yagmur\product\11.2.0\dbhome_1)
     (SID_NAME = ank)
   )

TnsNames.ora / Primary (Eklenecekler)

 ANK =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = ALIYAGMUR-PC.ug.net)(PORT = 1521))
     (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = ank)
     )
   )

 ANKSB =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = ydbase)(PORT = 1521))
     (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = anksb)
     )
   )


Listener.ora / Standby (Oldugu gibi)

 # listener.ora Network Configuration File: c:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
 # Generated by Oracle configuration tools.

 SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = c:\app\oracle\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:c:\app\oracle\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
    (SID_DESC =
      (GLOBAL_DBNAME = anksb)
      (ORACLE_HOME = c:\app\oracle\product\11.2.0\dbhome_1)
      (SID_NAME = anksb)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = anksb_DGMGRL)
      (ORACLE_HOME = c:\app\oracle\product\11.2.0\dbhome_1)
      (SID_NAME = anksb)
    )
   )

 LISTENER =
   (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ydbase)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
   )

 ADR_BASE_LISTENER = c:\app\oracle

TnsNames.ora / Standby (As It is)

   1. tnsnames.ora Network Configuration File: c:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora
   2. Generated by Oracle configuration tools.

 anksb =
   (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ydbase)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = anksb)
    )
   )

 ank=
   (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ALIYAGMUR-PC.ug.net)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ank)
    )
   )

 ORACLR_CONNECTION_DATA =
   (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
    )
   )

Sonraki aşamada primary database'de password dosyası yaratılır ve standby database'e kopyalanır.

   orapwd file=d:\app\ali.yagmur\product\11.2.0\dbhome_1\database\PWDANK.ora password=oracle entries=10 ignorecase=y
   dosya standby database'in ORACLE_HOME\database kalsörü altına kopyalanır.

Daha sonraki aşamada Standby database ile ilgili service yaratılır.

   oradim -new -sid ANKSB -syspwd oracle (oracle : sys user'ının password'u)

Standby'da database ile ilgili klasörler oluşturulur :

   mkdir c:\app\oracle\admin
   mkdir c:\app\oracle\admin\anksb
   mkdir c:\app\oracle\admin\anksb\adump
   mkdir c:\app\oracle\admin\anksb\dpdump
   mkdir c:\app\oracle\admin\anksb\pfile
   mkdir c:\app\oracle\oradata
   mkdir c:\app\oracle\oradata\anksb
   mkdir c:\app\oracle\flash_recovery_area
   mkdir c:\app\oracle\flash_recovery_area\anksb


Standby database'de init dosyası oluşturulur.

   C:\app\oracle\product\11.2.0\dbhome_1\database\initANKSB.ora dosyasına ;
   DB_NAME=ANKSB yazılır. (Eğer primary ve standby isimleri farklı olacaksa StdbyDbName STDBY olarak kullanılabilir.)

sonra sqlplus ile bağlanılarak standby database nomount durumunda açılır;

   sqlplus sys/oracle@anksb as sysdba

   startup nomount pfile='C:\app\oracle\product\11.2.0\dbhome_1\database\initANKSB.ora'

Son adım primary database rman ile duplicate komutunu çalıştırmak olacaktır:

      rman target sys/oracle@ank auxiliary sys/oracle@ANKSB
      RMAN> run{
                          allocate channel prmy1 type disk;
                          allocate channel prmy2 type disk;
                          allocate channel prmy3 type disk;
                          allocate channel prmy4 type disk;
                          allocate auxiliary channel stby type disk;
                          duplicate target database for standby from active database
                          spfile
                          parameter_value_convert 'ank','anksb'
                           set DB_FILE_NAME_CONVERT = 'd:\app\ali.yagmur\oradata\ank' , 'c:\app\oracle\oradata\anksb'
                           set LOG_FILE_NAME_CONVERT='d:\app\ali.yagmur\oradata\ank','c:\app\oracle\oradata\anksb'
                           set db_unique_name='anksb'
                           set db_create_file_dest='c:\app\oracle\oradata\anksb'
                           set db_recovery_file_dest='c:\app\oracle\flash_recovery_area'
                           set diagnostic_dest='c:\app\oracle'
                           set audit_file_dest='c:\app\oracle\admin\anksb\adump'
                           set db_recovery_file_dest_size='5G'
                           set control_files='c:\app\oracle\oradata\control01.ctl'
                           set log_archive_max_processes='5'
                           set fal_client='anksb'
                           set fal_server='ank'
                           set standby_file_management='AUTO'
                           set log_archive_config='dg_config=(ank, anksb)'
                           set log_archive_dest_2='service=ank ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=ank';
                }

Redo apply'ın çalışması için standby database'de şu komut çalıştırılabilir :

    alter database recover managed standby database using current logfile disconnect from session;

DGM-17016: failed to retrieve status for database ORA-16664: unable to receive the result from a database



ORA-16664: unable to receive the result from a database
Cause: During execution of a command, a database in the Data Guard broker configuration failed to return a result.
Action: Check Data Guard broker logs for the details of the failure. Fix any possible network problems and try the command again.


DGM-17016: failed to retrieve status for database 

Opening standby database in read only mode causes to error affecting data guard broker configuration. You should open database in "mount" state. If operating system is Windows, then you should edit registry editor for that database is not automatically started.


In Registry editor:

ORA_DBUNIQUENAME_AUTOSTART should be false in "HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_ORACLEHOMENAME".

After  this, you should start database in mount state. I give an example script for that:


   @ECHO off

   set dbuser=sys

   set dbpass=oracle

   set dbtns=orcl

   set primaryDB=PRIMARY

   set physicalSB=PHYSICAL STANDBY

   set telaysServiceName=telays

   reg add "HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1" /v "ORA_%dbtns%_AUTOSTART" /t REG_SZ /d "FALSE" /f

   set oracle_sid=%dbtns%

  
   lsnrctl start listener

   rem waits 10 seconds

   ping 199.987.4.4 -n 1 -w 10000 > nul

  
   net start oracleservice%dbtns%

   rem waits 1 second

   ping 199.987.4.4 -n 1 -w 1000 > nul
  
  
   echo  startup mount;> c:\startmount.sql

   echo exit; >> c:\startmount.sql

   sqlplus -s "%dbuser%/%dbpass%@%dbtns%" as sysdba @c:\startmount.sql

  
   echo set pagesize 0; > c:\temp.sql

   echo spool c:\temp.txt; >> c:\temp.sql

   echo select database_role from v$database; >> c:\temp.sql

   echo spool off; >> c:\temp.sql

   echo exit; >> c:\temp.sql

   sqlplus -s "%dbuser%/%dbpass%@%dbtns%" as sysdba @c:\temp.sql

  
   FOR /F "tokens=* delims=" %%a IN (c:\temp.txt) do set src=%%a

   setlocal enabledelayedexpansion

   for /f "tokens=* delims= " %%a in ("%src%") do set src=%%a

   for /l %%a in (1,1,100) do if "!src:~-1!"==" " set src=!src:~0,-1!

   echo."%src%"

  
           if "%src%" == "%primaryDB%" (
               rem start the database
               echo  alter database open;> c:\start.sql

           echo exit; >> c:\start.sql
               sqlplus -s "%dbuser%/%dbpass%@%dbtns%" as sysdba @c:\start.sql
               rem start application server
               net start %telaysServiceName%
               eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO "TELAYS WINDOWS ACILISI" /D "Veritabani ve application server veritabani rolune gore acildi"
           ) else if "%src%" == "%physicalSB%" (
               rem start replication
           echo alter database recover managed standby database disconnect from session; >> c:\start.sql
               echo exit; >> c:\start.sql
           sqlplus -s "%dbuser%/%dbpass%@%dbtns%" as sysdba @c:\start.sql
               eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO "TELAYS WINDOWS ACILISI" /D "Veritabani veritabani rolune gore acildi"
       ) else (
               eventcreate /ID 1 /L APPLICATION /T ERROR /SO "TELAYS WINDOWS ACILISI" /D "Veritabani rolu yanlis"
       )
   del c:\temp.txt
   del c:\temp.sql
   del c:\start.sql
   del c:\startmount.sql
  
   endlocal & exit

Recovering undo tablespace from corrupted undo Datafile


  alter system set undo_management=manual scope=spfile;
  shu immediate;
  startup mount;
  alter database datafile 'C:\APP\ADMINISTRATOR\ORADATA\TSTCLONE\UNDOTBS01.DBF' offline drop;
  alter databae open;
  drop tablespace undotbs1;
  create undo tablespace undotbs2 datafile 'C:\app\Administrator\oradata\ANKARA\UNDOTBS01.DBF'  size 100M   REUSE AUTOEXTEND ON NEXT  5120K MAXSIZE  2000M;
  alter system set undo_management=auto scope=spfile;
  alter system set undo_retention = 900 scope = both;
  shu immediate;
  startup;

ORA-00280: change string for thread string is in sequence #string



ORA-00280: change string for thread string is in sequence #string
Cause: This message helps to locate the redo log file with the specified change number requested by other messages.
Action: Use the information provided in this message to specify the required archived redo log files for other errors.

Çözüm :

SQL> startup mount
SQL>
RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL;

  CANCEL

SQL> ALTER DATABASE open resetlogs