Friday, 16 August 2019

Restoring the failed member in MySQL InnoDB cluster with MySQL Enterprise Backup

Using MySQL Enterprise Backup to restore and rebuild the failed member in secondary node

Testing Environment:

Linux OS: CentOS 7.4
MySQL Server Version: 8.0
MySQL Enterprise Backup 8.0
MySQL Enterprise Transparent Encryption Encryption 
MySQL InnoDB cluster 8.0

Host: primary01 as primary node
Host: second02 as secondary node

A. Pre-Task: 

1. Taking Full-backup with Compression on secondary using MySQL Enterprise Backup

mysqlbackup --defaults-file=my.cnf --backup_image=/backup/mysqld/my.mbi_`date +%d%m_%H%M` --backup-dir=/backup/mysqld/backup_`date +%d%m_%H%M` --user=mysbackup -p --host=second02 --port=3306 --encrypt-password= --compress --compress-level=5  backup-to-image &>> `date +%d%m_%H%M`_full_compress_tde_mysqld_backup.log

2. check backup log with "completed" and please ignore the warning since the backup was taken on secondary node.

ySQL Enterprise Backup  Ver 8.0.15-commercial for linux-glibc2.12 on x86_64 (MySQL Enterprise - Commercial)
Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

190816 16:56:26 MAIN    INFO: A thread created with Id '140676524181376'
190816 16:56:26 MAIN    INFO: Starting with following command line ...
 mysqlbackup
        --defaults-file=my.cnf
        --backup_image=/backup/mysqld/my.mbi_1608_1656
        --backup-dir=/backup/mysqld/backup_1608_1656
        --user=mysbackup -pxxxxxxxxxxxx --host=second02 --port=3306
        --encrypt-password=xxxxxxxxxx --compress --compress-level=5
        backup-to-image

190816 16:56:26 MAIN    INFO:
190816 16:56:26 MAIN    INFO: No SSL options specified.
190816 16:56:26 MAIN    INFO: MySQL server version is '8.0.15-commercial'
190816 16:56:26 MAIN    INFO: MySQL server compile os version is 'linux-glibc2.12'
190816 16:56:26 MAIN    INFO: SSL/TLS version used for connection is TLSv1.2
190816 16:56:26 MAIN WARNING: This backup operation cannot write to backup progress. The MySQL server is running with the --super-read-only option.
....
mysqlbackup completed OK! with 1 warnings

B. Task: Restore the backup on secondary node
1.Stop MySQL server
mysql -u mysql -p password  -hsecond02 -P3306 -e "shutdown"

2. remove all data files under mysql database data directory
rm -rf /data/mysqld
mkdir -p /data/mysqld

3. remove all log files and the keyring files 
rm -rf /data/mysql-keyring
mkdir -p /data/mysql-keyring
rm -rf /data/log
mkdir -p /data/log

4. create restore directory
mkdir -p /backup/mysqld/restore

5. restore backup 
mysqlbackup --defaults-file=/my.cnf --backup-image=/backup/mysqld/ --backup-dir=/backup/mysqld/restore --datadir=/data/mysqld --user=mysbackup -p password  --host=second02 --port=3306 --encrypt-password= encryption_password  --uncompress copy-back-and-apply-log &>> `date +%d%m_%H%M`_full_compress_tde_mysqld_restore.log

C. Post-Task: Re-join as a New Member in MySQL InnoDB cluster
1. Start restored MySQL Server
mysqld_safe --defaults-file=my.cnf &

2. Reset group replication member status
mysql -u mysql -p password -hsecond02 -P3306
mysql> RESET MASTER;
mysql> RESET SLAVE ALL;


*Remark: please follow the below steps if enabled auto recover using group replication's built-in mechanism with the variable "gtid_executed
//start

mysql> SET sql_log_bin=off;
mysql> source /data/mysqld/backup_gtid_executed.sql
mysql> SET sql_log_bin=on;

//end

3. Re-join the restored server in MySQL InnoDB cluster
mysqlsh --uri=mysql:password @primary01:3306

