Tuesday, 29 March 2016

Rollback a Database Upgrade - 11.2.0.4 to 11.2.0.3

Database rollbacks usually follow a similar sequence of steps. From time to time, the rollback varies ever so slightly but on the most part, you can be pretty sure there is a significant overlap in database rollback plans. I've rolled back database in Linux and now in Windows.

The following post contains my notes on how to rollback a database from 11.2.0.4 to 11.2.0.3 in Windows. To raise the stakes, the rollback is done on Windows and in a RAC environment. Please note that if you are doing an Oracle Downgrade in windows from 11.2.0.4 to 11.2.0.3 you will likely invalidate your Oracle Multimedia component and you cannot work your way out of it without the assistance of MOS (Doc ID 2022064.1) - So read the note if you're doing this downgrade in windows.
The notes are an in depth adaptation of the Oracle Guide:
Downgrading Oracle Database to an Earlier Release
https://docs.oracle.com/cd/E11882_01/server.112/e23633/downgrade.htm
The database I am downgrading is fairly uncomplicated. You may want to have a look at the above document to see if there are any special circumstances that apply to your database setup.

Here is a brief guideline of the process:

1. Stop the database resource across both nodes using svrctl on the primary node
2. Create a pfile from the spfile
3. Adjust the pfile and set the cluster parameters to false
4. Overwrite the spfile using the new pfile
5. Start the database up using sqlplus in downgrade mode.
6. Run the cat downgrade script
7. Stop and delete the OracleService<INSTANCENAME> on the primary and secondary node
8. Using ORADIM, recreate the service on the primary node ONLY using the pfile from step 3 and
    using the old home.
9. Change directory to the old Oracle home admin directory
10. Startup the database in upgrade mode
11. Reload the catalogue.
12. Shutdown and startup the database followed by a recompile
13. Downgrade the database cluster resource with srvctl
14. Stop the database using srvctl.
15. Create a pfile with CLUSTER ENABLED
16. Stop and delete the OracleService<INSTANCENAME> on the primary and secondary node, recreate the services
17. Startup the database using srvctl

Lets begin with an overview.

Overview and preparation
Oracle home is where your database RDBMS software is held. Set it:
SET ORACLE_HOME=E:\Oracle\product\11.2.0.4\dbhome_1

Consider the following points:
Most of this work will take place in command prompt.
You are not downgrading any clusterware, just the database.
You are going to start the database up in downgrade mode within the latest release.
The catalogue will be downgraded from 11.2.0.4 to 11.2.0.3 using 11.2.0.4 downgrade script
The oracle home will be adjusted at some point and set back to 11.2.0.3
The entire catalogue will be recompiled using the older releases catalogue scripts.
The duration of this process is that of a database upgrade with some extra – I say 90 minutes.

Unless specified, you can assume all instructions apply to NODE1 – the primary node.
If an instruction must be executed on the secondary node, it will be stated explicitly


Remote desktop
into the primary cluster node

Open up an administrator command window on both nodes in the cluster.

Set your ORACLE_HOME to the 11.2.0.4 directory:
SET ORACLE_HOME=E:\Oracle\product\11.2.0.4\dbhome_1

Set your ORACLE_SID to the database instance on the primary node:
SET ORACLE_SID=INSTANCE1

Adjust your %PATH% variable to ensure your 11.2.0.4 %ORACLE_HOME% appears first in the list before any 11.2.0.3 directory. To test this type “where sqlplus”
To see your path – type “path”

For trouble shooting purposes, it is recommended that you use baretail.exe (linux tail command for windows) which can be found here:
https://www.baremetalsoft.com/baretail/

Use tail to follow the database logs which usually resides in
%ORACLE_BASE%\diag\rdbms\<databasename>\
<instancename>\trace\alert_<instancename>.log

1. Stop the database resource across both nodes using svrctl on the primary node

srvctl stop database -d <DATABASENAME>


Either watch the alert log or check the cluster resource ora.<DATABASENAME>.db to see when the database is finally shutdown.

2. Create a pfile from the spfile

You are going to create a pfile using the current spfile that is within the +ASM diskgroup.
Make sure the following folder exists on NODE1 and NODE2 so you can modify the pfile file you’re about to create:
E:\Oracle\scripts\downgrade\

In your administration command window on the primary node, create the pfile:
sqlplus /nolog
conn / as sysdba
create pfile='E:\Oracle\scripts\downgrade\<DATABASENAME>_clusterdisable.ora' from spfile='+DATA/
<DATABASENAME>/spfile<DATABASENAME>.ora';

3. Adjust the pfile and set the cluster parameters to false


Set the CLUSTER_DATABASE parameter in the pfile to false and SAVE the file

4. Overwrite the spfile using the new pfileIn your administration command window on the primary node, overwrite the spfile using the adjusted pfile:

sqlplus /nolog
conn / as sysdba
create spfile='+DATA/<DATABASENAME>/spfile<DATABASENAME>.ora' from pfile='E:\Oracle\scripts\downgrade\<DATABASENAME>_clusterdisable.ora';



5. Start the database up using sqlplus in downgrade mode. In command, change directory to the administration folder of the 11.2.0.4 release:
e:
cd E:\Oracle\product\11.2.0.4\dbhome_1\RDBMS\ADMIN

Now log into sqlplus and start the database up in downgrade mode
sqlplus /nolog
conn / as sysdba
startup downgrade

6. Run the cat downgrade script

Here you are downgrading the catalogue to the previous database release. Make use of the new releases downgrade script.

spool e:\oracle\scripts\downgrade\downgade.log

@catdwgrd.sql
spool off

If you encounter serious errors that abort the script – correct the issues with the assistance of the my oracle support website and rerun the script again and again. Don’t worry about Oracle Multimedia components, they can be ignored until later.


7. Stop and delete the OracleService<INSTANCENAME> on the primary and secondary node

Shutdown the database
sqlplus /nolog
conn / as sysdba
shutdown immediate

In command, the service must be deleted

NODE1
NET STOP OracleService<INSTANCENAME>
oradim -DELETE -SID 
<INSTANCENAME>

NODE2
NET STOP OracleService<INSTANCENAME>
oradim -DELETE -SID 
<INSTANCENAME>

*Usually in a cluster, instance name is typically your databasename suffixed with a number to indicate the node it resides on.


8. Using ORADIM, recreate the service on the primary node ONLY using the pfile from step 3 and using the old home.

Change homes in command:
set ORACLE_HOME=E:\Oracle\product\11.2.0.3\dbhome_1

Now recreate the service using the PFILE from step 3.
oradim -new -SID <INSTANCENAME> -startmode manual -pfile 'E:\Oracle\scripts\downgrade\<INSTANCENAME>_clusterdisable.ora


9. Change directory to the old Oracle home admin directory

In command, change directories to your old oracle home:
e:
cd E:\Oracle\product\11.2.0.3\dbhome_1\RDBMS\ADMIN



10. Startup the database in upgrade mode
Now is the time to reload the 11.2.0.3 catalogue back into the database. The following is similar to an upgrade:

sqlplus /nolog
conn / as sysdba
startup upgrade

11. Reload the catalogue.

Reload the catalogue:
spool e:\oracle\scripts\downgrade\reload.log
@catrelod.sql
spool off


Check the spool file for any errors.
If you encounter any issues that terminate the script, use MOS to resolve the issue.
The script should run its course in an hour. Once complete, it will kick you out of your console.


12. Shutdown and startup the database followed by a recompile

Recompile the invalid database objects:
sqlplus /nolog
conn / as sysdba
shutdown immediate
startup
@utlrp.sql

If Oracle Multimedia is in an invalid state, execute
exec validate_ordim;

NOTE:
What would a major rebuild be without some bugs. There is a bug when downgrading from Oracle 11.2.0.4 to 11.2.0.3 in WINDOWS – no matter what you do, your Oracle Multimedia will remain invalid. To correct this issue, see note (Doc ID 2022064.1)


13. Downgrade the database cluster resource with srvctl

Downgrade the cluster resource on the primary node.
From command, execute the following.

NODE 1:
set ORACLE_HOME=E:\Oracle\product\11.2.0.4\dbhome_1

srvctl downgrade database -d <DATABASENAME> -o E:\Oracle\product\11.2.0.3\dbhome_1 -t 11.2.0.3.0


14. Stop the database using srvctl.

NODE 1:
srvctl stop database -d <DATABASENAME>

15. Create a pfile with CLUSTER ENABLED

Duplicate the <DATABASENAME>_clusterdisable.ora file to a new file <DATABASENAME>_clusterenable.ora

Change the cluster database parameter to enable the cluster

Copy this file to E:\Oracle\scripts\downgrade\ on NODE1 and NODE2

16. Stop and delete the OracleService<INSTANCENAME> on the primary and secondary node, recreate the services

NODE1

NET STOP OracleService<INSTANCENAME>
oradim -DELETE -SID 
<INSTANCENAME>
Change homes in command:
set ORACLE_HOME=E:\Oracle\product\11.2.0.3\dbhome_1

Now recreate the service using the PFILE from step 3.
oradim -new -SID <INSTANCENAME> -startmode manual -pfile 'E:\Oracle\scripts\downgrade\<DATABASENAME>_clusterenable.ora

NODE2

NET STOP OracleService<INSTANCENAME>
oradim -DELETE -SID 
<INSTANCENAME>

Change homes in command:
set ORACLE_HOME=E:\Oracle\product\11.2.0.3\dbhome_1

Now recreate the service using the PFILE from step 3.
oradim -new -SID <INSTANCENAME> -startmode manual -pfile 'E:\Oracle\scripts\downgrade\<DATABASENAME>_clusterenable.ora*Usually in a cluster, instance name is typically your databasename suffixed with a number to indicate the node it resides on.

17. Startup the database using srvctl

NODE1
srvctl start database -d <DATABASENAME>

Check that the database is accessible on both nodes, restart the cluster if accessibility is an issue on both nodes. 

Tuesday, 15 March 2016

What camera do you use?

Here is a response image to a question I've often been asked in the past: what camera do you use or which is the best camera for taking pictures?

All my camera equipment is second hand and totals to around R20,000 - including a R1500 11-18mm wide angle not shown here - all purchased over 5 years.
On all accounts, I am a "weekend warrior" and try to stay invisible while out and about but individuals find me and approach me quite often asking the aforementioned question.

The lengthier answer is: the DSLR camera body has little to do with the images and the quality of image is more dependent on opportunity (and how you make use of it), light conditions and, to a degree, the quality of the glass on the end on the body which help realize a decent image.

For instance: the lens seen on the body in the picture above is a lens that is older than me. It is a Nikon 400 mm f/5.6 IF-ED MF and purchased for R4000 or $500 in 2013. This lightweight manual focusing lens delivers sharp images, but it does take practice considering its a manual focus lens. The image below was captured in 2013 at a national surfing competition here in South Africa and printed in the national papers. This is not bad considering a modern 400mm lens with stabilization will cost between R150-200K (~$12000). What this all means is that using old cheap equipment, hand me down lenses and a very old prosumer camera body, I've been able to take images that are decent. It is years of enjoyment, experience and with an intention to improve that have helped produce better images.



So, assuming the real question underneath the the original question is : how do I take better pictures?

The answer is: Immerse yourself in what you do for long enough to create a critical mass of experience to build upon. Part of learning is taking terrible shots, so take 10,000 terrible shots sooner rather than later. Reading helps too so google up or buy some books. If you're serious, follow a photographer online or listen to podcasts like Gavin Seim of Seim Studios. Read up on Ansel Adams and other famous photographers. Social media helps you find your style or niche so join an online group.





Monday, 14 March 2016

crsctl status very slow in windows environment


If you find that crsctl takes time to return the cluster or a component status then it is quite possible that the calling user is not part of the local administration group.

crsctl stat res -t

For details, see RAC on Windows: 'crsctl' Commands are Slow (Doc ID 2024419.1)

Add your user to the local administrators group as show below.


Thursday, 10 March 2016

Daily Cluster Health Report

This post will show you how to setup a RAC component report: an email that sends the state of the cluster components. This helps a DBA keep an eye on the cluster and act preemptively if any component appears offline.

REQUIREMENTS:

1. Access to Task Scheduler (or cron for Linux)
2. A from address from a recognized mail server within your domain.
3. A home folder to deploy the scripts

INSTALL

1. Open up command prompt (cmd) and execute the following – adjust root location if need be

e:
mkdir E:\dba\script\clusterhealthreport
cd E:\dba\script\clusterhealthreport

2. Create a file called mail.vbs inside E:\oracle\scripts\LogReport. Copy the following and paste into the file
'Grab the parameters
from_address = WScript.Arguments(0)
to_address = WScript.Arguments(1)
subject = WScript.Arguments(2)
file = WScript.Arguments(3)

'Set the file reading variables
Const ForReading = 1
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

'Set the mail properties
SMTPServer = "smtprelay.inter.domain.net"
Recipient = to_address
From = from_address
Subject = subject


'Create the mail object
GenericSendmail SMTPserver, From, Recipient, Subject, Message
Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)
Message = fso.OpenTextFile(file,ForReading).ReadAll

'Assisgn the values to our mail object and send the mail off
set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message
msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg.Configuration.Fields.Update
msg.Send
End Sub

3. Create a file called clusterhealthreport.bat and paste the following into it. Set the variables in yellow to what you want:
SET CLUSTERNAME=CLUSTERNAME
SET WORKING_DIR=E:\dba\script\clusterhealthreport
SET PATH=%PATH%;%WORKING_DIR%
SET ORACLE_BASE=E:\Oracle
SET ORACLE_HOME=E:\OracleGrid\11.2.0.4

cd %WORKING_DIR%
E:

SETLOCAL EnableDelayedExpansion

echo CLUSTER HEALTH REPORT  > clusterhealthreport.log
echo ---------------------  >> clusterhealthreport.log
echo .                      >> clusterhealthreport.log
echo crsctl stat res -t     >> clusterhealthreport.log

crsctl stat res -t >> clusterhealthreport.log

mail.vbs serveraddress@servername.net emailaddress@domain.net "%CLUSTERNAME% Cluster Health Report" %WORKING_DIR%\clusterhealthreport.log

4. Create a task scheduler to run once a day – I usually set it for 5:30am:























Click start, open task scheduler















Right click task scheduler library



Under the general tab, ensure the task executes with the highest privileges and runs while the user in not logged into the system. Enter a description for the server administrator.

Create a schedule – for details on their configuration see the screenshot below.


In the action tab, browse to the bat file location created in step 3

Your email should look like the following:
CLUSTER HEALTH REPORT 
--------------------- 
.                     
crsctl stat res -t    
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS      
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                               
ora.H_DRIVE.dg
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.LISTENER.lsnr
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.asm
               ONLINE  ONLINE       yournodedb01           Started            
               ONLINE  ONLINE       yournodedb02           Started            
ora.gsd
               OFFLINE OFFLINE      yournodedb01                              
               OFFLINE OFFLINE      yournodedb02                              
ora.net1.network
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.ons
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.registry.acfs
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       yournodedb02                              
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       yournodedb01                              
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       yournodedb01                              
ora.cvu
      1        ONLINE  ONLINE       yournodedb01                              
ora.oc4j
      1        ONLINE  ONLINE       yournodedb01                              
ora.scan1.vip
      1        ONLINE  ONLINE       yournodedb02                              
ora.scan2.vip
      1        ONLINE  ONLINE       yournodedb01                              
ora.scan3.vip
      1        ONLINE  ONLINE       yournodedb01                              
ora.database.db
      1        ONLINE  ONLINE       yournodedb01           Open               
      2        ONLINE  ONLINE       yournodedb02           Open               
ora.yournodedb01.vip
      1        ONLINE  ONLINE       yournodedb01                               
ora.yournodedb02.vip
      1        ONLINE  ONLINE       yournodedb02         

Wednesday, 9 March 2016

Alert Log Daily Report

This document will show you how to setup an alert log report: an email that sends the alert log trail since the last report was sent. This helps a DBA keep an eye on the alert log of a database and helps the administrators spot any issues pre-emptively

REQUIREMENTS:

1. Access to Task Scheduler (or cron for Linux)
2. A from address from a recognized mail server within your domain.
3. A home folder to deploy the scripts
4. Download UnixUtils – the 20+ unix utilities adapted for windows-in particular: wc.exe and tail.exe

INSTALL

1. Open up command prompt (cmd) and execute the following – adjust root location if need be

e:
mkdir E:\oracle\scripts\LogReport
cd E:\oracle\scripts\LogReport


2. Create a file called mail.vbs inside
E:\oracle\scripts\LogReport. Copy the following and paste into the file

'Grab the parameters
from_address = WScript.Arguments(0)
to_address = WScript.Arguments(1)
subject = WScript.Arguments(2)
file = WScript.Arguments(3)

'Set the file reading variables
Const ForReading = 1
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

'Set the mail properties
SMTPServer = "smtprelay.inter.domain.net"
Recipient = to_address
From = from_address
Subject = subject


'Create the mail object
GenericSendmail SMTPserver, From, Recipient, Subject, Message
Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)
Message = fso.OpenTextFile(file,ForReading).ReadAll

'Assisgn the values to our mail object and send the mail off
set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message
msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg.Configuration.Fields.Update
msg.Send
End Sub

3. Create a file called logreport_DBNAME.bat and paste the following into it. Set the variables in yellow to what you want:
SET ORACLE_SID=DBNAME
SET ORACLE_BASE=E:\Oracle
SET ALERT_LOG=%ORACLE_BASE%\diag\rdbms\%ORACLE_SID%\%ORACLE_SID%\trace\alert_%ORACLE_SID%.log
SET WORKING_DIR=E:\oracle\scripts\LogReport
SET PATH=%PATH%;%WORKING_DIR%

cd %WORKING_DIR%
E:

SETLOCAL EnableDelayedExpansion

echo Alert Log Difference
`echo --------------------
echo .
echo Load the last line count taken into a variable...
set /p old_linecount=<linecount.txt

echo Get the current line count of the database alert log...
wc -l < %ALERT_LOG% > linecount.txt
set /p new_linecount=<linecount.txt

echo Subtract the latest from the previous...
set /a difference=%new_linecount%-%old_linecount%

echo %difference%

if %difference% geq 3000 set difference=3000

if %difference% geq 1 tail -n %difference% %ALERT_LOG% > alert_%ORACLE_SID%.out

if %difference% equ 0 echo The alert log has not change or is empty, if you receive this message twice, investigate the log file %ALERT_LOG%. > alert_%ORACLE_SID%.out

if %difference% lss 0 echo The alert log %ALERT_LOG% has changed in a way where yesterdays file has a greater line count than todays, if you receive this message twice, investigate the log file. > alert_%ORACLE_SID%.out

mail.vbs servername@domainname.net emailaddress@domainname.net "%ORACLE_SID% DailyAlert" %WORKING_DIR%\alert_%ORACLE_SID%.out




4. Copy cat.exe (unixutils) into E:\oracle\scripts\LogReport or unix utils in your %PATH% location

5. Create a task scheduler to run once a day – I usually set it for 5:30am:



























Click start, open task scheduler
















Right click task scheduler library


Under the general tab, ensure the task executes with the highest privileges and runs while the user in not logged into the system. Enter a description for the server administrator.


In the action tab, browse to the bat file location created in step 3


Create a schedule – for details on their configuration see the screenshot below.


Schedule the job to run at 2 times – create 2 schedules on daily repeat

Tuesday, 8 March 2016

Tiffindell 2015 - Snow in South Africa

Tiffindell, a place deep in the Transkei. If you're a South African and you want an affordable ski experience, pay them a visit them between July and August. 
Tiffindell Ski Resort
Snowboard Gear
Tiffindell Evening

Top of the Slope

Fun


ARCHIVELOG to NOARCHIVELOG

-+12 development databases, all in archivelog mode, consumed all the available disk space on a drive causing the instances to shutdown at the same time. So I put all the databases into NOARCHIVELOG mode.

In each database, I ran the following:

SHUTDOWN IMMEDIATE;
STARTUP MOUNT EXCLUSIVE;
ALTER DATABASE NOARCHIVELOG;
ALTER DATABASE OPEN;

Once done, I adjusted the generic rman backup script to be geared toward NOARCHIVELOG mode - a cold backup:

run{ 
   configure backup optimization on; 
   sql 'alter system switch logfile';
   shutdown immediate;
   startup mount;
   allocate channel backup_disk1 type disk format '%U.rman'; 
   backup as compressed backupset database include current controlfile tag 'COLD_BACKUP'; 
   crosscheck backupset; 
   delete noprompt expired backupset; 
   release channel backup_disk1;
   sql 'alter database open';
   }