Beiträge getaggt mit 12c New Features
Fast-Start Failover for Maximum Protection in #Oracle 12c
Fast-Start Failover is supported with Maximum Protection in 12cR2. Also Multiple Observers can now monitor the same Data Guard Configuration simultaneously. I will show both in this article. Starting with a (Multitenant) Primary in Maximum Protection mode with two Standby Databases. It is still not recommended to have the highest protection mode configured with only one standby. So this is my starting point:
DGMGRL> show configuration; Configuration - myconf Protection Mode: MaxProtection Members: cdb1 - Primary database cdb1sb - Physical standby database cdb1sb2 - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS (status updated 57 seconds ago)
All three databases have flashback turned on. I want to have a setup like this in the end:

FSFO with Max Protection and 2 Observers
This is how it’s been configured:
DGMGRL> edit database cdb1 set property faststartfailovertarget='cdb1sb,cdb1sb2'; Property "faststartfailovertarget" updated DGMGRL> edit database cdb1sb set property faststartfailovertarget='cdb1,cdb1sb2'; Property "faststartfailovertarget" updated DGMGRL> edit database cdb1sb2 set property faststartfailovertarget='cdb1,cdb1sb'; Property "faststartfailovertarget" updated DGMGRL> enable fast_start failover; Enabled.
On host uhesse4:
[oracle@uhesse4 ~]$ dgmgrl sys/oracle@cdb1 DGMGRL for Linux: Release 12.2.0.1.0 - Production on Fri Jan 13 17:20:52 2017 Copyright (c) 1982, 2016, Oracle and/or its affiliates. All rights reserved. Welcome to DGMGRL, type "help" for information. Connected to "cdb1" Connected as SYSDBA. DGMGRL> start observer number_one; [W000 01/13 17:21:04.85] FSFO target standby is cdb1sb [W000 01/13 17:21:07.05] Observer trace level is set to USER [W000 01/13 17:21:07.05] Try to connect to the primary. [W000 01/13 17:21:07.05] Try to connect to the primary cdb1. [W000 01/13 17:21:07.05] The standby cdb1sb is ready to be a FSFO target [W000 01/13 17:21:09.06] Connection to the primary restored! [W000 01/13 17:21:13.07] Disconnecting from database cdb1.
On host uhesse3:
[oracle@uhesse3 ~]$ dgmgrl sys/oracle@cdb1 DGMGRL for Linux: Release 12.2.0.1.0 - Production on Fri Jan 13 17:22:16 2017 Copyright (c) 1982, 2016, Oracle and/or its affiliates. All rights reserved. Welcome to DGMGRL, type "help" for information. Connected to "cdb1" Connected as SYSDBA. DGMGRL> start observer number_two; [W000 01/13 17:22:32.68] FSFO target standby is cdb1sb [W000 01/13 17:22:34.85] Observer trace level is set to USER [W000 01/13 17:22:34.85] Try to connect to the primary. [W000 01/13 17:22:34.85] Try to connect to the primary cdb1. [W000 01/13 17:22:34.85] The standby cdb1sb is ready to be a FSFO target [W000 01/13 17:22:36.86] Connection to the primary restored! [W000 01/13 17:22:40.86] Disconnecting from database cdb1.
This is now the state of the configuration:
DGMGRL> show configuration; Configuration - myconf Protection Mode: MaxProtection Members: cdb1 - Primary database cdb1sb - (*) Physical standby database cdb1sb2 - Physical standby database Fast-Start Failover: ENABLED Configuration Status: SUCCESS (status updated 33 seconds ago) DGMGRL> show fast_start failover; Fast-Start Failover: ENABLED Threshold: 15 seconds Target: cdb1sb Candidate Targets: cdb1sb,cdb1sb2 Observers: (*) number_two number_one Lag Limit: 30 seconds (not in use) Shutdown Primary: TRUE Auto-reinstate: TRUE Observer Reconnect: (none) Observer Override: FALSE Configurable Failover Conditions Health Conditions: Corrupted Controlfile YES Corrupted Dictionary YES Inaccessible Logfile NO Stuck Archiver NO Datafile Write Errors YES Oracle Error Conditions: (none)
That protects against the failure of any two components in the configuration with automatic failover and zero data loss! For example the first standby may fail and then the primary. We failover to the second standby that becomes the new fast-start failover target:
[oracle@uhesse2 ~]$ ps -ef | grep smon oracle 15087 1 0 17:40 ? 00:00:00 ora_smon_cdb1sb oracle 15338 9765 0 17:49 pts/2 00:00:00 grep --color=auto smon [oracle@uhesse2 ~]$ kill -9 15087
Above crashed the first standby. This is what the Observers report:
[W000 01/13 17:49:34.24] Failed to ping the standby. [W000 01/13 17:49:37.25] Failed to ping the standby. [W000 01/13 17:49:40.25] Failed to ping the standby. [W000 01/13 17:49:43.25] Failed to ping the standby. [W000 01/13 17:49:46.26] Failed to ping the standby. [W000 01/13 17:49:46.26] Standby database has changed to cdb1sb2. [W000 01/13 17:49:47.26] Try to connect to the primary. [W000 01/13 17:49:47.26] Try to connect to the primary cdb1. [W000 01/13 17:49:48.34] The standby cdb1sb2 is ready to be a FSFO target [W000 01/13 17:49:53.35] Connection to the primary restored! [W000 01/13 17:49:57.35] Disconnecting from database cdb1.
This is the state of the configuration now:
DGMGRL> show configuration;
Configuration - myconf
Protection Mode: MaxProtection
Members:
cdb1 - Primary database
Error: ORA-16778: redo transport error for one or more members
cdb1sb2 - (*) Physical standby database
cdb1sb - Physical standby database
Error: ORA-1034: ORACLE not available
Fast-Start Failover: ENABLED
Configuration Status:
ERROR (status updated 14 seconds ago)
Notice that the Fast-Start Failover indicator (*) now points to cdb1sb2. Now the primary fails:
[oracle@uhesse1 ~]$ ps -ef | grep smon oracle 21334 1 0 17:41 ? 00:00:00 ora_smon_cdb1 oracle 22077 5043 0 17:52 pts/0 00:00:00 grep --color=auto smon [oracle@uhesse1 ~]$ kill -9 21334
This is what the Observers report:
[W000 01/13 17:52:54.04] Primary database cannot be reached.
[W000 01/13 17:52:54.04] Fast-Start Failover threshold has not exceeded. Retry for the next 15 seconds
[W000 01/13 17:52:55.05] Try to connect to the primary.
[W000 01/13 17:52:57.13] Primary database cannot be reached.
[W000 01/13 17:52:58.13] Try to connect to the primary.
[W000 01/13 17:53:06.38] Primary database cannot be reached.
[W000 01/13 17:53:06.38] Fast-Start Failover threshold has not exceeded. Retry for the next 3 seconds
[W000 01/13 17:53:07.39] Try to connect to the primary.
[W000 01/13 17:53:09.46] Primary database cannot be reached.
[W000 01/13 17:53:09.46] Fast-Start Failover threshold has expired.
[W000 01/13 17:53:09.46] Try to connect to the standby.
[W000 01/13 17:53:09.46] Making a last connection attempt to primary database before proceeding with Fast-Start Failover.
[W000 01/13 17:53:09.46] Check if the standby is ready for failover.
[S019 01/13 17:53:09.47] Fast-Start Failover started...
17:53:09.47 Friday, January 13, 2017
Initiating Fast-Start Failover to database "cdb1sb2"...
[S019 01/13 17:53:09.47] Initiating Fast-start Failover.
Performing failover NOW, please wait...
Failover succeeded, new primary is "cdb1sb2"
17:53:23.68 Friday, January 13, 2017
After having restarted the two crashed databases, they become automatically reinstated and the configuration then looks like this:
DGMGRL> show configuration;
Configuration - myconf
Protection Mode: MaxProtection
Members:
cdb1sb2 - Primary database
cdb1 - (*) Physical standby database
cdb1sb - Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS (status updated 7 seconds ago)
DGMGRL> show fast_start failover;
Fast-Start Failover: ENABLED
Threshold: 15 seconds
Target: cdb1
Candidate Targets: cdb1,cdb1sb
Observers: (*) number_two
number_one
Lag Limit: 30 seconds (not in use)
Shutdown Primary: TRUE
Auto-reinstate: TRUE
Observer Reconnect: (none)
Observer Override: FALSE
Configurable Failover Conditions
Health Conditions:
Corrupted Controlfile YES
Corrupted Dictionary YES
Inaccessible Logfile NO
Stuck Archiver NO
Datafile Write Errors YES
Oracle Error Conditions:
(none)
Switching back to make cdb1 primary – this is of course optional:
DGMGRL> switchover to cdb1;
Performing switchover NOW, please wait...
Operation requires a connection to database "cdb1"
Connecting ...
Connected to "cdb1"
Connected as SYSDBA.
New primary database "cdb1" is opening...
Operation requires start up of instance "cdb1sb2" on database "cdb1sb2"
Starting instance "cdb1sb2"...
ORACLE instance started.
Database mounted.
Connected to "cdb1sb2"
Switchover succeeded, new primary is "cdb1"
DGMGRL> show configuration;
Configuration - myconf
Protection Mode: MaxProtection
Members:
cdb1 - Primary database
cdb1sb - (*) Physical standby database
cdb1sb2 - Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS (status updated 29 seconds ago)
I think this enhancement is really a big deal!
Auto Sync for Password Files in #Oracle 12c Data Guard

A useful enhancement in 12cR2 is that password files are automatically synchronized in a Data Guard environment:
[oracle@uhesse1 ~]$ dgmgrl sys/oracle_4U@cdb1
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Tue Jan 10 07:38:15 2017
Copyright (c) 1982, 2016, Oracle and/or its affiliates. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected to "cdb1"
Connected as SYSDBA.
DGMGRL> show configuration;
Configuration - myconf
Protection Mode: MaxPerformance
Members:
cdb1 - Primary database
cdb1sb - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 31 seconds ago)
DGMGRL> exit
[oracle@uhesse1 ~]$ sqlplus sys/oracle_4U@cdb1 as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 10 07:38:49 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> alter user sys identified by oracle;
User altered.
SQL> connect sys/oracle@cdb1 as sysdba
Connected.
SQL> connect sys/oracle@cdb1sb as sysdba
Connected.
I have just changed the password of sys on the Primary and it got automatically also changed on the Standby. In earlier versions that had to be done manually, typically by replacing the password file on the standby with a new copy from the primary. One little thing less to keep in mind now 🙂
Real-Time Materialized Views in #Oracle 12c

In 12cR2, a Materialized View that is STALE can still speed up queries while delivering correct results. The data from the stale MV is then on the fly combined with the change information from MV logs in an operation called ON QUERY COMPUTATION. The result is delivered slightly slower as if the MV were FRESH, so there is some overhead involved in the process. But it should be noticeable faster than having to do Full Table Scans as it was required in versions before 12c in that situation.
Operationally, that means that REFRESH can be done less frequently while keeping satisfactory query performance all the time. Let’s see that in action:
[oracle@uhesse ~]$ sqlplus adam/adam@pdb1
SQL*Plus: Release 12.2.0.1.0 Production on Thu Jan 5 14:31:00 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Last Successful login time: Thu Jan 05 2017 10:57:35 +01:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> set timing on
SQL> select channel_id,sum(amount_sold) from sales group by channel_id;
CHANNEL_ID SUM(AMOUNT_SOLD)
---------- ----------------
1 4000000
2 4000000
4 4000000
3 4000000
0 4000000
Elapsed: 00:00:03.47
SQL> set timing off
The query takes more than three seconds without an MV initially.
SQL> create materialized view log on sales
with rowid, sequence(channel_id,amount_sold)
including new values;
Materialized view log created.
SQL> create materialized view mv1
refresh fast on demand
enable query rewrite
enable on query computation
as
select channel_id,
sum(amount_sold),
count(amount_sold),
count(*)
from sales
group by channel_id;
Materialized view created.
SQL> set timing on
SQL> select channel_id,sum(amount_sold) from sales group by channel_id;
CHANNEL_ID SUM(AMOUNT_SOLD)
---------- ----------------
1 4000000
2 4000000
4 4000000
3 4000000
0 4000000
Elapsed: 00:00:00.07
SQL> set timing off
The FRESH MV speeds up the query – not yet new. The same kind of execution plan would have been used in 11g:
SQL> @lastplan PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------- SQL_ID 9wwp2am6pm4dz, child number 1 ------------------------------------- select channel_id,sum(amount_sold) from sales group by channel_id Plan hash value: 2958490228 ------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 3 (100)| | | 1 | MAT_VIEW REWRITE ACCESS FULL| MV1 | 5 | 30 | 3 (0)| 00:00:01 | ------------------------------------------------------------------------------------- 13 rows selected.
Now I change something in the sales table, making the MV STALE:
SQL> update sales set amount_sold=2 where rownum<2;
1 row updated.
SQL> commit;
Commit complete.
SQL> select mview_name,staleness,on_query_computation from user_mviews;
MVIEW_NAME STALENESS O
---------- ------------------- -
MV1 NEEDS_COMPILE Y
In spite of the STALE MV, the next query is still fast, although not as fast as with the FRESH MV:
SQL> set timing on
SQL> select channel_id,sum(amount_sold) from sales group by channel_id;
CHANNEL_ID SUM(AMOUNT_SOLD)
---------- ----------------
2 4000000
3 4000000
4 4000000
0 4000000
1 4000001
Elapsed: 00:00:00.12
SQL> set timing off
So what happens is roughly this:

That there’s some work been done under the covers is revealed by looking at the (rather scary) execution plan now:
SQL> @lastplan
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------
SQL_ID 9wwp2am6pm4dz, child number 2
-------------------------------------
select channel_id,sum(amount_sold) from sales group by channel_id
Plan hash value: 2525395710
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 18 (100)| |
| 1 | VIEW | | 363 | 9438 | 18 (23)| 00:00:01 |
| 2 | UNION-ALL | | | | | |
|* 3 | VIEW | VW_FOJ_0 | 100 | 2900 | 7 (15)| 00:00:01 |
|* 4 | HASH JOIN FULL OUTER | | 100 | 4300 | 7 (15)| 00:00:01 |
| 5 | VIEW | | 5 | 160 | 3 (0)| 00:00:01 |
| 6 | MAT_VIEW ACCESS FULL | MV1 | 5 | 60 | 3 (0)| 00:00:01 |
| 7 | VIEW | | 100 | 1100 | 4 (25)| 00:00:01 |
| 8 | HASH GROUP BY | | | | 4 (25)| 00:00:01 |
|* 9 | TABLE ACCESS FULL | MLOG$_SALES | 2 | 74 | 3 (0)| 00:00:01 |
| 10 | VIEW | | 263 | 6838 | 11 (28)| 00:00:01 |
| 11 | UNION-ALL | | | | | |
|* 12 | FILTER | | | | | |
| 13 | NESTED LOOPS OUTER | | 250 | 16000 | 4 (25)| 00:00:01 |
| 14 | VIEW | | 100 | 5200 | 4 (25)| 00:00:01 |
|* 15 | FILTER | | | | | |
| 16 | HASH GROUP BY | | | | 4 (25)| 00:00:01 |
|* 17 | TABLE ACCESS FULL | MLOG$_SALES | 2 | 74 | 3 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | I_SNAP$_MV1 | 3 | 36 | 0 (0)| |
| 19 | MERGE JOIN | | 13 | 871 | 7 (29)| 00:00:01 |
| 20 | MAT_VIEW ACCESS BY INDEX ROWID| MV1 | 5 | 60 | 2 (0)| 00:00:01 |
| 21 | INDEX FULL SCAN | I_SNAP$_MV1 | 5 | | 1 (0)| 00:00:01 |
|* 22 | FILTER | | | | | |
|* 23 | SORT JOIN | | 100 | 5500 | 5 (40)| 00:00:01 |
| 24 | VIEW | | 100 | 5500 | 4 (25)| 00:00:01 |
| 25 | SORT GROUP BY | | | | 4 (25)| 00:00:01 |
|* 26 | TABLE ACCESS FULL | MLOG$_SALES | 2 | 74 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("AV$0"."OJ_MARK" IS NULL)
4 - access(SYS_OP_MAP_NONNULL("SNA$0"."CHANNEL_ID")=SYS_OP_MAP_NONNULL("AV$0"."GB0"))
9 - filter("MAS$"."SNAPTIME$$">TO_DATE(' 2017-01-05 14:32:07', 'syyyy-mm-dd hh24:mi:ss'))
12 - filter(CASE WHEN ROWID IS NOT NULL THEN 1 ELSE NULL END IS NULL)
15 - filter(SUM(DECODE(DECODE("MAS$"."OLD_NEW$$",'N','I','D'),'I',1,(-1)))>0)
17 - filter("MAS$"."SNAPTIME$$">TO_DATE(' 2017-01-05 14:32:07', 'syyyy-mm-dd hh24:mi:ss'))
18 - access("MV1"."SYS_NC00005$"=SYS_OP_MAP_NONNULL("AV$0"."GB0"))
22 - filter("MV1"."COUNT(*)"+"AV$0"."D0">0)
23 - access("MV1"."SYS_NC00005$"=SYS_OP_MAP_NONNULL("AV$0"."GB0"))
filter("MV1"."SYS_NC00005$"=SYS_OP_MAP_NONNULL("AV$0"."GB0"))
26 - filter("MAS$"."SNAPTIME$$">TO_DATE(' 2017-01-05 14:32:07', 'syyyy-mm-dd hh24:mi:ss'))
Note
-----
- dynamic statistics used: dynamic sampling (level=2)
60 rows selected.
But the query delivers the correct result – so that is not simply using the STALE MV only like QUERY_REWRITE_INTEGRITY=STALE_TOLERATED does. Just to confirm:
SQL> show parameter query_rewrite_integrity
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_integrity string enforced
Still REFRESH should be done from time to time like here:
SQL> exec dbms_mview.refresh('MV1','F')
PL/SQL procedure successfully completed.
SQL> set timing on
SQL> select channel_id,sum(amount_sold) from sales group by channel_id;
CHANNEL_ID SUM(AMOUNT_SOLD)
---------- ----------------
1 4000001
2 4000000
4 4000000
3 4000000
0 4000000
Elapsed: 00:00:00.06
Isn’t it nice that also the good old stuff gets enhanced instead of only the fancy new things like the In-Memory Option? At least I think so 🙂
Watch me on YouTube explaining and demonstrating the above:
