Cleaning AUD$

Notes:
SCRIPT: Basic example to manage AUD$ table in 11.2 with dbms_audit_mgmt (Doc ID 1362997.1)
DBMS_AUDIT_MGMT.INIT_CLEANUP Fails With ORA-46267 (Doc ID 1508787.1)

This is a procedure to clean the AUD$ table to avoid locks during 
the truncate process. Even being online process is recommended to be 
executed in a maintenance window. For small environments or non-prod you
can try execute online, without stop the application.

Script: purge_job.sql ==> Run this script as SYS database user account.

=> Please before start take the current size of AUD$ on DBA_SEGMENTS.
select sum(bytes)/(1024*1024) mb 
from dba_segments where segment_name='AUD$';

=> Create a new tablespace based on the value returned on the previous 
select.
create tablespace AUDTBS datafile '/oradata/db/audtbs1.dbf' 
size <VALUE>g autoextend on next 128m maxsize 20g;

=> Take the current number of rows, just to check after <OPTIONAL>
select count(*) from aud$;

prompt start of the script

set serveroutput on
prompt Change based on our customization done 
update dam_config_param$ set string_value='AUDTBS' 
where audit_trail_type#=1 and param_id=22;
commit;

prompt First Step: init cleanup (if not already)

BEGIN
IF NOT DBMS_AUDIT_MGMT.IS_CLEANUP_INITIALIZED(
DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD) THEN
dbms_output.put_line('Calling DBMS_AUDIT_MGMT.INIT_CLEANUP');
 DBMS_AUDIT_MGMT.INIT_CLEANUP(
audit_trail_type => dbms_audit_mgmt.AUDIT_TRAIL_AUD_STD,
default_cleanup_interval => 12);
else
 dbms_output.put_line('Cleanup for STD was already initialized');
end if;
end;
/

prompt revert back to default values again
update dam_config_param$ set string_value='SYSAUX' 
where audit_trail_type#=1 and param_id=22;
commit;

prompt set last archive timestamp to older than 7 days

begin
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
last_archive_time => sysdate - 7);
end;
/

prompt setup a purge job

BEGIN
DBMS_AUDIT_MGMT.CREATE_PURGE_JOB (
AUDIT_TRAIL_TYPE => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
AUDIT_TRAIL_PURGE_INTERVAL => 12,
AUDIT_TRAIL_PURGE_NAME => 'Standard_Audit_Trail_PJ',
USE_LAST_ARCH_TIMESTAMP => TRUE );
END;
/

prompt call DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP 
regularly to advance the last archive timestamp

create or replace 
procedure set_archive_retention (retention in number default 7) as
begin
 DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(
 audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
 last_archive_time => sysdate - retention);
end;
/

BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'advance_archive_timestamp',
job_type => 'STORED_PROCEDURE',
job_action => 'SET_ARCHIVE_RETENTION',
number_of_arguments => 1,
start_date => SYSDATE,
repeat_interval => 'freq=hourly;interval=12' ,
enabled => false,auto_drop => FALSE);
dbms_scheduler.set_job_argument_value(
job_name =>'advance_archive_timestamp',
argument_position =>1,argument_value => 7);
DBMS_SCHEDULER.ENABLE('advance_archive_timestamp');
End;
/

BEGIN
DBMS_SCHEDULER.run_job (
job_name => 'advance_archive_timestamp',use_current_session => FALSE);
END;
/

prompt End of the script


To verify the purge status and configured jobs status execute 
the following queries.

select min(NTIMESTAMP#) from aud$;
select LAST_START_DATE,LAST_RUN_DURATION,NEXT_RUN_DATE 
from dba_scheduler_jobs where job_name='ADVANCE_ARCHIVE_TIMESTAMP';
select LAST_START_DATE,LAST_RUN_DURATION,NEXT_RUN_DATE 
from dba_scheduler_jobs where job_name='STANDARD_AUDIT_TRAIL_PJ';

 

Advertisements

Convert standby in a snapshot database

 

Here the article to how to create a dataguard with broker:
https://ezdba.wordpress.com/2017/05/15/dataguard-setup-with-broke
--- convert the physical standby database to a snapshot database 
and open it for read-write operations.

-- Primary: Boston hostname(vddl-ocme1-rac-01)
-- Standby: London hostname(vddl-ocm-odg-01)

1.) Terminal windows with LONDON variables

