Wednesday, 13 December 2023

Oracle 19C RAC Database stop and start Step By Step process

 

Dear All,


In this post i am going to show you how to start and stop Oracle 19c RAC Database services including cluster services .


Check the db and grid background process status from putty ( backend ) 

ps -ef |grep oracle / ps -fu $USER  >> this will show you the all the process which are running under specific login user .


ps -ef |grep grid

ps -ef |grep d.bin

ps -ef |grep smon




Check the DB and Oracle Instance status from SQL prompt : 


select name,open_mode,instance_name from v$database,v$instance;

 


 

 

 Stop the database :: 

 

srvctl stop database -d RACSDB -o immediate

srvctl stop database -d RACSDB

 



Start and stop individual Instances : 


srvctl start instance -d RACSDB -i racsdb1

srvctl start instance -d RACSDB -i racsdb2

 

srvctl stop instance -d RACSDB -i racsdb1

srvctl stop instance -d RACSDB -i racsdb2

 



 Start and stop the cluster services :


Note : login to root user and go the grid home/bin path and execute below commands 


##cluster status 

./crsctl check cluster -all

./crsctl stat res -t

./crsctl check crs







##stop the cluster services 

./crsctl stop crs






##start the cluster services 

./crsctl start crs

 


crsctl check cluster -all

crsctl start res ora.crsd -init

crsctl check crs

./crsctl stat res -t









crsctl check crs

>>> Check Oracle High Availability Services On The Local Server.


crsctl stop crs

>>> Stop Oracle High Availability Services On The Local Server.


crsctl start crs

 >>> Start Oracle High Availability Services On The Local Server.

 

crsctl query crs software version

>>> Check Oracle Cluster ware Software Version


crsctl query crs 
active version

 >>> Check Oracle Cluster ware Active Version


crsctl query crs 
release version

>>> Check Oracle Cluster ware Release Version

 




 Thanks,

srini


Tuesday, 12 December 2023

Oracle DBA Interview Q&A - Part 3

 Dear All,


Here i'm posting few Oracle DBA Interview Question and answers these will help you on Fresher or experience level technical Interviews .


1. Oracle Database Administration ( DBA ):

Q: How do you create a new user in Oracle DB?

Answer: To create a new user in Oracle, you can use the CREATE USER SQL statement. For example:


SQL > CREATE USER username IDENTIFIED BY password;

Q: Explain the difference between ARCHIVELOG and NOARCHIVELOG mode in Oracle DB.

Answer:

 In ARCHIVELOG mode, the database archives filled redo log files to a specified storage location, allowing for complete recovery from media or instance failure. In NOARCHIVELOG mode, the database does not archive filled redo log files, limiting recovery options.

 

Q. What is Oracle Database ( DB)?

 

Answer: 

Oracle Database is a relational database management system (RDBMS) developed by Oracle Corporation. It is a collection of data and procedures, which can be accessed and managed by various applications.

 

Q. Explain the architecture of Oracle Database ( DB).

 

Answer: 


Oracle Database architecture consists of the following components:

 

Instance: It is a set of memory structures and background processes that manage a database.

Database: It is a collection of physical files on disk managed by Oracle.

Tablespace: Logical storage unit within a database where actual data is stored.

Data files, Control files, Redo log files: Physical files associated with an Oracle database.

Q. Explain the role of the REDO log in Oracle DB.

 

Answer: 


The REDO log records all changes made to the database. It plays a crucial role in database recovery in case of a failure. REDO log files store changes before they are actually written to the database files, ensuring data integrity and recoverability.

 

2. Performance Tuning:

Q: How do you identify and resolve performance bottlenecks in Oracle Database ?

Answer: Performance bottlenecks can be identified using tools like Oracle Enterprise Manager or by querying dynamic performance views (e.g., V$SESSION, V$SQL, V$SQL_PLAN). Common tuning techniques include optimizing SQL queries, adding indexes, adjusting memory parameters, and optimizing I/O.

Q: What is the purpose of an Oracle index and how does it improve query performance in Database?

Answer:

 An Oracle index is a database object that improves the speed of data retrieval operations on a table at the cost of additional storage and decreased performance on data modification operations. Indexes provide a faster way to access rows, reducing the need for full-table scans.

 

