ASM Filter Driver

Not going to invent the wheel on this one, but posted a few links below.

What I have discovered is that it only works for certain versions of the Unix kernel and I had fun with "grubby" to make sure the server I was using booted with a supported kernel.



I think the best option is to build this fresh but I tried to migrate from ASMLIB to ASMFD by removing the packages (should have followed the Oracle process rather than a web link) which messed everything up. Fortunately, just on a test bix so no big deal.

I am going to build this from scratch and post some notes. In the meantime, please consider using ASMFD over ASMLIB if you are on Linux.

"Prior to Oracle Grid Infrastructure (GI) release 12.1.0.2, ASM Library (ASMLIB) was the only method to access storage devices by means of ASM Disks and Diskgroups. There were serious limitations to this method. The ASM disks were owned by GI home owner and both the owner and any users belonging to an operating system group designated as the OSASM group could read from and write to ASM disks using OS commands like strings, echo, dd etc. This led to compromising the security of data as well as accidental corruption of the data in the ASM disks and ASM disks themselves.
With Oracle Grid Infrastructure release 12.1.0.2, Oracle has introduced a new component called Oracle Automatic Storage Management Filter Driver (Oracle ASMFD) which is installed with an Oracle Grid Infrastructure installation. It is intended to overcome the limitations mentioned earlier and replace traditional ASMLIB. ASMFD is currently available only on the Linux operating system and can be completely managed by the ASMCMD command Line interface."


https://www.oraclenext.com/2017/06/migrating-from-asmlib-to-oracle-asm.html

http://oracledba.help/index.php/SpecialTopics/ASMFD

https://www.red-gate.com/simple-talk/sql/oracle/oracle-automatic-storage-management-filter-driver-oracle-asmfd/


Multipath Playground

http://talek.github.io/blog/2015/04/22/multipath-playground/

This looks very interesting - will investigate and post details :)

DataGuard - quick notes

DATAGUARD – Setting up manual process using RMAN DUPLICATE


This is a working doc - will amend as necessary 
Thanks to Russell Willcox for the instructions.
See also
There is a prebuilt Oracle VM under here - I built the Linux 7, Oracle 12.2 version to test.

(You can use the vagrant user - password "vagrant" to login to the servers built under there but for Dataguard, the root user is "rootpasswd" and the oracle password is "oracle.)

1 On Primary database check db in archive log mode

            Export ORACLE_SID="insert name here"

            Sqlplus / as sysdba

            archive log list;

2 If not in archive log mode turn it on

            shutdown immediate;

            startup mount;

            alter database archivelog;

            alter database open;

3 Enable force logging by issuing command

            alter database force logging;

            alter system switch logfile;

4 Create standby redo logs on both the Primary and Standby


alter database add standby logfile group 4 ('+NFPSADWORADATA','+FRA') size 200M;
alter database add standby logfile group 5 ('+NFPSADWORADATA','+FRA') size 200M;
alter database add standby logfile group 6 ('+NFPSADWORADATA','+FRA') size 200M;


5 Check the DB_NAME and DB_UNIQUE_NAME on the Primary database


            Show parameter db_name

            Show parameter db_unique_name

The DB_NAME of the standby database will be the same as the primary but the DB_UNIQUE_NAME will be different.

6 Ensure that the STANDBY_FILE_MANAGEMENT is set

            alter system set standby_file_management=auto;


7 TNS service names setup


Ensure that the primary and standby databases are in the tnsnames.ora on both servers.
  

Standby




Primary



8 Setup the listener.ora on both servers

Primary


Standby


9 Stop and start the listener on both servers

            lsnrctl stop

            lsnrctl start


10 Prepare for the RMAN duplicate

11 Create the standby Control file and Pfile on the Primary database

            alter database create standby controlfile as ‘/tmp/adwdata_stby.ctl’;

            create pfile=’/tmp/adwdata_stby.ora’;


12 Create the necessary directories on the Standby server

            Mkdir -p /u01/app/12.2.0/admin/ADWDATA

                        This location needs to be the same as the primary

13 Copy the created files from the Primary server


            Scp standby control file to all locations

            Scp servername:/tmp/adwdata_stby.ctl /u01/app/oracle………

            Scp servername:/tmp/adwdata_stby.ora /u01/app/oracle/product/dbhmome/dbs


14 Establish the remote login password file
           

Either copy the password file from the primary server, or create it on the standby using the same sys password as that used on the primary, the default location for the file is:

 /u01/app/oracle/product/dbhome/dbs

Syntax to create the password file is

Orapwd file=filepath/filename password=sys password entries=10


15 Create the standby using RMAN Duplicate

            Rman TARGET sys/password@ADWDATA AUXILIARY sys/password@ADWDATA_STBY

            DUPLICATE TARGET DATABASE

            FOR STANDBY

            FROM ACTIVE DATABASE

            DORECOVER

            SPFILE

            SET db_unique_name='DB11G_STBY' COMMENT 'Is standby'

SET LOG_ARCHIVE_DEST_2='SERVICE=db11g ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G'

            SET FAL_SERVER='DB11G' COMMENT 'Is primary'

            NOFILENAMECHECK;


            A brief explanation of the individual clauses is shown below.

FOR STANDBY: This tells the DUPLICATE command is to be used for a standby, so it will not force a DBID change.

FROM ACTIVE DATABASE: The DUPLICATE will be created directly from the source datafile, without an additional backup step.

DORECOVER: The DUPLICATE will include the recovery step, bringing the standby up to the current point in time.

SPFILE: Allows us to reset values in the spfile when it is copied from the source server.

NOFILENAMECHECK: Destination file locations are not checked.

16 Check the output of the duplicate process

            If no errors are seen proceed to the next step otherwise try the following:

            Dgmgrl sys/password@ADWDATA  (primary)

            Show configuration

            Show database ADWDATA

            Show database ADWDATA_STBY

            Show database ADWDATA InconsistentProperties

            Show database ADWDATA_STBY InconsistentProperties

            If any properties are inconsistent then resolve them before starting the apply process


17 Enable the broker


At this point you will have a primary database and a standby database so you need to start using the Dataguard Broker to manage those databases, enter the following command on both the Primary and the Standby:

alter system set dg_broker_start=true;


On the Primary server issue the following command to register the primary server with the broker:

Dgmgrl sys/password@ADWDATA

create configuration adwdata_dg_config as primary database is ADWDATA connect identifier is ADWDATA;


On the Standby server enter:

add database ADWDATA_STBY as connect identifier is ADWDATA_STBY maintained as physical;

enable configuration;


18 Start the apply process


            alter database recover managed standby database; or

            alter database recover managed standby database disconnect from session;

            (this will return control to your session after starting apply process)

            If you need to cancel the apply process:

            alter database recover managed standby database cancel;

            If you want to delay the application of changes to your standby enter:
  

alter database recover managed standby database cancel;

alter database recover managed standby database delay 30 disconnect from session;

alter database recover managed standby database cancel;

alter database recover managed standby database nodelay disconnect from session;





Additional

Oracle Data Guard switchover

To show the status of the databases currently

Logon onto the Oracle Data Guard broker:

DGMGRL sys/password

Ø Show configuration

Ø Show database dbname

Make a note of which database is the current standby.

To switchover to the standby instance

Ø Switchover to standby_instance

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 "cdb1" on database "cdb1_stby"

Starting instance "cdb1"...

ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance

ORACLE instance started.

Database mounted.

Connected to "cdb1_stby"

Switchover succeeded, new primary is "cdb1"

ORA-01017 error on switchover

switchover to cdb1_stby;

Performing switchover NOW, please wait...

New primary database "cdb1_stby" is opening...

Operation requires start up of instance "cdb1" on database "cdb1"

Starting instance "cdb1"...

ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.


Please complete the following steps to finish switchover:

start up and mount instance "cdb1" of database "cdb1"

Resolution

Copy the orapw file from the database that you are initiating the switchover from

Or

Recreate the Oracle password file using Oracle utility as below:

orapwd file=…../dbs/filename password=sys password entries=10

Or

As a quick fix, mount the standby database and put it into recovery mode

Sqlplus / as sysdba

alter database mount;

alter database recover managed standby database disconnect from session;

Verify that switchover is successful

DGMGRL sys/password

Ø Show database primary_dbname

Database - cdb1

Role: PRIMARY

Intended State: TRANSPORT-ON

Instance(s):

cdb1

Database Status:

SUCCESS

Ø Show database standby_dbname

Database - cdb1_stby

Role: PHYSICAL STANDBY

Intended State: APPLY-ON

Transport Lag: 0 seconds (computed 27 seconds ago)

Apply Lag: 0 seconds (computed 27 seconds ago)

Average Apply Rate: 218.00 KByte/s

Real Time Query: OFF

Instance(s):


+++++++++++++++++++++++++++++


This is handy - from here :

https://dba.stackexchange.com/questions/110497/how-does-one-identify-if-oracle-data-guard-is-enabled-in-oracle-database

set serveroutput on
declare
  feature_boolean number;
  aux_count number;
  feature_info clob;
begin
  dbms_feature_data_guard(feature_boolean, aux_count, feature_info);
  dbms_output.put_line(feature_boolean);
  dbms_output.put_line(feature_info);
end;
/
Sample output when Data Guard is not used:
0
Data Guard usage not detected
Sample output when Data Guard is used:
1
Number of standbys: 1, Redo Apply used: TRUE, SQL Apply used: FALSE, Snapshot
Standby used: FALSE, Broker used: TRUE, Protection mode: MAXIMUM PERFORMANCE,
Log transports used: LGWR ASYNC, Fast-Start Failover used: FALSE, Real-Time
Apply used: TRUE, Compression used: FALSE, Flashback used: FALSE










RMAN backup script

#!/bin/ksh
##########################################################################################
#
# Script Name : rman_backup.ksh
#
# Written By  : 
#
# Date        : 
#
# Usage       : rman_backup.ksh -M <mode> -A <archivelog retention days>
#
# Parameters  :
#               M = Mode; DATABASE, ARCHIVELOG, ADHOC
#
# Description : 
##########################################################################################
#
# FUNCTIONS
#
##########################################################################################

InitialiseVariables ()
{
export ORACLE_SID="DB Name as appropriate"
export ORACLE_HOME=/u01/app/oracle/product/12.1.0.1/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
LogfileDir=/u02/backups/rman_logfiles
WrapperLogfile=${LogfileDir}/rman_backup_wrapper.log
Today=$(date +'%Y%m%d')
Now=$(date +'%Y%m%d_%H%M%S')
NLS_DATE_FORMAT='DD-Mon-YYYY Dy HH24:MI:SS'
export NLS_DATE_FORMAT
BACKUP_AREA=/u02/backups/
if [ ! -d $BACKUP_AREA ]
then
   mkdir ${BACKUP_AREA}
fi

ArcBackupArea=${BACKUP_AREA}/rman_archivelog_backups
DBBackupArea=${BACKUP_AREA}/rman_database_backups

ReportName=${LogfileDir}/rman_report_${Today}.txt
CrossscheckLogfile=${LogfileDir}/crosscheck.log

ArchiveLogRetention=7 #was previously 14

NumBackupsKeep=2

}

##########################################################################################

Usage ()
{
  echo "Usage: $0 -M <Mode> -A <archivelog retention days>"
}
##########################################################################################

ValidateParameters ()

{

#Script Mode:

case $ScriptMode in

'DATABASE') return ;;
'ARCHIVELOG') return ;;
'ADHOC') return ;;
*)    Usage; exit -1;;
esac
}
##########################################################################################
DeleteOldBackups ()
{
NumBackups=$(ls -d ${DBBackupArea}/20[0-9][0-9][0-9][0-9][0-9][0-9] | wc -l)
echo "Number of DB backups = ${NumBackups}."  >> ${WrapperLogfile}
if [ ${NumBackups} -lt ${NumBackupsKeep} ]
then
echo "No need to delete any backups."  >> ${WrapperLogfile}
else

Oldest=$(ls -d1 ${DBBackupArea}/20[0-9][0-9][0-9][0-9][0-9][0-9] | head -1 | xargs basename)
echo "Deleting backup ${Oldest}" >> ${WrapperLogfile}
rm -rf ${DBBackupArea}/${Oldest}

NumBackups=$(ls -d ${DBBackupArea}/20[0-9][0-9][0-9][0-9][0-9][0-9] | wc -l)

echo "There are now ${NumBackups} backups." >> ${WrapperLogfile}

fi

}

##########################################################################################

RMANReport ()

{

rman nocatalog target / << EOF > ${ReportName}

set echo on;
show all ;
list backupset of database summary ;
list backupset of database ;
list backupset of controlfile summary ;
list backupset of controlfile ;
exit ;

EOF
sqlplus -s "/ as sysdba" << FIN >> ${ReportName}

PROMPT
PROMPT ARCHIVELOG Summary:
PROMPT ===================

set pages 25

column date1 format a12 hea "Date Created"

select count(*) "No. Backupsets", to_char(completion_time,'YYYY/MM/DD') date1

  from v\$backup_set

where backup_type = 'L'

group by to_char(completion_time,'YYYY/MM/DD')

order by to_char(completion_time,'YYYY/MM/DD');

PROMPT
PROMPT END OF REPORT
PROMPT

exit

FIN

}

##########################################################################################

BackupArch ()

{

echo "Starting backup ..."  >> ${WrapperLogfile}
BackupTag="ARCLG_${Today}"
LogFile=${LogfileDir}/rman_arc_${Now}.log
rman nocatalog target / <<EOF > ${LogFile}

set echo on;

run {

SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${ArcBackupArea}/controlf_autobackup_%F';

allocate channel d1  type disk ;
allocate channel d2  type disk ;
allocate channel d3  type disk ;
allocate channel d4  type disk ;
allocate channel d5  type disk ;
allocate channel d6  type disk ;

delete noprompt archivelog until time 'trunc(sysdate - ${ArchiveLogRetention})' ;
delete noprompt backup of archivelog all completed before 'trunc(sysdate - ${ArchiveLogRetention})' ;

sql 'alter system archive log current';

backup as compressed backupset

       tag=${BackupTag}

       format '${ArcBackupArea}/rman_arc_%d_%t_%s_%p'

       (archivelog all not backed up 2 times) ;


release channel d1 ;
release channel d2 ;
release channel d3 ;
release channel d4 ;
release channel d5 ;
release channel d6 ;

}

exit;

EOF

}

#######################################

ArchivelogReport ()

{

sqlplus -s "/ as sysdba" << FIN >> ${ReportName}

PROMPT
PROMPT ARCHIVELOG Summary:
PROMPT ===================
column date1 format a12 hea "Date Created"

select count(*) "No. Backupsets", to_char(completion_time,'YYYY/MM/DD') date1
  from v\$backup_set
where backup_type = 'L'
group by to_char(completion_time,'YYYY/MM/DD')
order by to_char(completion_time,'YYYY/MM/DD');

PROMPT
PROMPT END OF REPORT
PROMPT

exit

FIN

}

##########################################################################################

CheckErrors ()

{

NumErrors=$(grep -c "RMAN-" ${LogFile})

if [ ${NumErrors} -ne 0 ]

then

echo "ERRORS were encountered !!!" >> ${WrapperLogfile}

else

echo "No errors encountered." >> ${WrapperLogfile}

fi

}

##########################################################################################
CrosscheckBackups ()

{

echo "Performing crosscheck ..."  >> ${WrapperLogfile}
rman nocatalog target / <<EOF > ${CrossscheckLogfile}

set echo on;

run {
crosscheck backupset ;
delete noprompt expired backupset ;

}

exit;

EOF

}

##########################################################################################

BackupDatabase ()

{

echo "Starting backup ..."  >> ${WrapperLogfile}

BACKUP_DIR=${DBBackupArea}/${Today}

export BACKUP_DIR

if [ ! -d $BACKUP_DIR ]

then

mkdir ${BACKUP_DIR}

fi

BackupTag="REGDB_$(date +'%Y%m%d')"

LogFile=${LogfileDir}/rman_dbf_${Now}.log

rman nocatalog target / <<EOF > ${LogFile}

set echo on;

run {

CONFIGURE CONTROLFILE AUTOBACKUP ON;

SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${BACKUP_DIR}/controlf_autobackup_%F';


allocate channel d1  type disk ;
allocate channel d2  type disk ;
allocate channel d3  type disk ;
allocate channel d4  type disk ;
allocate channel d5  type disk ;
allocate channel d6  type disk ;

backup as compressed backupset

       section size 51200M

       tag=${BackupTag}

       format '${BACKUP_DIR}/rman_dbf_%d_%t_%s_%p'

       (database include current controlfile);

sql 'alter system archive log current';

backup as compressed backupset

       format '${ArcBackupArea}/rman_arc_%d_%t_%s_%p'

       (archivelog all not backed up 2 times) ;


release channel d1 ;
release channel d2 ;
release channel d3 ;
release channel d4 ;
release channel d5 ;
release channel d6 ;

}

exit;

EOF


BackupSize=$(du -sh ${BACKUP_DIR})

echo "Size of backup =  ${BackupSize}"  >> ${WrapperLogfile}

}

##########################################################################################

BackupAdhoc ()

{

echo "Starting backup ..."  >> ${WrapperLogfile}

BACKUP_DIR=${DBBackupArea}/ADHOC

export BACKUP_DIR

if [ ! -d $BACKUP_DIR ]

then

mkdir ${BACKUP_DIR}

fi

BackupTag="ADHOC_$(date +'%Y%m%d')"

LogFile=${LogfileDir}/rman_dbf_${Now}.log

rman nocatalog target / <<EOF > ${LogFile}

set echo on;

run {

CONFIGURE CONTROLFILE AUTOBACKUP ON;

SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${BACKUP_DIR}/controlf_autobackup_%F';

allocate channel d1  type disk ;
allocate channel d2  type disk ;
allocate channel d3  type disk ;
allocate channel d4  type disk ;
allocate channel d5  type disk ;
allocate channel d6  type disk ;
allocate channel d7  type disk ;
allocate channel d8  type disk ;

sql 'alter system archive log current';

backup as compressed backupset database

       section size 51200M
       tag=${BackupTag}
       format '${BACKUP_DIR}/rman_adh_%d_%t_%s_%p'
       keep until time 'sysdate+182'
       restore point ${BackupTag} ;

sql 'alter system archive log current';


release channel d1 ;
release channel d2 ;
release channel d3 ;
release channel d4 ;
release channel d5 ;
release channel d6 ;
release channel d7 ;
release channel d8 ;

}

exit;

EOF

BackupSize=$(du -sh ${BACKUP_DIR})

echo "Size of backup =  ${BackupSize}"  >> ${WrapperLogfile}

}

##########################################################################################

ExitIfAlreadyRunning ()

{


NUM=$(ps -ef |grep rman_backup.ksh|grep -v $$|grep -v grep|wc -l)


if [ $NUM -ne 0 ]

then

echo "RMAN backup is already running.  Therefore, exiting here ..." >> ${WrapperLogfile}

echo "Script completed at `date`" | tee -a ${WrapperLogfile}

exit

fi

}

##########################################################################################

HousekeepArchivelogs ()

{


ARC_COUNT=$(ls /u02/backups/rman_archivelog_backups/rman_arc* | wc -l)

echo "Number of archivelogs before deletion: ${ARC_COUNT}" >> ${WrapperLogfile}

find /u02/backups/rman_archivelog_backups -name "rman_arc*" -mtime +18 -exec rm {} \;

ARC_COUNT=$(ls /u02/backups/rman_archivelog_backups/rman_arc* | wc -l)

echo "Number of archivelogs after deletion: ${ARC_COUNT}" >> ${WrapperLogfile}

}

##########################################################################################
#
# MAIN PROCESSING
#
##########################################################################################

# Source profile, as this will run from cron

#. ~/.profile > /dev/null  2>&1



while getopts M: flag

do

  case $flag in

  M) ScriptMode=$OPTARG ;;

  *) Usage; exit -1;;

  esac

done





if [ "$ScriptMode" = "" ]

then

  Usage

  exit -1

fi



ValidateParameters



InitialiseVariables

echo "-------------------------------------------------" | tee -a ${WrapperLogfile}

#echo " " | tee -a ${WrapperLogfile}

echo "Script starting at `date`" | tee -a ${WrapperLogfile}

echo "Mode = ${ScriptMode}." >> ${WrapperLogfile}

ExitIfAlreadyRunning


if [ "$ScriptMode" = "ARCHIVELOG" ]

then

BackupArch

fi


if [ "$ScriptMode" = "DATABASE" ]

then

DeleteOldBackups

CrosscheckBackups

BackupDatabase

RMANReport

HousekeepArchivelogs

fi

if [ "$ScriptMode" = "ADHOC" ]

then

BackupAdhoc

fi

CheckErrors


echo "Script completed at `date`" | tee -a ${WrapperLogfile}

##########################################################################################
exit
##########################################################################################