[oracle@vddl-ocm-odg-01 ~]$ . oraenv
ORACLE_SID = [oracle] ? london
The Oracle base remains unchanged with value /opt/oracle
[oracle@vddl-ocm-odg-01 ~]$

sqlplus / as sysdba

SQL> select database_role from v$database;

DATABASE_ROLE
----------------
PHYSICAL STANDBY

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES

SQL> show parameter DB_FLASHBACK_RETENTION_TARGET

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440

SQL> show parameter DB_RECOVERY_FILE_DEST

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /opt/oracle/oradata/london/arc
db_recovery_file_dest_size big integer 11105M

select file_type,number_of_files,percent_space_used
from v$recovery_area_usage;

FILE_TYPE NUMBER_OF_FILES PERCENT_SPACE_USED
----------------------- -------------------- --------------------
CONTROL FILE 0 0
REDO LOG 4 1.8
ARCHIVED LOG 27 7.6
BACKUP PIECE 2 .31
IMAGE COPY 0 0
FLASHBACK LOG 6 2.7
FOREIGN ARCHIVED LOG 0 0
AUXILIARY DATAFILE COPY 0 0

2.) Stop the RECOVERY

alter database recover managed standby database cancel;

3.) Convert to snapshot

alter database convert to snapshot standby;
SQL> select database_role from v$database;

DATABASE_ROLE
----------------
SNAPSHOT STANDBY

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES

SQL> select name, storage_size from v$restore_point;

NAME STORAGE_SIZE
---------------------------------------- --------------------
SNAPSHOT_STANDBY_REQUIRED_06/19/2017 10: 52428800
33:40

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

4.) Open the database

SQL> alter database open;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

5.) Test

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
-------------------- ------------------------------ ---------- ----------
 2 PDB$SEED READ ONLY NO
 3 DEV1 MOUNTED
SQL>
SQL>
SQL> alter pluggable database dev1 open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
-------------------- ------------------------------ ---------- ----------
 2 PDB$SEED READ ONLY NO
 3 DEV1 READ WRITE NO
SQL>
SQL>
SQL> alter session set container=dev1;

Session altered.

SQL>
SQL> create table misc1 (x varchar2(50) );

Table created.

SQL> insert into misc1 values ('Test Row');

1 row created.

SQL> commit;

Commit complete.

SQL> conn / as sysdba
Connected.

INSTANCE_NAME
----------------
london

6.) Check the Primary database: Boston

. oraenv
boston

SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

MAX(SEQUENCE#) THREAD#
-------------------- --------------------
 74 1

alter system switch logfile;

7.) Check the Sequence on standby snapshot database london.

SQL> SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

MAX(SEQUENCE#) THREAD#
-------------------- --------------------
 75 1

Note: Here we have a sequence bigger than primary because on this configuration i am using
FAR SYNC also.

8.) Convert back to standby:

. oraenv

london

sqlplus / as sysdba

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 520093696 bytes
Fixed Size 2926272 bytes
Variable Size 356518208 bytes
Database Buffers 155189248 bytes
Redo Buffers 5459968 bytes
Database mounted.
SQL> alter database convert to physical standby;

Database altered.

CON_ID CON_NAME OPEN MODE RESTRICTED
-------------------- ------------------------------ ---------- ----------
 2 PDB$SEED MOUNTED
 3 DEV1 MOUNTED

SQL> select file_type,number_of_files,percent_space_used
from v$recovery_area_usage; 2

FILE_TYPE NUMBER_OF_FILES PERCENT_SPACE_USED
----------------------- -------------------- --------------------
CONTROL FILE 0 0
REDO LOG 4 1.8
ARCHIVED LOG 29 7.67
BACKUP PIECE 2 .31
IMAGE COPY 0 0
FLASHBACK LOG 6 2.7
FOREIGN ARCHIVED LOG 0 0
AUXILIARY DATAFILE COPY 0 0

8 rows selected.

SQL>
SQL>
SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
-------------------- ------------------------------ ---------- ----------
 2 PDB$SEED MOUNTED
 3 DEV1 MOUNTED
SQL> alter database open;

Database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
-------------------- ------------------------------ ---------- ----------
 2 PDB$SEED READ ONLY NO
 3 DEV1 MOUNTED