3. Oracle Backup and Recovery:

Q: How do you perform a hot backup in Oracle database?

Answer: 

Hot backup, also known as online backup, can be performed using tools like RMAN (Recovery Manager) or by using the ALTER TABLESPACE BEGIN BACKUP and END BACKUP commands to put tablespaces in backup mode and copy the data files while the database is online.

Q: Explain the steps to recover a database using RMAN after a critical failure of database.

Answer: 

To recover a database using RMAN, you would typically:

 

Restore the database files from a valid backup.

Apply incremental backups, if available, to reduce recovery time.

Apply archived redo logs to roll forward the database to the desired point in time.

Open the database with the RESETLOGS option to reset the redo log sequence.

 

4. Security in Oracle DB:

Q: How do you grant and revoke privileges in Oracle DB?

Answer:

 Privileges can be granted using the GRANT statement and revoked using the REVOKE statement. For example:

 

SQL > GRANT SELECT, INSERT ON table_name TO username;

SQL > REVOKE SELECT ON table_name FROM username;

Q: What is Oracle Transparent Data Encryption (TDE) and how does it enhance security in Oracle DB?

Answer: 

Oracle TDE encrypts sensitive data stored in database columns, tablespaces, or entire databases, adding an additional layer of security. It helps protect data at rest, preventing unauthorized access to sensitive information.

 

5. Troubleshooting Questions :

Q: How do you diagnose and resolve locking issues in Oracle database?

Answer: 

Locking issues can be diagnosed by querying the V$LOCK and V$SESSION views. To resolve locking problems, you can either commit or rollback open transactions, release locks explicitly, or tune SQL statements causing excessive locks.

Q: What are common causes of performance degradation in Oracle databases ( DB), and how do you address them?

Answer:

 Performance degradation can be caused by suboptimal SQL queries, inadequate hardware resources, inefficient database design, or improper configuration. Addressing these issues involves optimizing SQL queries, adjusting memory and I/O configurations, and periodically reviewing database schema and indexing strategies.

Q. How do you optimize SQL queries for better performance in Oracle database?

 

Answer: 

Optimization techniques include:

Analyzing query execution plans using tools like Explain Plan.

Indexing frequently queried columns.

Avoiding the use of SELECT * and fetching only necessary columns.

Using appropriate hints to guide the optimizer.

Regularly analyzing and rebuilding indexes.

Properly designing database schema and normalizing data.

Q. Explain what a deadlock is and how to resolve it in oracle.

 Answer:

 A deadlock occurs when two or more transactions are blocked, each waiting for the other to release a resource. To resolve a deadlock, Oracle automatically detects and resolves it by rolling back one of the statements involved in the deadlock. Proper transaction management and application design can also prevent deadlocks.



Thanks,

Srini



Saturday, 9 December 2023

Step by Step Oracle 19C Data Guard setup on Oracle VM

 Dear All,


In this post i am going to share you oracle 19c Data guard step by step activity guide .


Primary database details :

 

Db name : PROD

Db unique name :stby

Host & IP :  standby.localdomain

SID : stby

 

Standby Database Details :

 

Db name : PROD

Db unique name : prod

Host & IP : primary.localdomain

SID : prod



DG Configuration steps : 

Step:1 Enable the archive log  mode in the primary database.

 

alter database archivelog;

archive log list;


Step:2 Enable the force logging. 

SQL> alter database force logging;

Database altered.

 

Note : to enable flash back we need to setup below pre-requisites

alter system set db_recovery_file_dest_size= 10G scope=both;

 

alter system set db_recovery_file_dest='/u02/app/oracle/fast_recovery_area' scope=both;


Step:3 Flashback should be enabled in primary database.

SQL> ALTER DATABASE FLASHBACK ON;

Database altered.

select name,FORCE_LOGGING,log_mode,flashback_on from v$database;




Step:4 Add the Standby redo log files for standby side.

 set lines 200

col MEMBER format a65

select l.GROUP#,l.THREAD#,f.member,l.ARCHIVED,l.status,(bytes/1024/1024) "size(MB)" from v$log l,v$logfile f where f.group#=l.group# order by 1,2;

 

select l.GROUP#,l.THREAD#,f.member,l.ARCHIVED,l.status,(bytes/1024/1024) "size(MB)" from v$standby_log l,v$logfile f where f.group#=l.group# order by 1,2;

 

SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG;


alter database add standby logfile group 4 '/u01/app/oracle/oradata/STBY/redo04.log' size 200m;

 alter database add standby logfile group 5 '/u01/app/oracle/oradata/STBY/redo05.log' size 200m;

alter database add standby logfile group 6 '/u01/app/oracle/oradata/STBY/redo06.log' size 200m;

alter database add standby logfile group 7 '/u01/app/oracle/oradata/STBY/redo07.log' size 200m;





select member from v$logfile;




Step:5 Take the backup of Primay database , pfile and password files on Primary database

 

create one directory for Primary side backups .


mkdir -p /u01/backup

cd /u01/backup


Create pfile from spfile on Primary database this we can use in the standby database side . there we need to modify some parameter as per the standby db .

create pfile='/u01backup/initprod.ora' from spfile;


copy the primary password file to backup location on Primary node this we need to copy to standby side oracle home / dbs location there we need to rename the sid as per the standby db.

cp /u01/app/oracle/product/19.0.0/db_home/dbs/initstby.ora .



rman target=/ nocatalog <<EOF

run {

    sql "alter system archive log current";

               allocate channel ch1 type disk format '/u01/backup/PROD_bkp_standby_%U';

               backup as compressed backupset database plus archivelog;

               backup current controlfile for standby;

               sql "alter system archive log current";

}

               exit;

EOF

 

Note : Tar the rman backup if you are using manual restore use this backup , if you are using active clone / active rman command no need of this backup .


tar -cvzf rmanbackup.tar.gz rman

tar -xvzf rmanbackup.tar.gz

 

Step:6  set the log archive config and other DG  parameters on primary database . see the below snap for all the parameters which i set on primary node side .


 ALTER SYSTEM SET log_archive_config='dg_config=(prod,stby)' SCOPE=both;

ALTER SYSTEM SET log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=prod' SCOPE=both;

ALTER SYSTEM SET log_archive_dest_2='service=stby async valid_for=(online_logfiles,primary_role) db_unique_name=stby' SCOPE=both;

ALTER SYSTEM SET fal_client='prod' SCOPE=both;

ALTER SYSTEM SET fal_server='stby' SCOPE=both;

ALTER SYSTEM SET standby_file_management='AUTO' SCOPE=both;

ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

 

alter system set db_file_name_convert='/u01/app/oracle/oradata/STBY/','/u01/app/oracle/oradata/PROD' scope=spfile;

alter system set log_file_name_convert='/u01/app/oracle/oradata/STBY/','/u01/app/oracle/oradata/PROD' scope=spfile;

converts the filename of a

new datafile and logfile respectively on the primary database to a filename on the

standby database.

 

 

crosscheck the DR parameters on primary once

 

col name for a30

col value for a85

set lines 200 pagesize 200

 

select name, value from v$parameter where name in ('db_name','db_unique_name','log_archive_config','log_archive_dest_1','log_archive_dest_2','log_archive_dest_state_1′,’log_archive_dest_state_2','remote_login_passwordfile','log_archive_format','log_archive_max_processes','fal_server','fal_client','db_file_name_convert','log_file_name_convert','standby_file_management');

 


 

Set the log archive format = ‘%t_%s_%r.arc ,it determines the name of the archive log file it comes into role when archive log is enabled.

 

alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;

 

Step:7 configure the log_archive_process to 6 ,it prevents to avoid any runtime overhead of invoking additional ARCn process,you can set the LOG_ARCHIVE_MAX_PROCESSES

 

alter system set log_archive_max_processes=6; ( optional ) default value is 4 

show parameter remote_login_passwordfile  ( default value )

 





Step:8 Configure standby database .

 

alter system set db_unique_name=stby scope=spfile;

select name from v$datafile;

 

show parameter audit

 

 

mkdir -p /u01/app/oracle/oradata/STBY/

mkdir -p /u01/app/oracle/oradata/STBY/pdbseed/

mkdir -p /u01/app/oracle/oradata/STBY/pdb         

mkdir -p /u01/app/oracle/oradata/STBY/adump