MySQL  primary01:3306 ssl  JS > var x = dba.getCluster();
MySQL  primary01:3306 ssl  JS > x.rescan();
Rescanning the cluster...

Result of the rescanning operation for the 'default' ReplicaSet:
{
    "name": "default", 
    "newTopologyMode": null, 
    "newlyDiscoveredInstances": [], 
    "unavailableInstances": [
        {
            "host": "second02:3306", 
            "label": "second02:3306", 
            "member_id": "4e1eff7d-bf22-11e9-93f4-080027ea2dcf"
        }
    ]
}

The instance 'second02:3306' is no longer part of the ReplicaSet.
The instance is either offline or left the HA group. You can try to add it to the cluster again with the cluster.rejoinInstance('second02:3306') command or you can remove it from the cluster configuration.
Would you like to remove it from the cluster metadata? [Y/n]: y 
Removing instance from the cluster metadata...
The instance 'second02:3306' was successfully removed from the cluster metadata.

MySQL  primary01:3306 ssl  JS > dba.checkInstanceConfiguration('group_replication_user:group_replication_password@second02:3306');
MySQL  primary01:3306 ssl  JS > dba.configureInstance('mysadm:mysadm43d@second02:3306', {clusterAdmin:'group_replication_user',clusterAdminPassword:'group_replication_password'});
dba.checkInstanceConfiguration('group_replication_user:group_replication_password@second02:3306');
MySQL  primary01:3306 ssl  JS > x.status();
MySQL  primary01:3306 ssl  JS >x.addInstance('group_replication_user:group_replication_password>@second02:3306');
MySQL  primary01:3306 ssl  JS > x.status();
{
    "clusterName": "CC_CLU01", 
    "defaultReplicaSet": {
        "name": "default", 
        "primary": "primary01:3306", 
        "ssl": "REQUIRED", 
        "status": "OK_NO_TOLERANCE", 
        "statusText": "Cluster is NOT tolerant to any failures.", 
        "topology": {
            "primary01:3310": {
                "address": "primary01:3306", 
                "mode": "R/W", 
                "readReplicas": {}, 
                "role": "HA", 
                "status": "ONLINE"
            }, 
            "second02:3310": {
                "address": "second02:3306", 
                "mode": "R/O", 
                "readReplicas": {}, 
                "role": "HA", 
                "status": "ONLINE"
            }
        }, 
        "topologyMode": "Single-Primary"
    }, 
    "groupInformationSourceMember": "primary01:3306"
}


3. check member status after re-join the restored server in MySQL InnoDB cluster
mysql -u mysql -p password  -hsecond02 -P3306
mysql> SELECT member_host, member_port, member_state FROM performance_schema.replication_group_members;
+-------------+-------------+--------------+
| member_host | member_port | member_state |
+-------------+-------------+--------------+
| primary01   |        3306 | ONLINE       |
| second02    |        3306 | ONLINE       |
+-------------+-------------+--------------+
2 rows in set (0.00 sec)

mysql> 






Monday, 18 March 2019

Resolve ORA-01034 and ORA-27101

Got error message "ORA-01034" & "ORA-27101" when connect the database with "@", this issue may caused by the listener service is not started well.
I tried to stop and start again the listener, the issue has been resolved.


1. Please check ORACLE_SID
2. Please check listener.ora configuration
3. Please try to restart the listener service 

Here is the example:
Got error message when connect to the database with  TNS name "@"

[oracle@primary01 ~]$ sqlplus 'sysbackup/abc123@testdgbdr as sysbackup'

SQL*Plus: Release 12.1.0.2.0 Production on Mon Mar 18 18:09:19 2019

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> show user
USER is "SYSBACKUP"
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
Process ID: 0
Session ID: 0 Serial number: 0


SQL>exit

