How to Test an Oracle Database Upgrade using a Physical Standby

Posted in: Oracle, Technical Track

It was a Thursday morning. I started my day at work and found out that I was tasked with running a test upgrade to 11.2.0.4 right on Friday. This is just to make clear that I did not have much time for planning and testing and that there may be better options to complete this task, but this is the way I found to work.

Let’s start with the setup. This is a 11.2.0.3 single instance database with two physical standbys managed with Data Guard (DG). To add a bit of salt to the mix, Fast-Start Failover (FSFO) is enabled. Let’s call these our new database friends, A (the primary), B (one physical standby) and C (the other physical standby). There is a fourth partner in the party: the DG Observer. This is part of the FSFO architecture and is a process running, ideally, out of a server that is not hosting any of the databases.

The idea of the test was to remove B from the DG setup, upgrade it to 11.2.0.4, downgrade to 11.2.0.3 and then put it back in the mix. Easily said, not so easy to accomplish.

This blog post is a simplification of the whole process, straight to the point and only showing possible caveats if someone faces a requirement like this one in the future, myself included.

The plan

So, the Pythian machinery started to work. Yes we are good, not only because we are individually good, but also because we collaborate internally to make things even better, hence “the machinery” term I’ve just coined.

I started with a basic plan:

  • Changed the failover target in Data Guard to point to C
  • Disable B physical standby in the Data Guard configuration
  • Create a guaranteed restore point on B
  • Activate the physical standby
  • Upgrade to 11.2.0.4
  • Downgrade to 11.2.0.3
  • Flashback the database
  • Enable it back into the Data Guard configuration
  • Go get some rest

Get to the point

First things first, and this is a lesson I’ve learned the hard way: always use TNS to connect to Data Guard CLI dgmgrl. Why? Because most of the time you will be changing things or reviewing stuff, but when it comes to executing a switchover operation, a bequeath connection fails to connect to the database that goes down and the operation fails.

Now, I start by changing the FSFO target, initially pointing to B, to point to C database. This requires temporarily disabling FSFO or facing the following error:

1
Error: ORA-16654: fast-START failover IS enabled

So, we disable FSFO, change the database configuration and enable FSFO back:

1
2
3
4
5
6
DGMGRL> disable fast_start failover;
Disabled.
DGMGRL>  edit DATABASE 'A' SET property 'FastStartFailoverTarget' = 'C';
Property "FastStartFailoverTarget" updated
DGMGRL> enable fast_start failover;
Error: ORA-16651: requirements NOT met FOR enabling fast-START failover

Oops!! What happened here?  A quick review of the MOS document “Data Guard Broker – Configure Fast Start Failover, Data Protection Levels and the Data Guard Observer (Doc ID 1508729.1)” showed me that the LogXPTMode of the C database was set to ASYNC, while it is required to be SYNC for the database to be eligible as a FSFO target. Let’s do it then:

1
2
3
4
5
6
7
8
DGMGRL> edit DATABASE C SET property 'LogXptMode' = 'SYNC';
Property "LogXptMode" updated
DGMGRL> disable fast_start failover;
Disabled.
DGMGRL> edit DATABASE 'A' SET property 'FastStartFailoverTarget' = 'C';
Property "FastStartFailoverTarget" updated
DGMGRL>  enable fast_start failover;
Enabled.

Right, the first step completed. I will now send some archived logs to the standby databases, just to make sure that everything is up to date before I disable the B database.

And here comes another piece of advice: Enable the time and the timing in SQL*Plus wherever you are working. It will give more sense to your notes and you can easily track back your work in case something goes wrong. Yes, I learned this one the hard way, too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sys@A> SET TIME ON timing ON
01:38:01 sys@A> ALTER system archive log CURRENT;
 
System altered.
 
Elapsed: 00:00:00.29
01:38:13 sys@A> ALTER system archive log CURRENT;
 
System altered.
 
Elapsed: 00:00:00.92
01:38:14 sys@A> ALTER system archive log CURRENT;
 
System altered.
 
Elapsed: 00:00:01.19
01:38:15 sys@A> ALTER system checkpoint;
 
System altered.
 
Elapsed: 00:00:00.18

And now I modify the DG configuration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
oracle@serverA> dgmgrl
DGMGRL FOR Linux: Version 11.2.0.3.0 - 64bit Production
 