mkdir -p /u01/app/oracle/fast_recovery_area/

 

 

vi /u01/app/oracle/product/19.0.0/db_home/dbs/initstby.ora

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

*.audit_trail='db'

*.compatible='19.0.0.0.0'

*.control_files='/u01/app/oracle/oradata/stby/standby1.ctl'#Restore Controlfile

*.db_block_size=8192

*.db_file_name_convert='/u01/app/oracle/oradata/PROD/','/u01/app/oracle/oradata/STBY/'

*.db_name='prod'

*.db_recovery_file_dest_size=10737418240

*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area/'

*.db_unique_name='stby'

*.dg_broker_start=TRUE

*.diagnostic_dest='/u01/app/oracle/admin/stby/adump'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=stbyXDB)'

*.enable_pluggable_database=true

*.fal_client='stby'

*.fal_server=''

*.local_listener='LISTENER_PROD'

*.log_archive_config='dg_config=(stby,prod)'

*.log_archive_dest_1='location=use_db_recovery_file_dest valid_for=(all_logfiles,all_roles) db_unique_name=stby'

*.log_archive_dest_2='service="prod"','ASYNC NOAFFIRM delay=0 optional compression=disable max_failure=0 reopen=300 db_unique_name="prod" net_timeout=30','valid_for=(online_logfile,all_roles)'

*.log_archive_dest_state_2='ENABLE'

*.log_archive_format='%t_%s_%r.dbf'

*.log_archive_max_processes=5

*.log_file_name_convert='/u01/app/oracle/oradata/PROD/','/u01/app/oracle/oradata/STBY/'

*.nls_language='AMERICAN'

*.nls_territory='AMERICA'

*.open_cursors=300

*.pga_aggregate_target=568m

*.processes=300

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=1704m

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'



Step:9 Configure network files on both primary and standby databases.

 

Listener & TNS entry in the primary database


[oracle@primary admin]$ cat listener.ora

LISTENER =

      (DESCRIPTION =

           (ADDRESS = (PROTOCOL = TCP) (HOST = primary.localdomain) ( PORT = 1521))

     )



SID_LIST_LISTENER =

 (SID_LIST =

  (SID_DESC =

   (GLOBAL_DBNAME = prod)

   (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_home)

   (SID_NAME = prod)

 )

   (SID_DESC =

   (GLOBAL_DBNAME = prod_DGMGRL)

   (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_home)

   (SID_NAME = prod)

 )

)


ADR_BASE_LISTENER = /u01/app/oracle

[oracle@primary admin]$


 [oracle@primary admin]$ cat tnsnames.ora

# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.0.0/db_home/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.


PROD =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = primary.localdomain)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = prod)

    )

  )



STBY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = standby.localdomain)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = stby)

    )

  )


PDB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = primary.localdomain)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = pdb)

    )

  )


LISTENER_PROD =

  (ADDRESS = (PROTOCOL = TCP)(HOST = primary.localdomain)(PORT = 1521))


[oracle@primary admin]$



Standby side Listener and TNS details : 


[oracle@standby admin]$ cat listener.ora

LISTENER =

      (DESCRIPTION =

           (ADDRESS = (PROTOCOL = TCP) (HOST = standby.localdomain) ( PORT = 1521))

     )



SID_LIST_LISTENER =

 (SID_LIST =

  (SID_DESC =

   (GLOBAL_DBNAME = stby)

   (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_home)

   (SID_NAME = stby)

 )

   (SID_DESC =

   (GLOBAL_DBNAME = stby_DGMGRL)

   (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_home)

   (SID_NAME = stby)

 )

)


ADR_BASE_LISTENER = /u01/app/oracle


[oracle@standby admin]$ cat tnsnames.ora

STBY =

 (DESCRIPTION =

  (ADDRESS = (PROTOCOL = TCP)(HOST = standby.localdomain)(PORT = 1521))

  (CONNECT_DATA =

   (SERVER = DEDICATED)

   (SERVICE_NAME = stby)

  )

 )


PROD =

 (DESCRIPTION =

  (ADDRESS = (PROTOCOL = TCP)(HOST = primary.localdomain)(PORT = 1521))

  (CONNECT_DATA =

   (SERVER = DEDICATED)

   (SERVICE_NAME = prod)

  )

 )