SQL> alter pluggable database dev1 open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
-------------------- ------------------------------ ---------- ----------
 2 PDB$SEED READ ONLY NO
 3 DEV1 READ ONLY NO
SQL> alter session set container=dev1;

Session altered.

SQL> select * from misc1;
select * from misc1
 *
ERROR at line 1:
ORA-00942: table or view does not exist




SQL> conn / as sysdba
Connected.

INSTANCE_NAME
----------------
london

1 row selected.




SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 520093696 bytes
Fixed Size 2926272 bytes
Variable Size 356518208 bytes
Database Buffers 155189248 bytes
Redo Buffers 5459968 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect;

Database altered.


exit;

 

Dataguard – FAR SYNC

Here the article to how to create a dataguard with broker:
https://ezdba.wordpress.com/2017/05/15/dataguard-setup-with-broker/
FAR SYNC:
https://docs.oracle.com/database/121/SBYDB/create_fs.htm#SBYDB5441

Dataguard Far Sync.

Primary: Boston - hostname(vddl-ocme1-rac-01)
Standby: London - hostname(vddl-ocm-odg-01)

Far Sync:
bostonFS - hostname(vddl-ocm-odg-01)
londonFS - hostname(vddl-ocme1-rac-01)

tns entries on both sides for:

BOSTON 
LONDON 
LONDONFS 
BOSTONFS

1.)
create pfile='/tmp/initbostonFS.ora' from spfile;

2.)
alter database create far sync instance controlfile as '/tmp/bostonFS.ctl';

3.)
cp /opt/oracle/product/12.1.0.2/standalone/dbs/orapwboston /tmp

4.) 
[oracle@vddl-ocme1-rac-01 tmp]$ scp *boston* vddl-ocm-odg-01:/tmp
oracle@vddl-ocm-odg-01s password:
bostonFS.ctl 100% 17MB 17.4MB/s 00:00
initbostonFS.ora 100% 1983 1.9KB/s 00:00
orapwboston

5.) on Standby server:
mkdir -p /opt/oracle/oradata/bostonFS/
mkdir -p /opt/oracle/oradata/bostonFS/dev1/
mkdir -p /opt/oracle/fast_recovery_area/BOSTONFS
mkdir -p /opt/oracle/fast_recovery_area/bostonFS
mkdir -p /opt/oracle/admin/bostonFS/adump

6.) On Standby set the variables
. oraenv
bostonFS

7.) Edit

vi /tmp/initbostonFS.ora
:%s/boston/bostonFS/g

*.db_name='boston'
*.log_archive_config='dg_config=(boston,bostonFS,london,londonFS)'
*.log_archive_dest_2='SERVICE=london SYNC REOPEN=15 valid_for=(STANDBY_LOGFILES,STANDBY_ROLE) db_unique_name=london'
*.control_files='/opt/oracle/oradata/bostonFS/bostonFS01.ctl','/opt/oracle/fast_recovery_area/bostonFS/bostonFS02.ctl'
#*.local_listener='LISTENER_BOSTON'
*.db_unique_name=bostonFS
*.fal_server=boston
*.log_file_name_convert='boston','bostonFS'

8.) Copy controlfile

cp /tmp/bostonFS.ctl /opt/oracle/oradata/bostonFS/bostonFS01.ctl
cp /tmp/bostonFS.ctl /opt/oracle/fast_recovery_area/bostonFS/bostonFS02.ctl

9.) Copy Password FILE
cp /tmp/orapwboston $ORACLE_HOME/dbs/orapwbostonFS

10.) Check the environment variables to see if are pointed to bostonFS

set | grep ORA

11.) Create the spfile:

sqlplus / as sysdba
create spfile from pfile='/tmp/initbostonFS.ora';

12.) Mount the FAR Sync Instance:
startup mount;

13.) From Primary Server
sqlplus / as sysdba

--> Old Configurations
service="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=vddl-ocm-odg-01.lux.eproseed.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=london.example.com)(SERVER=DEDICATED)))", ASYNC NOAFFIRM delay=0 optional compression=disable max_failure=0 max_connections=1 reopen=300 db_unique_name="london" net_timeout=30,valid_for=(online_logfile,all_roles)

--> New configuration
alter system set log_archive_config='dg_config=(boston,bostonFS,london,londonFS,london2)' scope=both; --> Must be also on London Standby
alter system set log_archive_dest_2='SERVICE=bostonFS SYNC REOPEN=15 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=bostonFS' scope=both;

14.) Check the sequences:

Primary:
SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

MAX(SEQUENCE#) THREAD#
-------------------- --------------------
 49 1

alter system switch logfile;

SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

MAX(SEQUENCE#) THREAD#
-------------------- --------------------
 50 1

StandBy: bostonFS,
At this time all of TNS must be working fine, check the logs (Broker) to see if there is no error inside.

SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

MAX(SEQUENCE#) THREAD#
-------------------- --------------------
 50 1

StandBy: london:

SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;

MAX(SEQUENCE#) THREAD#
-------------------- --------------------
 50 1


15.) On standby server as bostonFS:
Check the Standby redolog files

1* select * from v$logfile
SQL> col member format a75
SQL> /

GROUP# STATUS TYPE MEMBER IS_ CON_ID
-------------------- ------- ------- --------------------------------------------------------------------------- --- --------------------
 3 ONLINE /opt/oracle/oradata/bostonFS/redo03.log NO 0
 2 ONLINE /opt/oracle/oradata/bostonFS/redo02.log NO 0
 1 ONLINE /opt/oracle/oradata/bostonFS/redo01.log NO 0
 4 STANDBY /opt/oracle/fast_recovery_area/BOSTONFS/onlinelog/o1_mf_4_dn7z8tbx_.log YES 0
 5 STANDBY /opt/oracle/fast_recovery_area/BOSTONFS/onlinelog/o1_mf_5_dn7z8wgm_.log YES 0
 6 STANDBY /opt/oracle/fast_recovery_area/BOSTONFS/onlinelog/o1_mf_6_dn7z8x7c_.log YES 0
 7 STANDBY /opt/oracle/fast_recovery_area/BOSTONFS/onlinelog/o1_mf_7_dn7z8tbm_.log YES 0

16.) Adding a second far sync, now for London standby. When London becomes primary the archived logs will sent to londonFS
instead of to send to boston.

. oraenv
boston

connect to vddl-ocme1-rac-01 - PRIMARY

[oracle@vddl-ocme1-rac-01 trace]$ cd /tmp
[oracle@vddl-ocme1-rac-01 tmp]$ ls -ltr
total 17988
drwx------. 2 root root 40 Jun 2 11:29 hsperfdata_root
-rw-r--r--. 1 oracle oinstall 135548 Jun 13 15:52 dwh_test.log
drwxr-xr-x. 2 oracle oinstall 60 Jun 14 22:19 hsperfdata_oracle
-rw-r--r--. 1 oracle oinstall 1983 Jun 16 16:01 initbostonFS.ora <-------
-rw-r-----. 1 oracle oinstall 18268160 Jun 16 16:01 bostonFS.ctl
-rw-r-----. 1 oracle oinstall 7680 Jun 16 16:02 orapwboston

mv /tmp/initbostonFS.ora /tmp/initlondonFS.ora

mkdir -p /opt/oracle/oradata/londonFS/
mkdir -p /opt/oracle/oradata/londonFS/dev1/
mkdir -p /opt/oracle/fast_recovery_area/LONDONFS
mkdir -p /opt/oracle/fast_recovery_area/londonFS
mkdir -p /opt/oracle/admin/londonFS/adump

17.) Fix the /tmp/initlondonFS.ora

:%s/boston/london/g

please fix:

*.db_name='boston'
*.control_files='/opt/oracle/oradata/londonFS/londonFS01.ctl','/opt/oracle/fast_recovery_area/londonFS/londonFS02.ctl'
*.log_archive_config='dg_config=(boston,bostonFS,london,londonFS,london2)'
*.log_file_name_convert='boston','londonFS'
*.log_archive_dest_2='SERVICE=boston ASYNC REOPEN=15 valid_for=(STANDBY_LOGFILES,STANDBY_ROLE) db_unique_name=boston'
*.db_unique_name=londonFS
*.fal_server=london

18.) Copy controlfiles