Try to startup the DB instance as sysdba
[oracle@primary01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Mon Mar 18 18:10:24 2019

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 2097152000 bytes
Fixed Size                  2999888 bytes
Variable Size            1207962032 bytes
Database Buffers          872415232 bytes
Redo Buffers               13774848 bytes
Database mounted.
Database opened.
SQL> show parameter local_listener

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
local_listener                       string      LISTENER_testdgbdr
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

Check the listener service status 
[oracle@primary01 ~]$ lsnrctl status p01lsnr1521

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 18-MAR-2019 18:01:15

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=primary01)(PORT=1528)))
STATUS of the LISTENER
------------------------
Alias                     p01lsnr1521
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                19-JAN-2019 16:59:55
Uptime                    28 days 0 hr. 3 min. 20 sec
Trace Level               off
Security                  OFF
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/primary01/p01lsnr1521/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=primary01)(PORT=1528)))
Services Summary...
Service "testdgbdr" has 2 instance(s).
  Instance "testdgbdr", status UNKNOWN, has 1 handler(s) for this service...
  Instance "testdgbdr", status READY, has 1 handler(s) for this service...
Service "testdgbdrXDB" has 1 instance(s).
  Instance "testdgbdr", status READY, has 1 handler(s) for this service...

Try to stop the listener service 

[oracle@primary01 ~]$ lsnrctl stop p01lsnr1521

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 18-MAR-2019 18:17:49

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=primary01)(PORT=1521)))
The command completed successfully

Start the listener again.

[oracle@primary01 ~]$ lsnrctl start p01lsnr1521
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 18-MAR-2019 18:01:15

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=primary01)(PORT=1528)))
STATUS of the LISTENER
------------------------
Alias                     p01lsnr1521
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                18-MAR-2019 18:17:55
Uptime                    28 days 0 hr. 3 min. 20 sec
Trace Level               off
Security                  OFF
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/primary01/p01lsnr1521/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=primary01)(PORT=1528)))
Services Summary...
Service "testdgbdr" has 2 instance(s).
  Instance "testdgbdr", status UNKNOWN, has 1 handler(s) for this service...
  Instance "testdgbdr", status READY, has 1 handler(s) for this service...
Service "testdgbdrXDB" has 1 instance(s).
  Instance "testdgbdr", status READY, has 1 handler(s) for this service...

Try to connect to the database with @, to stop and start the DB instance.
The issue has been resolved after restarted the listener, to stop the database instance without error ORA-01034 & ORA-27101

[oracle@primary01 ~]$ sqlplus 'sysbackup/abc123@testdgbdr as sysbackup'
The command completed successfully
SQL*Plus: Release 12.1.0.2.0 Production on Mon Mar 18 18:19:59 2019

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

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

Total System Global Area 2097152000 bytes
Fixed Size                  2999888 bytes
Variable Size            1207962032 bytes
Database Buffers          872415232 bytes
Redo Buffers               13774848 bytes
Database mounted.
Database opened.
SQL> exit

Friday, 1 September 2017

Got error ORA-31625 and ORA-01031 insufficient privileges using data pump utility (expdp/impdp) under database vault environment

How authorise your database administrator using data pump utility to export and import data under database vault environment (DBV)?

Basically, DBA is not allowed to export and import data under database vault environment even you have granted EXP_FULL_DATABASE or IMP_FULL_DATABASE role. And must be got the error message with ORA-31625 and ORA-01031 when using data pump utility to export and import data under DBV environment.

Here show the example that allow the system user to using data pump utility, for details please refer to the oracle database vault administration online document.

A. To authorise the user using data pump utility to export and import all schema data.

For #1 and #2 , kindly please login as SYS
#1. Grant BECOME USER, EXP_FULL_DATABASE and IMP_FULL_DATABASE role  
    
      GRANT BECOME USER TO SYSTEM;
      GRANT EXP_FULL_DATABASE TO SYSTEM;
      GRANT IMP_FULL_DATABASE TO SYSTEM;

#2. verify the above roles are granted to the user
       
       SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE='SYSTEM'
       AND GRANTED_ROLE IN ('BECOME USER','EXP_FULL_DATABASE','IMP_FULL_DATABASE'); 


For #3, kindly please login as database vault owner
#3. authorise system using data pump utility
      EXEC DBMS_MACADM.AUTHORIZE_DATAPUMP_USER('SYSTEM');