LISTENER_PROD =

(ADDRESS = (PROTOCOL = TCP)(HOST = standby.localdomain)(PORT = 1521))

[oracle@standby admin]$


tnsping should work on primary and standby side : 







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

Step 10 :  update the parameter files on stand by and start standby database in nomount using newly created pfile.

 

 startup nomount pfile='initstby.ora';


 /u01/app/oracle/oradata/TEST,/u01/app/oracle/fast_recovery_area/TEST,/u01/app/oracle/oradata/TEST/pdb1

Fast recovery area location: /u01/app/oracle/fast_recovery_area/TEST

 

 rman target sys/Welcome_123@prod auxiliary sys/Welcome_123@stby

 

duplicate target database for standby from active database nofilenamecheck;


 

after restore completes enable the mrp process and then stop the db startup , it will start in read only mode .


select max(sequence#) from v$archived_log;






The same information can be obtained by checking the view v$archived_log, like this:

select sequence# from v$archived_log where registrar = 'RFS' and  applied = 'NO';




select sequence# , first_time,next_time from v$archived_log order by sequence#;

 


The actual lag that these non-applied logs causes, can be found with the query:

set lines 200

col source_db_unique_name format a10 

col value format a10

SELECT source_db_unique_name,name,value,unit,time_computed,datum_time FROM v$dataguard_stats WHERE name = 'apply lag';

 



select name,open_mode,database_role from v$database;






Note : start the mrp 


alter database recover managed standby database disconnect nodelay;


stop the mrp :


alter database recover managed standby database cancel;




DG commands : 


select name,open_mode,database_role from v$database;

 SELECT sequence#, first_time, next_time, applied FROM v$archived_log ORDER BY sequence#;

select max(sequence#) from v$archived_log;

alter database recover managed standby database cancel;

alter database recover managed standby database disconnect from session;

alter database open read only;

alter database archivelog;

alter database open;

select FORCE_LOGGING,log_mode from v$database;

alter system switch logfile;

alter database flashback on;

show parameter recovery;

select group#, thread#, bytes/1024/1024 mb from v$log;

alter database add standby logfile thread 1 size 200m;

select member from v$logfile where type='STANDBY';

alter system set db_unique_name=prod scope=both;

set linesize 500 pages 100

col name format a30

col value format a100



select name, value

from v$parameter

where name in ('db_name','db_unique_name','log_archive_config',

'log_archive_dest_1','log_archive_dest_2',

'log_archive_dest_state_1','log_archive_dest_state_2',

'remote_login_passwordfile', 'log_archive_format', 'log_archive_max_processes',

'fal_server','db_file_name_convert', 'log_file_name_convert', 'standby_file_management');


alter system set STANDBY_FILE_MANAGEMENT=AUTO scope = both;



alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,stby)' scope = both;

alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES)

DB_UNIQUE_NAME=prod' scope = both;

or 

alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST' scope = both;

ALTER SYSTEM SET log_archive_dest_2='service=stby async valid_for=(online_logfiles,primary_role) db_unique_name=stby' SCOPE=both; 

fal_client  no longer needed in 19C 

alter system set FAL_SERVER='stby' scope = both;

alter system set db_unique_name=prod scope=both;


Thanks,

Srini

Monday, 27 November 2023

Oracle Data Guard switchover with DG Broker on oracle database 19C

 Dear All,


In this post i am going to share oracle Data Guard switchover  activity using  data guard  broker.


perform an Oracle Data Guard switchover with broker, you can follow below steps:

Prepare for the switchover
Before starting the switchover process, make sure that both the primary and standby databases are synchronized and that all required logs have been applied to the standby database. Also, ensure that the broker is configured and running on both the primary and standby sites.

Manual Switchover Read Here


Step 1: Check Archvie Gap

Before starting the switchover activity let's verify the archive gap between primary and standby.


On Primary:

SQL> select thread#, max(sequence#) "Last Primary Seq# Generated" from v$archived_log v, v$database d
where v.resetlogs_change# = d.resetlogs_change#
group by thread# order by 1;




On Standby:

SQL> select thread#, max(sequence#) "Last Primary Seq# Generated" from v$archived_log v, v$database d
where v.resetlogs_change# = d.resetlogs_change#
group by thread# order by 1; 



Step 2: Connect to the broker
dgmgrl sys/Welcome_123


Step 3: Verify the configuration

DGMGRL> show configuration


Step 4: Prepare for the switchover


Validate Primary Database


DGMGRL> validate database prod;

  Database Role:    Primary database

  Ready for Switchover:  Yes

  Flashback Database Status:
    prod:  Off

  Managed by Clusterware:
    prod:  NO
    Validating static connect identifier for the primary database prod...
    The static connect identifier allows for a connection to database "prod".
Validate Standby Database

DGMGRL> validate database stby;


  Database Role:     Physical standby database
  Primary Database:  prod

  Ready for Switchover:  Yes
  Ready for Failover:    Yes (Primary Running)

  Flashback Database Status:
    prod:  Off
    stby :  Off

  Managed by Clusterware:
    prod:  NO
    stby :  NO
    Validating static connect identifier for the primary database prod...
    The static connect identifier allows for a connection to database "prod".

  Current Log File Groups Configuration:
    Thread #  Online Redo Log Groups  Standby Redo Log Groups Status
              (prod)               (stby)
    1         3                       2                       Insufficient SRLs

  Future Log File Groups Configuration:
    Thread #  Online Redo Log Groups  Standby Redo Log Groups Status
              (stby)                (prod)
    1         3                       0                       Insufficient SRLs
    Warning: standby redo logs not configured for thread 1 on prod

Step 5: Initiate the switchover

Initiate the switchover by running the "switchover to " command in dgmgrl. This will start the switchover process and automatically failover the primary database to the standby database.


DGMGRL> switchover to stby;
Performing switchover NOW, please wait...
Operation requires a connection to database "stby"
Connecting ...
Connected to "stby"
Connected as SYSDBA.
New primary database "stby" is opening...
Operation requires start up of instance "prod" on database "prod"
Starting instance "prod"...
Connected to an idle instance.
ORACLE instance started.
Connected to "prod"
Database mounted.
Database opened.
Connected to "prod"
Switchover succeeded, new primary is "stby"



Step 6: Verify the switchover

After the switchover, verify that the new primary database is running by running the "show database" command in dgmgrl.

Current Primary stby

DGMGRL> show database stby

Database - stby

  Role:               PRIMARY
  Intended State:     TRANSPORT-ON
  Instance(s):
    stby

Database Status:
SUCCESS
Current standby prod

DGMGRL> show database prod


Database - prod

  Role:               PHYSICAL STANDBY
  Intended State:     APPLY-ON
  Transport Lag:      0 seconds (computed 0 seconds ago)
  Apply Lag:          0 seconds (computed 0 seconds ago)
  Average Apply Rate: 0 Byte/s
  Real Time Query:    ON
  Instance(s):
    prod

Database Status:
SUCCESS
Database Warnings
Sometimes you will face the below error, then you have to check the log_archive_dest_1 and log_archive_dest_2 parameter on the standby side and configure it properly.

DGMGRL> show database prod


Database - prod

  Role:               PHYSICAL STANDBY
  Intended State:     APPLY-ON
  Transport Lag:      (unknown)
  Apply Lag:          (unknown)
  Average Apply Rate: (unknown)
  Real Time Query:    ON
  Instance(s):
    prod

  Database Warning(s):
    ORA-16854: apply lag could not be determined
    ORA-16856: transport lag could not be determined
    ORA-16858: last communication time from redo source could not be determined

Database Status:
WARNING


DGMGRL> show database stby;


Database - stby

  Role:               PRIMARY
  Intended State:     TRANSPORT-ON
  Instance(s):
   
Database Status:
ERROR

Step 7: Start Recovery

After the switchover start the MRP process using the broker or manually.

Enable with Broker:

DGMGRL> EDIT DATABASE prod SET STATE='APPLY-ON';
Succeeded.
Check MRP status using SQL command, if no row is selected that means MRP is disabled.

SQL> select inst_id, process, status from gv$managed_standby where process='MRP0';

   INST_ID PROCESS   STATUS
---------- --------- ------------
         1 MRP0      APPLYING_LOG
Disable with Broker
DGMGRL> EDIT DATABASE prod SET STATE='APPLY-OFF';

Enable/Disable MRP process manually:


stop MRP :

SQL> alter database recover managed standby database cancel;

start MRP:

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




Thanks,
Srini

Oracle Data Guard Failover with DG Broker on oracle database 19C

  Dear All,


In this post i am going to share oracle Data Guard Failover activity using  data guard  broker.


Note :::::
Before performing the FAILOVER activity, you should enable the FLASHBACK on standby and primary. If you missed to enable you need to rebuild the standby post failover activity.


Primary Database:

The primary database name is STBY.

Standby Database:
The Standby database name is prod.



Check the MRP process on Standby
Before doing anything let's check the MRP process on the STANDBY machine.

SQL> select sequence#,process,status from v$managed_standby;

As per the above screenshot, MRP and RFS processes are running.

Failover
To start this activity, I'm going to perform a failover on the primary database.


Step 1: Shutdown the PRIMARY Database

SQL> alter system switch logfile;

SQL> shut immediate;


Step 2: Check the MRP process again

After the shutdown of the PRIMARY database, check the MRP processes again on STANDBY.

SQL> select sequence#,process,status from v$managed_standby;
MRP process

 this time RFS is not running on the STANDBY server. after primary stoped RFS not running .



before primary stop see the RFS status 



Step 3: Connect with DG Broker on Standby

Let's connect with DG Broker on the Standby machine using the following command and check the database configuration.

$dgmgrl sys/Welcome_123

DGMGRL> show configuration


In the above screenshot, you can see there is an error "ORA-1034: ORACLE not available" with the PRIMARY database.

Step 4: START FAILOVER

Perform failover using DG broker, use the below query:

DGMGRL> failover to prod;
failover to prod
After failover, now "prod" is the primary database.

DGMGRL> show configuration
show configuration
After failover, you can see the log sequence number is reset and started from 1, as you can check in the below screenshot.

archive log list
Reinstate the old Primary
Let's reinstate the old primary database using the below steps.

Step 5: Start the old Primary till mount
To perform reinstate start the old primary till mount stage.

$sqlplus / as sysdba
SQL> startup mount
start database till mount
After mounting check the database role.


reinstate the old Primary
As per the above screenshot, the STBY database role is PRIMARY. But in the Data Guard environment, we can maintain only one Primary, and right now the prod is our Primary database.

Step 6: Reinstate Database
Now, this is the time to reinstate the database using the following command.

DGMGRL> reinstate database STBY;
reinstate database STBY
Let's check the database configuration now.

DGMGRL> show configuration

DGMGRL> reinstate database STBY;
Reinstating database "stby", please wait...
Reinstatement of database "stby" succeeded



DGMGRL> show configuration

Configuration - prod

  Protection Mode: MaxPerformance
  Members:
  prod - Primary database
    stby - Physical standby database

Fast-Start Failover:  Disabled

Configuration Status:
SUCCESS   (status updated 14 seconds ago)

DGMGRL> show database stby;

Database - stby

  Role:               PHYSICAL STANDBY
  Intended State:     APPLY-ON
  Transport Lag:      0 seconds (computed 1 second ago)
  Apply Lag:          0 seconds (computed 1 second ago)
  Average Apply Rate: 6.00 KByte/s
  Real Time Query:    ON
  Instance(s):
    stby

Database Status:
SUCCESS

DGMGRL> show database prod;

Database - prod

  Role:               PRIMARY
  Intended State:     TRANSPORT-ON
  Instance(s):
    prod

Database Status:
SUCCESS

DGMGRL>

reinstate the old Primary
Now you can see the error is removed and the STBY database becomes a physical standby database.

SQL> select sequence#,process,status from v$managed_standby;

 SEQUENCE# PROCESS   STATUS
---------- --------- ------------
         0 ARCH      CONNECTED
         0 DGRD      ALLOCATED
         0 DGRD      ALLOCATED
         0 ARCH      CONNECTED
         1 ARCH      CLOSING
         0 ARCH      CONNECTED
         0 ARCH      CONNECTED
         2 RFS       IDLE
         0 RFS       IDLE
         2 MRP0      APPLYING_LOG

10 rows selected.


Primary Node :





Standby Node :






Thanks,
Srini