[oracle@vddl-ocme1-rac-01 tmp]$ ls -tlr /tmp/*.ctl
-rw-r-----. 1 oracle oinstall 18268160 Jun 16 16:01 /tmp/bostonFS.ctl

cp /tmp/bostonFS.ctl /opt/oracle/oradata/londonFS/londonFS01.ctl
cp /tmp/bostonFS.ctl /opt/oracle/fast_recovery_area/londonFS/londonFS02.ctl

19.) Copy Passwordfile

[oracle@vddl-ocme1-rac-01 tmp]$ ls -ltr /tmp/orapw*
-rw-r-----. 1 oracle oinstall 7680 Jun 16 16:02 /tmp/orapwboston

cp /tmp/orapwboston $ORACLE_HOME/dbs/orapwlondonFS

19.) env variables

please include londonFS in /etc/oratab

. oraenv
londonFS

20.) Create spfile for londonFS
sqlplus / as sysdba
create spfile from pfile='/tmp/initlondonFS.ora';
startup mount;

21.) On standby Server:

. oraenv
london

sqlplus / as sysdba

SQL> show parameter log_archive_dest_2

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string

alter system set log_archive_dest_2='SERVICE=londonFS SYNC REOPEN=15 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=londonFS' scope=both;

Now the far sync for London database is done, this will be tested during the switchover tests.

 

Snapshot Databases in Oracle Database Appliance

 * Defining ORACLE_HOME:

[root@oda01 ~]# oakcli show dbhomes
Oracle Home Name      Oracle Home version                  Home Location
OraDb11204_home1      11.2.0.4.6(20299013,20420937)       /u01/app/oracle/product/11.2.0.4/dbhome_1
OraDb12102_home2      12.1.0.2.3(20299023,20299022)       /u01/app/oracle/product/12.1.0.2/dbhome_2
OraDb12102_home1      12.1.0.2.160719(23054246,23054327)  /u01/app/oracle/product/12.1.0.2/dbhome_1
root@oda01 ~]# oakcli show databases
DB01   RAC        ASM       OraDb12102_home1     /u01/app/oracle/product/12.1.0.2/dbhome_1          12.1.0.2.160719(23054246,23054327)
DB02   RAC        ASM       OraDb12102_home1     /u01/app/oracle/product/12.1.0.2/dbhome_1          12.1.0.2.160719(23054246,23054327)
 [grid@oda01 ~]$ asmcmd lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  NORMAL  N         512   4096  4194304   7372800  1478768           368640          555064              0             Y  DATA/
MOUNTED  NORMAL  N         512   4096  4194304   9796800  6419444           489840         2964802              0             N  RECO/
MOUNTED  HIGH    N         512   4096  4194304    763120   373600           381560           -2653              0             N  REDO/

* Create Test Database:

oakcli create database -db TSTSNAP -oh OraDb12102_home1
Pwd: oracle123
Please select one of the following for Database type  [1 .. 3] :
1    => OLTP
2    => DSS
3    => In-Memory
option: 1
Please select one of the following for Database Deployment  [1 .. 3] :
1    => EE : Enterprise Edition
2    => RACONE
3    => RAC
option: 3

Please select one of the following for Database Class  [1 .. 6] :
1    => odb-01s  (   1 cores ,     4 GB memory)
2    =>  odb-01  (   1 cores ,     8 GB memory)
3    =>  odb-02  (   2 cores ,    16 GB memory)
4    =>  odb-04  (   4 cores ,    32 GB memory)
5    =>  odb-06  (   6 cores ,    48 GB memory)
6    =>  odb-12  (  12 cores ,    96 GB memory)
option: 1
[root@oda01 ~]# oakcli show databases
DB01     RAC        ASM       OraDb12102_home1     /u01/app/oracle/product/12.1.0.2/dbhome_1          12.1.0.2.160719(23054246,23054327)
DB02     RAC        ASM       OraDb12102_home1     /u01/app/oracle/product/12.1.0.2/dbhome_1          12.1.0.2.160719(23054246,23054327)
TSTSNAP  RAC        ACFS      OraDb12102_home1     /u01/app/oracle/product/12.1.0.2/dbhome_1          12.1.0.2.160719(23054246,23054327) <---
 [root@oda01 ~]# srvctl config database -d TSTSNAP
Database unique name: TSTSNAP
Database name: TSTSNAP
Oracle home: /u01/app/oracle/product/12.1.0.2/dbhome_1
Oracle user: oracle
Spfile: /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/spfileTSTSNAP.ora
Password file: /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/orapwTSTSNAP
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools:
Disk Groups:
Mount point paths: /u01/app/oracle/oradata/datastore,/u02/app/oracle/oradata/datastore,/u01/app/oracle/fast_recovery_area/datastore
Services:
Type: RAC
Start concurrency:
Stop concurrency:
OSDBA group: dba
OSOPER group: racoper
Database instances: TSTSNAP1,TSTSNAP2
Configured nodes: oda01 ,oda02 
Database is administrator managed

—> Pre-Requisites to create a snpshot database

 https://docs.oracle.com/cd/E75550_01/doc.121/e79567/GUID-63DFD214-2B87-40A0-AE1B-C59805F0043E.htm#CMTXH-GUID-8B7849A5-1A3C-469D-9C90-12394364C980
    They must not be a standby or container database
    They must not be running in read-only mode, or in restricted mode, or in online backup mode
    They must be in ARCHIVELOG mode
    They must have all defined data files available and online
    They must not use centralized wallets with Transparent Data Encryption.

–> Archivelog Mode

 SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     3
Next log sequence to archive   4
Current log sequence           4

–> Size of DATABASE

create tablespace ts_test 
datafile '/u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/ts_test1.dbf' 
size 1g;
 col file_name format a100
select bytes/(1024*1024) mb, tablespace_name, file_name from dba_data_files;
         MB TABLESPACE_NAME                FILE_NAME
---------- ------------------------------ ----------------------------------------------------------------------------------------------------
       700 SYSTEM                         /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/o1_mf_system_dmlcolr5_.dbf
       600 SYSAUX                         /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/o1_mf_sysaux_dmlcp5g2_.dbf
       305 UNDOTBS1                       /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/o1_mf_undotbs1_dmlcplml_.dbf
       200 UNDOTBS2                       /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/o1_mf_undotbs2_dmlcq436_.dbf
         5 USERS                          /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/o1_mf_users_dmlcq8rx_.dbf
      1024 TS_TEST                        /u02/app/oracle/oradata/datastore/.ACFS/snaps/TSTSNAP/TSTSNAP/datafile/ts_test1.dbf
prompt "Total Size: "
select round(sum(bytes)/(1024*1024*1024),0) GB from
(select sum(bytes) bytes from dba_data_files
union
select sum(bytes) bytes from dba_temp_files);
        GB
----------
         3
 --> Populating the DB
 SQL> create user test identified by test default tablespace ts_test;
User created.
SQL> grant dba to test;
Grant succeeded.
create table test.tb1 as select * from dba_segments;
  1*  select segment_name, bytes / (1024*1024) mb, tablespace_name from dba_segments where segment_name='TB1'
SQL> /
SEGMENT_NAME                 MB TABLESPACE_NAME
-------------------- ---------- ------------------------------
TB1                         .75 TS_TEST
 declare
begin
for x in 1 .. 10 loop
  insert into test.tb1 select * from test.tb1;
end loop;
commit;
end;
/
  select segment_name, bytes / (1024*1024) mb, tablespace_name 
from dba_segments where segment_name='TB1'
SEGMENT_NAME                 MB TABLESPACE_NAME
-------------------- ---------- ------------------------------
TB1                         672 TS_TEST
 select round(sum(bytes)/(1024*1024*1024),2) GB
from dba_free_space;  2
         GB
----------
      1.21
1

—> Creating the Snapshot

Start Time: 2017-06-08 14:12:06
End Time  : 2017-06-08 14:29:22

oakcli create snapshotdb -db SNAP01 -from TSTSNAP
pwd: oracle123 (if the password doens't match try: welcome1)

Please select one of the following for Database Deployment  [1 .. 2] :
1    => RACONE
2    => RAC
Option: 2
Please select one of the following for Database Class  [1 .. 5] :
1    => odb-01s  (   1 cores ,     4 GB memory)
2    =>  odb-01  (   1 cores ,     8 GB memory)
3    =>  odb-02  (   2 cores ,    16 GB memory)
4    =>  odb-04  (   4 cores ,    32 GB memory)
5    =>  odb-06  (   6 cores ,    48 GB memory)
Option: 1
SUCCESS: 
All nodes in /opt/oracle/oak/temp_clunodes.txt are pingable and alive.
......
SUCCESS: All nodes in /opt/oracle/oak/temp_clunodes.txt are 
pingable and alive.
INFO: 2017-06-08 14:16:35: Creating the SNAP 
Database 'SNAP01' from the source Database 'TSTSNAP'
INFO: 2017-06-08 14:16:44: Do not perform any Structural change to 
Database 'TSTSNAP' till SNAP Database 'SNAP01' is created
INFO: 2017-06-08 14:17:05: Taking SNAP of the Database 'TSTSNAP'
INFO: 2017-06-08 14:17:10: Successfully took  the SNAP of database: TSTSNAP
INFO: 2017-06-08 14:20:53: Creating controlfile for database: SNAP01
INFO: 2017-06-08 14:21:39: Successfully created the control file for the database : SNAP01
INFO: 2017-06-08 14:21:39: Adding log files for the second thread for the database : SNAP01
INFO: 2017-06-08 14:21:46: Successfully added the log files for second thread
INFO: 2017-06-08 14:21:52: Recovering the database: SNAP01,  snapshot time : '2017-06-08:14:17:09' , until time : '2017-06-08:14:17:40'
INFO: 2017-06-08 14:21:55: Successfully recovered the database
INFO: 2017-06-08 14:21:55: Opening the database with resetlogs
INFO: 2017-06-08 14:22:26: Successfully opened the database after recovery
INFO: 2017-06-08 14:22:32: Setting the temporary tablespace for database : SNAP01
INFO: 2017-06-08 14:22:47: Successfully set the temporary tablespace for the database : SNAP01
INFO: 2017-06-08 14:23:32: Successfully changed the Database ID
INFO: 2017-06-08 14:25:17: Adding the Database resource to the clusterware
INFO: 2017-06-08 14:26:43: Successfully started the database
INFO: 2017-06-08 14:26:43: Updating the TNS entries for the database SNAP01
INFO: 2017-06-08 14:27:31: Successfully set the RMAN SNAPSHOT control file
INFO: 2017-06-08 14:27:44: Disabling the external references in the database 'SNAP01' inherited from 'TSTSNAP'
INFO: 2017-06-08 14:27:45: Successfully disabled the external references
INFO: 2017-06-08 14:28:08: Run the SQL script '/u01/app/oracle/product/12.1.0.2/dbhome_1/enable_external_refs_SNAP01_r_GY.sql' on the database 'SNAP01' to enable these external references
 Also need to restart the database after running the SQL script
SUCCESS: 2017-06-08 14:29:22: Successfully created the Database 'SNAP01' from 'TSTSNAP'
 2
[oracle@oda01 ~]$ srvctl config database -d SNAP01
Database unique name: SNAP01
Database name:
Oracle home: /u01/app/oracle/product/12.1.0.2/dbhome_1
Oracle user: oracle
Spfile: 
/u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/spfileSNAP01.ora
Password file: 
/u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/orapwSNAP01
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools:
Disk Groups:
Mount point paths: 
/u01/app/oracle/oradata/datastore,/u02/app/oracle/oradata/datastore,
/u01/app/oracle/fast_recovery_area/datastore
Services:
Type: RAC
Start concurrency:
Stop concurrency:
OSDBA group: dba
OSOPER group: racoper
Database instances: SNAP011,SNAP012
Configured nodes: oda01 ,oda02 
Database is administrator managed

. oraenv
SNAP011
 sqlplus / as sysdba
SQL> col file_name format a100
SQL> select bytes/(1024*1024) mb, tablespace_name, file_name 
from dba_data_files;
        MB TABLESPACE_NAME                FILE_NAME
---------- ------------------------------ ----------------------------------------------------------------------------------------------------
       700 SYSTEM                         /u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/datafile/o1_mf_system_dmlcolr5_.dbf
       600 SYSAUX                         /u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/datafile/o1_mf_sysaux_dmlcp5g2_.dbf
       305 UNDOTBS1                       /u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/datafile/o1_mf_undotbs1_dmlcplml_.dbf
       200 UNDOTBS2                       /u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/datafile/o1_mf_undotbs2_dmlcq436_.dbf
         5 USERS                          /u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/datafile/o1_mf_users_dmlcq8rx_.dbf
      1024 TS_TEST                        /u02/app/oracle/oradata/datastore/.ACFS/snaps/SNAP01/SNAP01/datafile/ts_test1.dbf
SQL> select round(sum(bytes)/(1024*1024*1024),0) GB from
(select sum(bytes) bytes from dba_data_files
union
select sum(bytes) bytes from dba_temp_files);
        GB
----------
         3
 ---> Creating the Snapshot from previous Snapshot
Start Time: 2017-06-08 14:41:18
End Time  : 2017-06-08 14:54:10
 oakcli create snapshotdb -db SNAP02 -from SNAP01
pwd: welcome1
*** Note: on this case i changed the type of the database to RACONE
[root@oda01 ~]# oakcli create snapshotdb -db SNAP02 -from SNAP01
INFO: 2017-06-08 14:41:18: Please check the logfile  
'/opt/oracle/oak/log/oda01/tools/12.1.2.8.0/createdb_SNAP02_61544.log' for more details
 Please enter the 'SYS'  password for the Database SNAP01:
Please re-enter the 'SYS' password:
Please select one of the following for Database Deployment  [1 .. 2] :
1    => RACONE
2    => RAC
1
The selected value is : RACONE
Please select one of the following for Database Class  [1 .. 5] :
1    => odb-01s  (   1 cores ,     4 GB memory)
2    =>  odb-01  (   1 cores ,     8 GB memory)
3    =>  odb-02  (   2 cores ,    16 GB memory)
4    =>  odb-04  (   4 cores ,    32 GB memory)
5    =>  odb-06  (   6 cores ,    48 GB memory)
1
The selected value is : odb-01s  (   1 cores ,     4 GB memory)
......
SUCCESS: 
All nodes in /opt/oracle/oak/temp_clunodes.txt are pingable and alive.
......
SUCCESS: 
All nodes in /opt/oracle/oak/temp_clunodes.txt are pingable and alive.
INFO: 2017-06-08 14:44:13: 
Creating the SNAP Database 'SNAP02' from the source Database 'SNAP01'
INFO: 2017-06-08 14:44:22: 
Do not perform any Structural change to Database 'SNAP01' till SNAP Database 'SNAP02' is created
INFO: 2017-06-08 14:44:42: 
Taking SNAP of the Database 'SNAP01'
INFO: 2017-06-08 14:44:47: 
Successfully took  the SNAP of database: SNAP01
INFO: 2017-06-08 14:45:35: 
Creating controlfile for database: SNAP02
INFO: 2017-06-08 14:46:40: 
Successfully created the control file for the database : SNAP02
INFO: 2017-06-08 14:46:46: 
Recovering the database: SNAP02,  snapshot time : '2017-06-08:14:44:47' , until time : '2017-06-08:14:44:57'
INFO: 2017-06-08 14:46:49: Successfully recovered the database
INFO: 2017-06-08 14:46:49: Opening the database with resetlogs
INFO: 2017-06-08 14:47:20: Successfully opened the database after recovery
INFO: 2017-06-08 14:47:25: Setting the temporary tablespace for database : SNAP02
INFO: 2017-06-08 14:47:33: Successfully set the temporary tablespace for the database : SNAP02
INFO: 2017-06-08 14:48:19: Successfully changed the Database ID
INFO: 2017-06-08 14:49:56: Adding the Database resource to the clusterware
INFO: 2017-06-08 14:51:40: Successfully started the database
INFO: 2017-06-08 14:51:46: Updating the TNS entries for the database SNAP02
INFO: 2017-06-08 14:52:27: Successfully set the RMAN SNAPSHOT control file
INFO: 2017-06-08 14:52:38: 
Disabling the external references in the database 'SNAP02' inherited from 'SNAP01'
INFO: 2017-06-08 14:52:39: Successfully disabled the external references
INFO: 2017-06-08 14:53:07: 
Run the SQL script '/u01/app/oracle/product/12.1.0.2/dbhome_1/enable_external_refs_SNAP02_wpY9.sql' on the database 'SNAP02' to enable these external references
 Also need to restart the database after running the SQL script
SUCCESS: 2017-06-08 14:54:10: 
Successfully created the Database 'SNAP02' from 'SNAP01'
 3

 

Please note that the second snapshot took 30% less of the used storage, this is because that only changed blocks are copied during the process.