#4. verify the privileges
      SELECT * FROM DVSYS.DBA_DV_DATAPUMP_AUTH WHERE GRANTEE = 'SYSTEM';


B. Revoke the privileges and the role are granted to authorise user using data pump utility to export and import all schema data.

 For #1 and #2 , kindly please login as SYS
#1. Revoke BECOME USER, EXP_FULL_DATABASE and IMP_FULL_DATABASE role  
    
      REVOKE BECOME USER FROM SYSTEM;
      REVOKE EXP_FULL_DATABASE FROM SYSTEM;
      REVOKE IMP_FULL_DATABASE FROM SYSTEM;

#2. verify the above roles are granted to the user
       
       SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE='SYSTEM'
       AND GRANTED_ROLE IN ('BECOME USER','EXP_FULL_DATABASE','IMP_FULL_DATABASE'); 


For #3, kindly please login as database vault owner
#3. authorise system using data pump utility
      EXEC DBMS_MACADM.UNAUTHORIZE_DATAPUMP_USER('SYSTEM');

#4. verify the privileges
      SELECT * FROM DVSYS.DBA_DV_DATAPUMP_AUTH WHERE GRANTEE = 'SYSTEM';  
      
Reference:

Monday, 22 August 2016

How to export/import the database data

In here, I will show you the basic steps for export/import the data from oracle database 11g.

Please note that the output of the export (expdp) and import (impdp) utilities are not compatible with the original Export(exp) and Import(imp).

For details, please refer to the oracle online document:
https://docs.oracle.com/cd/E18283_01/server.112/e17222/expimp.htm#i262247


Remark
To ensure the data exported from the right database instance, please set the ORACLE_SID before you execute the script for export/import.

export ORACLE_SID=dummydb;


A. Sample scripts for the Original Export (exp) and Import (imp) utilities (Compatible with 9i or before).

Export(exp) Utility - export data with specified table:

EXP [USER] TABLES=[TABLE_NAME] FILE=[DUMP_FILE] LOG=[LOG_FILE] FULL=[Y/N] ROWS=[Y/N]

E.g
EXP HR TABLES=EMPLOYEES FILE=exp_hr_employees.dmp log=exp_hr_employees.log full=n rows=y
Import(imp) Utility - Import Data with specified table

IMP [USER] FILE=[EXP_DUMP_FILE_NAME] IGNORE=[Y/N] FROMUSER=[EXPORT_SOURCE_USER] TOUSER=[IMPORT_TARGET_USER] LOG=[LOG_NAME] TABLES=[TABLE_NAME] ROWS=[Y/N] COMMIT=[Y/N]

E.g
IMP SCOTT FILE=exp_hr_employees.dmp IGNORE=Y FROMUSER=HR TOUSER=SCOTT log=imp_hr_employees.log TABLES=EMPLOYEES ROWS=y COMMIT=Y


B. Sample scripts for the Data Pump Utilities (Compatible with 10g or above).

As data dump utility which required to create the directory object on database when perform export/import data process.

The directory object is only a pointer to a physical directory and it does not actually create the physical directory on the file system of the database.So, if the location is changed , we also need update the path in database side.

The directory objects may require to create by DBA if you without sys privilege “CREATE DIRECTORY” on database.

Also, it required the privileges for database user who want to export/import other user data on database.

1. Export Utility

Reference: http://docs.oracle.com/cd/E11882_01/server.112/e22490/dp_export.htm#SUTIL200

1.1 Export specify table data only

EXPDP [USER] DIRECTORY=[DIRECTORY_OBJECT_NAME] TABLES=[TABLE_NAME] DUMPFILE=[DUMP_FILE] LOGFILE=[LOG_FILE_NAME]
E.g
EXPDP HR DIRECOTRY=DATA_EXP_IMP TABLES=TABLE_A DUMPFILE=impstestexp.dmp LOGFILE=action.log

1.2 Full Export

EXPDP [USER] DIRECTORY=[DIRECTORY_OBJECT_NAME] DUMPFILE=[DUMP_FILE] LOGFILE=[LOG_FILE_NAME]
E.g
EXPDP HR DIRECOTRY=DATA_EXP_IMP DUMPFILE=impstestexp.dmp LOGFILE=action.log

1.3 Full Export with specified schema user

EXPDP [USER] DIRECTORY=[DIRECTORY_OBJECT_NAME] DUMPFILE=[DUMP_FILE] LOGFILE=[LOG_FILE_NAME] SCHEMA=[SCHEMA_NAME]
E.g
EXPDP SYSTEM DIRECOTRY=DATA_EXP_IMP DUMPFILE=impstestexp.dmp LOGFILE=action.log SCHEMA=HR
2. Import Utility

Reference: http://docs.oracle.com/cd/E11882_01/server.112/e22490/dp_import.htm#SUTIL300
IMPDP [USER_NAME] DIRECTORY=[DIRETORY_OBJECT_NAME] REMAP_SCHEMA=[EXPORT_SOURCE_USER]:[IMPORT_TARGET_USER] DUMPFILE=[EXPORT_DUMP_FILE] LOGFILE=[LOG_FILE_NAME]
E.g
IMPDP SCOTT DIRECOTRY=DATA_EXP_IMP REMAP_SCHEMA=HR:SCOTT DUMPFILE=impstestexp.dmp LOGFILE=action.log 

Thursday, 21 July 2016

Gather the statistic of Archive log generation by hour

Use the following SQL to gather the statistic of archive log generation by hour, this information could help to you to monitor the database instance which hour is most frequency change the data in a day.


SQL> select
  2  to_char( a.COMPLETION_TIME, 'dd-mm-yyyy')as generation_date,
  3  to_char( a.COMPLETION_TIME, 'hh24')||':00' as start_time,
  4   round(sum(a.BLOCKS * a.BLOCK_SIZE)/1048576, 0) as Total_size_in_MB,
  5   count(a.recid) as no_of_archived_log
  6   from v$archived_log a
  7   group by to_char( a.COMPLETION_TIME, 'dd-mm-yyyy'),  to_char( a.COMPLETION_TIME, 'hh24')
  8   order by 1, 2, 3 desc, 4 desc;

GENERATION START TOTAL_SIZE_IN_MB NO_OF_ARCHIVED_LOG
---------- ----- ---------------- ------------------
01-07-2016 04:00               66                  2
01-07-2016 09:00               64                  2
01-07-2016 14:00               64                  2
01-07-2016 19:00               64                  2
01-07-2016 22:00               96                  2
02-07-2016 02:00               64                  2
02-07-2016 06:00               81                  2
02-07-2016 09:00               64                  2
02-07-2016 11:00               66                  2
02-07-2016 14:00               74                  2
02-07-2016 18:00               68                  2

Wednesday, 20 July 2016

Got security error with "Security token does not match. You must be login again..." on 12c EM express

When you login as system on 12c EM Express, you may got the following errors after login.


Basically, this error may happened on you haven't privilege to use EM Express, therefore, you should grant "EM_EXPRESS_BASIC" or "EM_EXPRESS_ALL" role to the specified user. 

In general, "EM_EXPRESS_BASIC" has been granted to "EM_EXPRESS_ALL" by default and the DBA role include "EM_EXPRESS_ALL".  

"EM_EXPRESS_ALL" grants a user all privileges required to perform any action in EM Express.


SQL> column grantee format a20
SQL> select grantee, granted_role from dba_role_privs where granted_role = 'EM_EXPRESS_ALL';

GRANTEE         GRANTED_ROLE
-------------------- --------------
DBA     EM_EXPRESS_ALL
SYS     EM_EXPRESS_ALL

SQL> GRANT EM_EXPRESS_ALL TO SYSTEM;

Grant succeeded.

SQL> select grantee, granted_role from dba_role_privs where granted_role = 'EM_EXPRESS_ALL';

GRANTEE         GRANTED_ROLE
-------------------- --------------
SYSTEM         EM_EXPRESS_ALL
DBA     EM_EXPRESS_ALL
SYS     EM_EXPRESS_ALL

SQL> 