Copyright (c) 2000, 2009, Oracle. ALL rights reserved.
 
Welcome TO DGMGRL, TYPE "help" FOR information.
DGMGRL> CONNECT sys@A
Password:
Connected.
DGMGRL> SHOW DATABASE 'B';
 
DATABASE - B
 
ROLE: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds
Apply Lag: 0 seconds
REAL TIME Query: OFF
Instance(s):
B
 
DATABASE STATUS:
SUCCESS
 
DGMGRL> EDIT DATABASE 'B' SET STATE='APPLY-OFF';
Succeeded.
DGMGRL> disable DATABASE 'B';
Disabled.
DGMGRL> SHOW configuration
 
Configuration - fsfo_A
 
Protection Mode: MaxAvailability
DATABASES:
A - PRIMARY DATABASE
C - (*) Physical standby DATABASE
Error: ORA-16820: fast-START failover observer IS no longer observing this DATABASE 
B - Physical standby DATABASE (disabled)
 
Fast-START Failover: ENABLED
 
Configuration STATUS:
ERROR

Wait, what? Another problem? This one was harder to spot. It turned out to be a problem with the Observer. It was unable to connect to the C database due to lack of proper credentials. An “ORA-01031: insufficient privileges” was the tip in the log file. Simply adding the credentials to the Oracle Wallet in use by the Observer fixed the issue, as I was able to verify from the very same connection:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
oracle@observer> mkstore -wrl /home/oracle/wallet/.private -createCredential C sys ************
Oracle Secret Store Tool : Version 11.2.0.3.0 - Production
Copyright (c) 2004, 2011, Oracle AND/OR its affiliates. ALL rights reserved.
 
Enter wallet password:
CREATE credential oracle.security.client.connect_string7
 
oracle@observer> dgmgrl  /@C (This IS NOT a bequeath connection ;) )
DGMGRL FOR Linux: Version 11.2.0.3.0 - 64bit Production
 
Copyright (c) 2000, 2009, Oracle. ALL rights reserved.
 
Welcome TO DGMGRL, TYPE "help" FOR information.
Connected.
 
 
DGMGRL> disable fast_start failover
Disabled.
DGMGRL> enable fast_start failover
Enabled.
DGMGRL> SHOW configuration verbose;
 
Configuration - fsfo_A
 
Protection Mode: MaxAvailability
DATABASES:
A - PRIMARY DATABASE
C - (*) Physical standby DATABASE
B - Physical standby DATABASE (disabled)
 
(*) Fast-START Failover target
 
Properties:
FastStartFailoverThreshold = '30'
OperationTimeout = '30'
FastStartFailoverLagLimit = '30'
CommunicationTimeout = '180'
FastStartFailoverAutoReinstate = 'TRUE'
FastStartFailoverPmyShutdown = 'TRUE'
BystandersFollowRoleChange = 'ALL'
 
Fast-START Failover: ENABLED
 
Threshold: 30 seconds
Target: C
Observer: observer
Lag LIMIT: 30 seconds (NOT IN USE)
Shutdown PRIMARY: TRUE
Auto-reinstate: TRUE
 
Configuration STATUS:
SUCCESS
 
DGMGRL> exit

At this point, we have B out of the Data Guard equation and can proceed with the upgrade/downgrade part.

Upgrade to 11.2.0.4 and downgrade to 11.2.03

In order to run the test, I have to activate the standby database, so I can open it as a primary and execute the upgrade/downgrade process. This is why I removed it from the DG configuration as a first step:to avoid facing serious trouble with two primary databases enabled.

So I start by creating a Guaranteed Restore Point (GRP) to easily revert the database back to its standby role. In order to be able to create the GRP, the redo apply must be stopped, which I did already.

1
2
3
2:53:48 sys@B> CREATE RESTORE POINT BEFORE_UPGRADE_11204 GUARANTEE FLASHBACK DATABASE;
 
Restore point created.

Now that the GRP has been created, I activate the standby and proceed with the tests. The DG broker process on the database must be stopped to avoid conflicts with the DG configuration. I also cleaned the log_archive_config init parameter to be sure that nothing is getting out of this database.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
02:54:00 sys@B> ALTER system SET dg_broker_start=FALSE scope=spfile;
 
System altered.
 
Elapsed: 00:00:00.04
 
02:54:24 sys@B> ALTER system SET log_archive_config='' scope=BOTH;
 
System altered.
 
Elapsed: 00:00:00.05
02:54:41 sys@B> shut immediate;
ORA-01109: DATABASE NOT OPEN
 
DATABASE dismounted.
ORACLE instance shut down.
 
02:55:01 sys@B> startup mount;
 
ORACLE instance started.
 
Total System Global Area 8551575552 bytes
Fixed SIZE 2245480 bytes
Variable SIZE 3607104664 bytes
DATABASE Buffers 4932501504 bytes
Redo Buffers 9723904 bytes
DATABASE mounted.
 
02:56:25 sys@B> ALTER DATABASE activate standby DATABASE;
 
DATABASE altered.
 
Elapsed: 00:00:00.58
02:56:31 sys@B> ALTER DATABASE OPEN;
 
DATABASE altered.

It is time to upgrade and downgrade the database now. There is plenty of documentation about the process and I encountered no issues, so there is nothing about the process worth including here.

I’ll post the script I used to run the catupgrd.sql script just in case it is useful to someone in the future. As you know, this script modifies the data dictionary to adjust it to the new version. Depending on the gap between versions and the size of the data dictionary, this script may run for quite a long time. Join this with the risk of a remote session going down over VPN or similar stuff, and you will want to make sure that your database session is still there when you come back.

There are tools like screen or tmux but they may not be available or usable, so I usually rely on nohup and a simple bash script.

This particular version is to be run after loading the proper Oracle environment variables with oraenv, but you can easily modify it to include this step if you want to schedule the script with cron or similar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
 
sqlplus >> EOF
conn / AS sysdba
SET TIME ON timing ON trimspool ON pages 999 LINES 300
ALTER SESSION SET nls_date_format='dd-mm-yyyy hh24:mi:ss';
 
spool /covisint/USER/a_catbpd/11204Upgrade/upgrade_dryrun_output.log
@$ORACLE_HOME/rdbms/admin/catupgrd.sql
spool off;
 
exit
 
EOF

Once the script is ready, and with execution permissions, simply run it in nohup mode with some logging in place:

1
nohup run_upgrade.sh > run_upgrade_`date "+%F_%H-%M"`.log 2>&1 &

The same script can be used to run catdwgrd.sql and catrelod.sql scripts for the downgrade by simply changing the relevant lines.

Back to the start point

After the upgrade and downgrade tests are successfully completed, it is time to bring everything back to what it looked like when we started this exercise.

The very first step is to flashback the B standby database to the GRP I created before.

This is done still using the 11.2.0.4 binaries.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
05:03:19 sys@B> flashback DATABASE TO restore point before_upgrade_11204;
 
Flashback complete.
 
Elapsed: 00:00:09.92
05:03:34 sys@B> ALTER DATABASE CONVERT TO physical standby;
 
DATABASE altered.
 
Elapsed: 00:00:00.39
05:04:06 sys@B> shutdown immediate
ORA-01507: DATABASE NOT mounted
 
 
ORACLE instance shut down.

After the flashback is complete, we mount the database again but now with the 11.2.0.3 binaries and start the DG broker process

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
05:05:22 > startup nomount
ORACLE instance started.
 
Total System Global Area 8551575552 bytes
Fixed SIZE 2245480 bytes
Variable SIZE 1358957720 bytes
DATABASE Buffers 7180648448 bytes
Redo Buffers 9723904 bytes
05:05:30 > ALTER system SET dg_broker_start=TRUE scope=BOTH;
 
System altered.
 
Elapsed: 00:00:00.01
05:05:38 > ALTER DATABASE mount standby DATABASE;
 
DATABASE altered.
 
Elapsed: 00:00:05.25
 
Once the DATABASE IS back up AND ready TO apply redo, I can enable it back IN the DG configuration:
 
oracle@serverA> dgmgrl
DGMGRL FOR Linux: Version 11.2.0.3.0 - 64bit Production
 
Copyright (c) 2000, 2009, Oracle. ALL rights reserved.
 
Welcome TO DGMGRL, TYPE "help" FOR information.
DGMGRL> CONNECT sys@A
Password:
Connected.
DGMGRL> SHOW configuration
 
Configuration - fsfo_A
 
Protection Mode: MaxAvailability
DATABASES:
A - PRIMARY DATABASE
C - (*) Physical standby DATABASE
B - Physical standby DATABASE (disabled)
 
