Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, October 13, 2020

RMAN feature in 12c:

 1.SYSBACKUP Privilege:

The SYSBACKUP privilege allows the DBA to perform RMAN backup commands without additional privileges. Prior to 12c, users needed SYSDBA privilege to backup the database.

rman target ' "/ as sysbackup" '

rman target ' "/ as sysdba" '

rman target /

rman target1 ‘ “bkpadm@PDB1 as sysbackup” ‘

rman target ‘ “sysadm@PDB1 as sysdba” ‘

rman target sysadm@PDB1

2.SQL Interface Improvements:

SQL commands can be run in RMAN.DDL/DML Commands can be from RMAN Command prompt.

SHUTDOWN/STARTUP the database and also can use ALTER commands.

RMAN DESCRIBE provides the same functionality of SQL*Plus DESCRIBE.

RMAN> desc dba_profiles;

RMAN> select sysdate from dual;

RMAN> create table table5(col1 number, col2 varchar2(20));

RMAN> insert into table5 values (1,'Test3');

RMAN> update table5 set col1=2;

RMAN> drop table table5;

RMAN> shutdown immediate

RMAN> startup mount

RMAN> alter database open;

3.Support for multitenant container and pluggable databases:

RMAN provides full support for backup and recovery for CDB and PDB.

RMAN you can back up an entire container database or individual pluggable databases and also can perform point-in-time recovery.  But it is recommended that you turn on control file auto backup.Otherwise point-in-time recovery for pluggable databases may not work efficiently when you need to undo data file additions or deletions.

When you back up a container database, RMAN backs up the root, pluggable databases in the container, and archive logs.while restoring we can choose the whole container, one or more pluggable databases or the root only.

Backup the CDB, PDB, and root:

You should have SYSBACKUP or SYSDBA privilege to backup any of the databases

Container Database (CDB) as same as non-container database using below command:

RMAN> BACKUP DATABASE plus ARCHIVELOG;

Pluggable Database (PDB) using below command:

RMAN> BACKUP PLUGGABLE DATABASE PDB1, PDB2;

Or connect to pluggable Database in RMAN :

% rman target sys@PDB1

RMAN> BACKUP DATABASE;

backup the root using below command:

RMAN> BACKUP DATABASE ROOT;

restore the whole CDB using below script.restoring CDB database will restore all the pluggable databases.

RMAN> RUN { 

     STARTUP MOUNT;

     RESTORE DATABASE;

     RECOVER DATABASE;

     ALTER DATABASE OPEN;

}

restore only ROOT Database using below script:

RMAN> RUN {

     STARTUP MOUNT;

     RESTORE DATABASE ROOT;

     RECOVER DATABASE ROOT;

     ALTER DATABASE OPEN;

}

restore Pluggable Databases in two ways. Either you can restore from root container and connect directly to PDB to restore.

Use below script to restore from root. Using this approach you can able to restore and recover multiple PDB’s with a single command.

RMAN > RUN {

     RESTORE PLUGGABLE DATABASE PDB1, PDB2;

     RECOVER PLUGGABLE DATABASE PDB1, PDB2;

     ALTER PLUGGABLE DATABASE PDB1, PDB2 OPEN;

}

Use below script to connect PDB, restore and recover the database. Using this approach you will be able to restore and recover only one PDB.

$ rman target=bkpadm@PDB1

     RMAN> run{

     RESTORE DATABASE;

     RECOVER DATABASE;

}

performing a point-in-time recovery of the CDB or PDB are the same as a normal database.

when you perform Point-in-time recovery on the CDB, it will effect on all the PDBs as well.

When you perform point-in-time recovery on a PDB, it will affect that single database.

The command to perform a point-in-time recovery is:

SET UNTIL TIME "TO_DATE(’10-Feb-2014 01:00:00’,’DD-MON-YYYY HH24:MI:SS’)";

SET UNTIL SCN 19900005; # alternatively, specify SCN

SET UNTIL SEQUENCE 120; # alternatively, specify log seq

4.Backup of Archived redo logs:

We can back up or delete archive logs when they connect to root as a common user with SYSDBA or SYSBACKUP privilege, but you cannot back up or delete archive logs when you connect to PDB as a local user with SYSDBA or SYSBACKUP privilege.

We only able to switch the archived logs when connect to the root of a CDB, but cannot switch archived redo logs when connected to a PDB.

If there is  more than one archive log destination, when RMAN used  to backup the archive redo logs it backs up only one copy of the archived redo logs. RMAN does not include more than one copy because multiple destinations will have same log sequence number.

5.DUPLICATE enhancements:

When you duplicate a database using RMAN DUPLICATE, the database is created and opened with RESETLOGS mode. With Oracle database 12c, you can specify that the database must not be opened with “NOOPEN” clause.

NOOPEN clause is useful in following situations:

If need to make changes to initialization parameters such as block change tracking, flashback database settings.

Opening the database conflict with other source database

If  plan to create database for upgrade and want to open in upgrade mode.

Below command used to creates duplicate database, but not open.

RMAN> DUPLICATE TARGET DATABASE TO DB1 FROM ACTIVE DATABASE NOOPEN;

6.Multi section Backup Improvements:

This backup functionality introduced in 11g to handle large data file backups. In this RMAN can break up a large file into sections during the backup and recovery, which will improve the performance of large datafiles backup. We can select the size using the SECTION SIZE keyword and each channel will create separate files within the backup set, and backup the database in parallel. This only supports backup sets in 11g.

In 12c, the multisection backup supports incremental backups and image copies, including backup sets (introduced in 11g).  This functionality can only be used for data files, We cannot use this to backup control files.

If the SECTION SIZE that is selected is larger than the actual file, then RMAN will not use multisection backup functionality. If specify a small SECTION SIZE that produces more than 256 sections then RMAN increases the SECTION SIZE to a value that results 256 sections.

To Create Multisection backup image copies.

RMAN> BACKUP AS COPY SECTION SIZE 1024M DATABASE;

To Create multisection incremental level1 backup:

RMAN> BACKUP INCREMENTAL LEVEL 1 SECTION SIZE 1024M DATABASE;

To enhance the backup performance, use unused block compression and block change tracking in conjunction with multisection incremental backups.

7.Restoring and Recovering Files over Network:

RMAN can restore and recover a database, tablespace, datafile, controlfile or spfile over network from a physical standby database. Restore to be happens over the network, RESTORE… FROM SERVICE command and RECOVER…FROM SERVICE command is used.

FROM SERVICE clause specifies the service name of the physical standby.

multisection, compression and encryption can be used to improve backup and restore performance.

This is very useful in scenarios involving a standby database:

Restore or recover files lost by connecting through the network on one database (standby/primary) which is available on the other database.

Recover a standby database to using an incremental backup taken off the primary to roll forward the standby.

Example to restoring data file over the network from physical standby to primary database:

Connect to Primary:

RMAN> CONNECT TARGET /

Backup sets encrypted using AES128 encryption algorithm:

RMAN> SET ENCRYPTION ALGORITHM 'AES128';

Restore datafile on the primary using service “standby_db”:

RMAN> RESTORE DATAFILE '/u01/oradata/datafile1.dbf' FROM SERVICE standby_db SECTION SIZE 1024M;

8.Active Database Duplication Improvements:

Active Database duplication  introduced in oracle 11g.This feature create clone or standby database by copying the data files and archive logs using the TARGET (Source) database channels over the network to clone AUXILIARY database. In this method no backups of the TARGET database is required. Processing load will be on the TARGET instance as TARGET database channels is being used.

In Oracle 12c, Active Database duplication can be performed using the backup sets. Sufficient AUXILIARY channels is allocated to connect TARGET database and retrieve the backup’s sets over the network, this reduced the load on the TARGET (source) database. Unused block compression can be used to reduce the size of the backups transported over the network. Encrypt backups and multisection backups can also be used. Network consumption reduces and performance improves in 12c.

RMAN to use backup sets we need to establish connection to target database using a net service name and one of the below conditions should satisfy:

(i)AUXILIARY channels numbers should be equal or greater than TARGET channels.

(ii)DUPLICATION …FROM ACTIVE DATABASE should contain either USING BACKUPSET, USING COMPRESSED BACKUPSET or SECTION SIZE .

9.Unified auditing and RMAN:

UNIFIED_AUDIT_TRAIL dictionary view has a set of fields (prefixed with RMAN_) which automatically record RMAN related events. AUDIT_ADMIN or AUDIT_VIEWER role required in order to query the UNIFIED_AUDIT_TRAIL view.

10.Recovering Tables and Table Partitions from RMAN Backups:

A dropped or purged (truncated) table can now back in time without affecting the rest of the objects within the database/tablespace.

RMAN 12c will create an auxiliary instance in a separate disk location of required files, recovers the tables or table partitions up to the desired point in time. It will then create a data pump export dump containing the recovered objects. 

11.Storage Snapshot Optimization:

With this feature we can take storage snapshot of database using third-party technologies without keeping the database in BACKUP mode. When need to recover, point in time can be used of the snapshot. Roll forward can be used by using the database archive logs, and use this snapshot feature to recover part or all of the database.

Recommended to use different storage to keep snapshot from where the database is running.

Following are required to backup database using storage snapshot optimization:

(i)The snapshot preserves the write order for each file.

(ii)The database is crash consistent during the snapshot.

(iii)The snapshot technology stores the time at which the snapshot is completed.

If above compliance id not fulfilled with third-party snapshot technology vendor, to take snapshot we have to keep database in BACKUP mode.

Following operational changes  ONLINE, OFFLINE, DROP, RENAME, ADD, READONLY and SHRINK on data files and table spaces during the snapshot then the snapshots are unusable.

Recovery time cannot be earlier than the snapshot time.

To recover complete database:

RECOVER DATABASE;

To recover database using particular snapshot

RECOVER DATABASE UNTIL TIME ‘11/10/2019 12:00:00’ SNAPSHOT TIME ‘11/9/2019 11:00:00’

partial recovery using archived redo logs:

RECOVER DATABASE UNTIL CANCEL SNAPSHOT TIME ‘11/19/2019 09:00:00’

Rman related question/answer:

 Difference between using recovery catalog and control file?

Old backup information in control file will be lost When new incarnation happens but it will be preserved in recovery catalog.

Scripts can be stored in recovery catalog. Recovery catalog is central and can have information of many databases.

What is the use of crosscheck command in RMAN?

Crosscheck will be useful to check whether the catalog information is intact with OS level information.

What are the differences between crosscheck and validate commands?

Validate command is to examine a backup set and report whether it can be restored. RMAN scans all of the backup pieces in the specified backup sets and looks at the checksum to verify that the contents are intact so that backup can be successfully restored if necessary.

Crosscheck command is to verify the status of backups and copies recorded in the RMAN repository against media such as disk or tape. The crosscheck command only processes files created on the same device type as the channel running crosscheck.

What is the difference between backup set and backup piece?

Backup set is logical. Backup piece is physical.

What is obsolete backup and expired backup?

Expired means that the backup piece or backup set is not found in the backup destination.

Obsolete means the backup piece is still available, but it is no longer needed. The backup piece is no longer needed since RMAN has been configured to no longer need this piece after so many days have elapsed, or so many backups have been performed.

Difference between auxiliary channel and maintenance channel?

New features in Oracle 12c RMAN?

New features in Oracle 11g RMAN?

What is the use of nofilenamecheck in RMAN ?

When NOFILENAMECHECK is used with the DUPLICATE command, RMAN does not validate the filenames during restoration. If the primary database and the standby database are on the same host, The DUPLICATE NOFILENAMECHECK option should not be used.

Do we need to shutdown db to change block change tracking file?

No.

What are all the  database file's that RMAN cannot backup ?

RMAN cannot take backup of the pfile, redo logs, tns or network configuration files, password files, external tables and the contents of the Oracle home files.

Can I take RMAN backup when the database is down ?

No, we can take RMAN backup only when the target database is open or in mount stage.

Wednesday, October 7, 2020

Unplugging/Plugging PDB:

 In multitenant environment, a PDB can unplug from a CDB and then plug it into another CDB.Once PDB is unplugged, it needs to be dropped from CDB as it become unusable in this CDB.Same PDB can be plugged back into the same CDB.

Unplugging PDB:

==================

Connect to PDB using sqlplus and list the location of all the datafiles of PDB which is going to unplugged.


sql>sqlplus "/ as sysdba"

sql>alter session set container=pdb1;

sql>select file_name from dba_data_files;


Close PDB:

========== 

sql>alter pluggable database pdb1 close immediate;


Unplug PDB:

===========

sql> alter pluggable database pdb1 unplug into '/u01/pdb1_db.xml';


Complete path is needed to specify which would created during this process and will contain information about this PDB. Same xml would be used during plugging into CDB.


Copy Datafile:

===============

Copy the datafiles listed in the above step to the host of CDB where we want to plug.Also copy xml file.


Drop unplugged PDB:

===================

sql>drop pluggable database pdb1 keep datafiles;


**We can skip this step, if plugging PDB on a different host.

KEEP DATAFILES clause used with drop command so that datafile dont get dropped and can be re-used id plugging in the same CDB.


Plugging PDB:

================

This would be in destination.Compatibility of PDB should be checked against CDB where it will be plugged in.

Below codes can be used, O/p should be Yes to go ahead further:

SET SERVEROUTPUT ON

DECLARE

compatible CONSTANT VARCHAR2(3) :=

CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(

pdb_descr_file => '/u01/pdb1_db.xml',

pdb_name       => 'PDB1')

WHEN TRUE THEN 'YES'

ELSE 'NO'

END;

BEGIN

DBMS_OUTPUT.PUT_LINE(compatible);

END;

Plug in PDB in target CDB:

============================

Datafiles location on the destination host/CDB can be same or different. If location is same, we don’t need to do anything, otherwise we will need to use FILE_NAME_CONVERT option of CREATE PLUGGABLE DATABASE command to specify the new location of the datafiles. 

sql> create pluggable database pdb1 using '/u01/pdb1_db.xml'  copy file_name_convert=('/u01/app/pdb1','/u01/db/pdb1');

sql> alter pluggable database pdb1 open;

***COPY keyword is default to be used to copy files to the new destination. If destination is same as source, specify NOCOPY.

If you have copied datafiles on a different location on the destination, you will need to edit .xml file to specify the location where you have copied the datafiles so that during plugging in phase, datafiles can be searched at this location.