After that, when you login again as system on EM Express, you can successfully to view the database instance performance. If you still got the security errors, please try use another browsers.


Reference:


"ORA-600 [3020]" / "ORA-16472" Perform failover after restore standby backup on standby site

If you got the error with "ORA-600 [3020]" or "ORA-16472" after performed failover on target standby database, you can try to perform a data-loss failover on target standby database.

As refer to the oracle document, this error is caused by the database configured the protection mode with "MaxAvailability" or "MaxPerformance" , data loss is detected during failover process.

For solve this issue, you can change the database protection mode to "Max Performance" before failover operation on target standby database or perform a data-loss failover on target standby database.

Here is the example:

Background:
1. The original protection mode of database is configured with "Max Availability".
2. The database is configured in physical standby database.
3. Oracle 12c Database on Oracle Linux
4. Both way are restored from same backup with applied the latest archive log, for plan A is unnecessary to perform a data-loss failover on target standby database.

A. Perform failover after changed the protection mode

RMAN> recover database;

Starting recover at 02-DEC-15
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=56
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=57
channel ORA_DISK_1: reading from backup piece /data_02/rman_disk/a_3045506482_20151202_151
channel ORA_DISK_1: piece handle=/data_02/rman_disk/a_3045506482_20151202_151 tag=TAG20151202T120618
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/arch/testdgbdr/1_56_896806709.dbf thread=1 sequence=56
archived log file name=/u01/app/arch/testdgbdr/1_57_896806709.dbf thread=1 sequence=57
media recovery complete, elapsed time: 00:00:02
Finished recover at 02-DEC-15

RMAN> alter database set standby database to maximize performance;

Statement processed

RMAN> exit


Recovery Manager complete.
[oracle@standby02 rman_disk]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed Dec 2 17:22:25 2015

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select db_unique_name, protection_mode from v$database;

DB_UNIQUE_NAME       PROTECTION_MODE
------------------------------ --------------------
testdgbdr       MAXIMUM PERFORMANCE

SQL> alter database failover to testdgbdr;

Database altered.

SQL> select db_unique_name, database_role, protection_mode from v$database;

DB_UNIQUE_NAME       DATABASE_ROLE PROTECTION_MODE
------------------------------ ---------------- --------------------
testdgbdr       PRIMARY MAXIMUM PERFORMANCE

SQL> exit

Also, you can perform manual failover using DGMGRL (i.e. DG Broker).

DGMGRL> FAILOVER TO testdgdbr;


B. Perform failover without change the protection mode

RMAN> recover database;

Starting recover at 02-DEC-15
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=56
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=57
channel ORA_DISK_1: reading from backup piece /data_02/rman_disk/a_3045506482_20151202_151
channel ORA_DISK_1: piece handle=/data_02/rman_disk/a_3045506482_20151202_151 tag=TAG20151202T120618
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/arch/testdgbdr/1_56_896806709.dbf thread=1 sequence=56
archived log file name=/u01/app/arch/testdgbdr/1_57_896806709.dbf thread=1 sequence=57
media recovery complete, elapsed time: 00:00:03
Finished recover at 02-DEC-15

RMAN> exit


Recovery Manager complete.
[oracle@standby02 rman_disk]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed Dec 2 17:34:11 2015

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select db_unique_name, database_role, protection_mode from v$database;

DB_UNIQUE_NAME       DATABASE_ROLE PROTECTION_MODE
------------------------------ ---------------- --------------------
testdgbdr       PHYSICAL STANDBY MAXIMUM AVAILABILITY

SQL> alter database failover to testdgbdr;
alter database failover to testdgbdr
*
ERROR at line 1:
ORA-16472: failover failed due to data loss

SQL> alter database activate physical standby database;

Database altered.

SQL> exit

Also, you can perform manual failover using DGMGRL (i.e. DG Broker).

DGMGRL> FAILOVER TO testdgdbr immediate;

Reference:
https://docs.oracle.com/database/121/SBYDB/role_management.htm#SBYDB4773
https://docs.oracle.com/database/121/DGBKR/sofo.htm#DGBKR370