Fast-START Failover: ENABLED
 
Configuration STATUS:
SUCCESS
 
 
DGMGRL> enable DATABASE B
Enabled.
 
 
DGMGRL> EDIT DATABASE 'B' SET STATE='APPLY-ON';
Succeeded.
 
 
DGMGRL> SHOW DATABASE B
 
DATABASE - B
 
ROLE: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds
Apply Lag: 1 HOUR(s) 11 minutes 49 seconds <span STYLE="color: red;"> &lt;== We have SOME lag here </span>
REAL TIME Query: OFF
Instance(s):
B
 
DATABASE STATUS:
SUCCESS
 
After a few minutes, the standby IS back IN sync WITH the PRIMARY
 
 
DGMGRL&gt; SHOW DATABASE B
 
DATABASE - B
 
ROLE: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds
Apply Lag: 0 seconds <span STYLE="color: green;"> &lt;== It catched up quite quickly</span>
REAL TIME Query: OFF
Instance(s):
B
 
DATABASE STATUS:
SUCCESS

I now set B again as the FSFO target and validate the final setup.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
DGMGRL&gt; DISABLE FAST_START FAILOVER
Disabled.
DGMGRL&gt; edit DATABASE 'A' SET property 'FastStartFailoverTarget' = 'B';
Property "FastStartFailoverTarget" updated
DGMGRL&gt; edit DATABASE 'B' SET property 'FastStartFailoverTarget' = 'A';
Property "FastStartFailoverTarget" updated
DGMGRL&gt; edit DATABASE 'C' SET property 'FastStartFailoverTarget' = '';
Property "FastStartFailoverTarget" updated
DGMGRL&gt; ENABLE FAST_START FAILOVER
Enabled.
DGMGRL&gt; SHOW DATABASE A FastStartFailoverTarget;
FastStartFailoverTarget = 'B'
DGMGRL&gt; SHOW DATABASE B FastStartFailoverTarget;
FastStartFailoverTarget = 'A'
DGMGRL&gt; SHOW DATABASE C FastStartFailoverTarget;
FastStartFailoverTarget = ''
 
DGMGRL&gt; SHOW fast_start failover
 
Fast-START Failover: ENABLED
 
Threshold: 30 seconds
Target: B
Observer: observer
Lag LIMIT: 30 seconds (NOT IN USE)
Shutdown PRIMARY: TRUE
Auto-reinstate: TRUE
 
Configurable Failover Conditions
Health Conditions:
Corrupted Controlfile YES
Corrupted Dictionary YES
Inaccessible Logfile NO
Stuck Archiver NO
Datafile Offline YES
 
Oracle Error Conditions:
(NONE)
 
DGMGRL&gt;
DGMGRL&gt; SHOW configuration
 
Configuration - fsfo_A
 
Protection Mode: MaxAvailability
DATABASES:
A - PRIMARY DATABASE
B - (*) Physical standby DATABASE
C - Physical standby DATABASE
 
Fast-START Failover: ENABLED
 
Configuration STATUS:
SUCCESS

Don’t forget to drop the GRP on B or you may have a little alarm to deal with later :)

1
DROP RESTORE POINT BEFORE_UPGRADE_11204;

Final thoughts

This was an interesting exercise for several reasons.

First, this gave me the possibility of testing a procedure before it is actually executed in a production environment. This is always a good thing. No matter how many times have you done something, there is always a slight change, something done differently in a given installation or a bug hiding behind the bushes. Testing will help you prepare for what may come ahead. Reduce the surprises to a minimum.

It will also give you some deeper familiarity with the environment you are working on and confidence while running the process in production. We as consultants may not work frequently on a given customer and getting to know the environment we are working with eases the tasks.

Another reason I liked this exercise is that I, once more, got the support from my co-workers here at Pythian (special thanks to my team members). Throw an idea into a Slack channel and they will come back with more ideas, experiences, caveats and whatnot, making the task more enjoyable and executed with better quality.

If four eyes see better than two, imagine sixteen or twenty. There’ll be still room for mistakes, issues and such but they will surely be quite rare.

email

Interested in working with Jose? Schedule a tech call.

About the Author

Oracle Project Engineer
First of all father, then husband and finally Oracle database consultant. I love technology in general and managing data in particular. Trying to learn one new thing every day.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *