Sunday, January 24, 2016

Enable Unified Audit in Oracle 12c

First, stop all oracle processes (instances, listeners)
$ cd $ORACLE_HOME/rdbms/lib
$ make -f ins_rdbms.mk uniaud_on ioracle ORACLE_HOME=$ORACLE_HOME

To monitor recent RMAN backup and recovery

SQL> select dbusername,rman_operation
  2  from unified_audit_trail
  3  where rman_operation is not null;

DBUSERNAME               RMAN_OPERATION
------------------------------ --------------------
SYS                   Backup
SYS                   Restore
SYS                   Recover
SYS                   Backup
SYS                   Restore
SYS                   Recover

6 rows selected.
 

Falshback from Common User Drop

$ export NLS_DATE_FORMAT='DD-MM-YYYY HH:MI:SS'
$ sqlplus / as sysdba
SQL> select flashback_on from v$DATABASE;

FLASHBACK_ON
------------------------
NO

SQL> shutdown immediate;
SQL> startup mount;
SQL> ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=2880 SCOPE=BOTH;
SQL> ALTER DATABASE FLASHBACK ON;
SQL> ALTER DATABASE OPEN;

2)
SQL> ALTER PLUGGABLE DATABASE ALL OPEN;
SQL> ALTER PLUGGABLE DATABASE ALL SAVE STATE;

3) DROP USER
SQL> col username for a20
SQL> select USERNAME, COMMON, CON_ID from cdb_users
where username='C##_USER';

 USERNAME         COM     CON_ID
-------------------- --- ----------
C##_USER         YES      1
C##_USER         YES      6
C##_USER         YES      5
C##_USER         YES      4
C##_USER         YES      3

Log the SCN before dropping
SQL> select timestamp_to_scn(current_timestamp) from v$database;

TIMESTAMP_TO_SCN(CURRENT_TIMESTAMP)
-----------------------------------
                2812476


 SQL> drop user C##_USER cascade;
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
SQL> FLASHBACK DATABASE TO SCN 2812476;
SQL > ALTER DATABASE OPEN READ ONLY;
SQL> 
SQL> col username for a20
SQL> select USERNAME, COMMON, CON_ID from cdb_users
  2  where username='C##_USER';

USERNAME         COM     CON_ID
-------------------- --- ----------
C##_USER         YES      1

 SQL> ALTER PLUGGABLE DATABASE ALL OPEN READ ONLY;

SQL> select USERNAME, COMMON, CON_ID from cdb_users
where username='C##_USER';

USERNAME         COM     CON_ID
-------------------- --- ----------
C##_USER         YES      3
C##_USER         YES      5
C##_USER         YES      1
C##_USER         YES      4
C##_USER         YES      6


 SQL> SHUTDOWN IMMEDIATE
SQL>STARTUP MOUNT;
SQL> FLASHBACK DATABASE TO SCN 2812476;
Flashback complete.
SQL > ALTER DATABASE OPEN RESETLOGS;

3) Check user
SQL> conn C##_USER
Enter password:
Connected.
SQL> conn c##_USER@PDB2
Enter password:
Connected.
SQL> connect C##_USER@PDB2_2
Enter password:
Connected.


4) Backup  DB
$ rman target /
RMAN> BACKUP DATABASE PLUS ARCHIVELOG delete all input;
...
RMAN> exit;



PITR on non-essential tablespace

PITR on non-essential tablespace

Lets' first log scn before issue.

SQL> select timestamp_to_scn(sysdate) from v$database;

TIMESTAMP_TO_SCN(SYSDATE)
-------------------------
          2809058

SQL> delete from local_test.tab_test where rownum < 3;

2 rows deleted.

SQL> commit
  2  ;

Commit complete.

SQL> select * from local_test.tab_test;

     C
----------
     3
     4

[oracle@edbtr43p0 trace]$ rman target /

RMAN> alter pluggable database pdb2_2 close;

using target database control file instead of recovery catalog
Statement processed

RMAN> run {
2> set until scn = 2809058;
3> restore pluggable database pdb2_2;
4> recover pluggable database pdb2_2 auxiliary
5> destination='/u01/app/oracle/oradata';
6> alter pluggable database pdb2_2 open resetlogs;
7> }

RMAN> exit


$ sqlplus sys@pdb2_2 as sysdba
SQL> select * from local_test.tab_test;

     C
----------
     1
     2
     3
     4










RMAN> delete obsolete;
RMAN> backup database plus archivelog delete all input;

RMAN Recovery from Non-Essential Datafile loss, # SYSAUX 


 RMAN> list failure
2> ;

using target database control file instead of recovery catalog
Database Role: PRIMARY

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
362        HIGH     OPEN      23-JAN-16     One or more non-system datafiles are missing


RMAN> list failure detail;

Database Role: PRIMARY

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
362        HIGH     OPEN      23-JAN-16     One or more non-system datafiles are missing
  Impact: See impact for individual child failures
  List of child failures for parent failure ID 362
  Failure ID Priority Status    Time Detected Summary
  ---------- -------- --------- ------------- -------
  985        HIGH     OPEN      23-JAN-16     Datafile 3: '/u01/app/oracle/oradata/cdb2/sysaux01.dbf' is missing
    Impact: Some objects in tablespace SYSAUX might be unavailable


RMAN> advise failure;

Database Role: PRIMARY

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
362        HIGH     OPEN      23-JAN-16     One or more non-system datafiles are missing
  Impact: See impact for individual child failures
  List of child failures for parent failure ID 362
  Failure ID Priority Status    Time Detected Summary
  ---------- -------- --------- ------------- -------
  985        HIGH     OPEN      23-JAN-16     Datafile 3: '/u01/app/oracle/oradata/cdb2/sysaux01.dbf' is missing
    Impact: Some objects in tablespace SYSAUX might be unavailable

analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=365 device type=DISK
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/cdb2/sysaux01.dbf was unintentionally renamed or moved, restore it

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore and recover datafile 3 
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/cdb2/cdb2/hm/reco_3475313480.hm


RMAN> repair failure preview;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/cdb2/cdb2/hm/reco_3475313480.hm

contents of repair script:
   # restore and recover datafile
   sql 'alter database datafile 3 offline';
   restore ( datafile 3 );
   recover datafile 3;
   sql 'alter database datafile 3 online';


RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/cdb2/cdb2/hm/reco_3475313480.hm

contents of repair script:
   # restore and recover datafile
   sql 'alter database datafile 3 offline';
   restore ( datafile 3 );
   recover datafile 3;
   sql 'alter database datafile 3 online';

Do you really want to execute the above repair (enter YES or NO)? YES
...........................
 sql statement: alter database datafile 3 online
repair failure complete

RMAN> exit


Sunday, January 10, 2016

Learning plan from workshop on Oracle Real Application Cluster


1 Installation and setting of Oracle VirtualBox, creation of RAC1 Virtual Machine (VM)
2 Installation of Oracle linux 64 bits operating system
3 Setting network cards and the /etc/hosts file
4 Tune RAC1 with yum: Kernel parameters, packages dependencies, user and groups
5 Clone RAC1 to RAC2, the second node of our Oracle RAC cluster
6 Creation of the shared disks from virtual box and present them to both racs
7 Creation of ASM disk for subsequent creation of diskgroups
8 Installation of the binaries GI 12c
Set the ssh connectivity between node 1 and node 2
Run runcluvfy to get all the check results
At this step if all is good, you have your first cluster 12c !
9 Installation of GI 12c silent mode
10 Installing Oracle 11gR2 binaries (graphic and silent)
11 Creating Database 11gR2 data (graphic and silent)
12 Learn all the command available to manage your cluster
With this course, you have in your hand a powerful environment, created with the last version of Oracle products and for a very low cost. You can simulate a production environment at home with your personal computer.
What are you going to get from this workshop?
Real Time Oracle Practice.
Install and set from scratch a 2 node cluster with Oracle 12c technology
Know all the important point to set a cluster with Oracle
Install and set Oracle virtual box for RAC
Install and set linux 6.6 64bits for RAC
Create and present shared disks to simulate you have a storage array
Install, configure and use oracle asmlib libraries to map the shared disks to ASM disks
Know and practice with the most important cluster command lines