You are on page 1of 7

login as: oracle

oracle@192.168.1.120's password:
Last login: Sat Oct 10 14:44:16 2020 from 192.168.1.108
[oracle@oracle ~]$
[oracle@oracle ~]$ lsnrctl strt
^C
[oracle@oracle ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 10-OCT-2020 19:47:32

Copyright (c) 1991, 2016, Oracle. All rights reserved.

Starting /u01/app/oracle/product/12.2.0.1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production


System parameter file is
/u01/app/oracle/product/12.2.0.1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle.localdomain)
(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle.localdomain)
(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 10-OCT-2020 19:47:36
Uptime 0 days 0 hr. 0 min. 2 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File
/u01/app/oracle/product/12.2.0.1/network/admin/listener.ora
Listener Log File
/u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle.localdomain)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "ORCL" has 1 instance(s).
Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sat Oct 10 19:47:46 2020

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1157627904 bytes


Fixed Size 8619936 bytes
Variable Size 436209760 bytes
Database Buffers 704643072 bytes
Redo Buffers 8155136 bytes
Database mounted.
Database opened.
SQL>
login as: oracle
oracle@192.168.1.120's password:
Last login: Sat Oct 10 21:13:31 2020
[oracle@oracle ~]$
[oracle@oracle ~]$
[oracle@oracle ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 10-OCT-2020 21:17:13

Copyright (c) 1991, 2016, Oracle. All rights reserved.

TNS-01106: Listener using listener name LISTENER has already been started
[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sat Oct 10 21:17:19 2020

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select flashback_on from v$database;

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

SQL> show parameter db_recovery_file_dest;

NAME TYPE VALUE


------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/fast_recovery_
area/orcl
db_recovery_file_dest_size big integer 8016M
SQL>
SQL>
SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area';

System altered.

SQL>
SQL>
SQL> alter system set db_recovery_file_dest_size=8G;

System altered.

SQL>
SQL> show parameter db_recovery_file_dest;

NAME TYPE VALUE


------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/fast_recovery_
area/orcl
db_recovery_file_dest_size big integer 8G
SQL>
SQL>
SQL> show parameter retention

NAME TYPE VALUE


------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440 <-------it is in minute and
total 1 day
undo_retention integer 900 <---this is also in minute
SQL>

SQL> alter system set db_flashback_retention_target=2880; <---now it is in 2day

System altered.

SQL>
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 5
Current log sequence 5
SQL> alter database flashback on;

Database altered.

SQL> select flashback_on from v$database;

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

SQL>
SQL>
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit
Production
[oracle@oracle ~]$
[oracle@oracle ~]$ cd /u01/app/oracle/
[oracle@oracle oracle]$
[oracle@oracle oracle]$ ll
total 8
drwxr-x---. 3 oracle oinstall 18 Sep 16 00:23 admin
drwxr-x---. 3 oracle oinstall 18 Sep 16 00:30 audit
drwxr-xr-x. 5 oracle oinstall 47 Aug 2 18:40 cfgtoollogs
drwxr-xr-x. 2 oracle oinstall 6 Aug 2 18:51 checkpoints
drwxrwxr-x. 21 oracle oinstall 4096 Aug 2 18:22 diag
drwxr-x---. 3 oracle oinstall 18 Sep 16 00:23 fast_recovery_area
drwxr-x---. 4 oracle oinstall 30 Sep 16 00:24 oradata
drwxr-xr-x. 3 oracle oinstall 22 Aug 2 18:09 product
drwxr-x---. 3 oracle oinstall 18 Sep 16 00:17 recovery_area
drwxr-xr-x. 2 oracle oinstall 4096 Oct 8 22:00 rman_bkp
drwxr-xr-x. 5 root root 71 Aug 2 18:25 tfa
[oracle@oracle oracle]$ cd fast_recovery_area/
[oracle@oracle fast_recovery_area]$ ll
total 0
drwxr-x---. 3 oracle oinstall 18 Sep 16 00:23 orcl
[oracle@oracle fast_recovery_area]$ cd orcl/
[oracle@oracle orcl]$ ll
total 0
drwxr-x---. 6 oracle oinstall 77 Oct 10 21:23 ORCL
[oracle@oracle orcl]$ cd ORCL/
[oracle@oracle ORCL]$ ll
total 0
drwxr-x---. 5 oracle oinstall 60 Oct 10 00:58 archivelog
drwxr-x---. 2 oracle oinstall 33 Oct 8 21:49 controlfile
drwxr-x---. 2 oracle oinstall 60 Oct 10 21:24 flashback
drwxr-x---. 2 oracle oinstall 93 Oct 8 21:59 onlinelog
[oracle@oracle ORCL]$ cd flashback/
[oracle@oracle flashback]$ ll
total 409620
-rw-r-----. 1 oracle oinstall 209723392 Oct 10 21:26 o1_mf_hr3njc95_.flb <------log
file will generate here
-rw-r-----. 1 oracle oinstall 209723392 Oct 10 21:24 o1_mf_hr3njyrz_.flb
[oracle@oracle flashback]$ date
Sat Oct 10 21:26:29 +06 2020
[oracle@oracle flashback]$

----------------------------------------------------------------------------

Scenerio 1
----------------------------------------------------------------------------

Go to SQLDEVELOPER as HR:
---------------------------
SELECT current_scn, SYSTIMESTAMP FROM v$database;

SELECT * FROM user_constraints WHERE table_name='EMPLOYEES';

SELECT 'alter table '||A.OWNER||'.'||A.table_name||' disable constraint '||


A.constraint_name||';'
FROM all_constraints A, all_constraints b
WHERE A.constraint_type = 'R'
AND A.r_constraint_name = b.constraint_name
AND A.r_owner = b.OWNER
AND b.table_name = 'EMPLOYEES';

ALTER TABLE hr.employees DISABLE CONSTRAINT EMP_MANAGER_FK;


ALTER TABLE hr.departments DISABLE CONSTRAINT DEPT_MGR_FK;
ALTER TABLE hr.job_history DISABLE CONSTRAINT JHIST_EMP_FK;

TRUNCATE TABLE employees;

SELECT * FROM employees;

SELECT 'alter table '||A.OWNER||'.'||A.table_name||' disable constraint '||


A.constraint_name||';'
FROM all_constraints A, all_constraints b
WHERE A.constraint_type = 'R'
AND A.r_constraint_name = b.constraint_name
AND A.r_owner = b.OWNER
AND b.table_name = 'DEPARTMENTS';

SELECT * FROM user_constraints WHERE table_name='DEPARTMENTS';

ALTER TABLE hr.employees DISABLE CONSTRAINT EMP_DEPT_FK;


ALTER TABLE hr.job_history DISABLE CONSTRAINT JHIST_DEPT_FK;

TRUNCATE TABLE departments;

SELECT * FROM departments;

Go to SQLDEVELOPER as sys:
-------------------------------------

select to_char(oldest_flashback_time,'DD-MM-YYYY HH24:MI:SS')


oldest_flashback_time,
oldest_flashback_scn from v$flashback_database_log;

OLDEST_FLASHBACK_TIME OLDEST_FLASHBACK_SCN
--------------------- ---------------------

10-10-2020 21:24:12 2142497

Go to sqlplus as sys:
--------------------------

[oracle@oracle ~]$ rman target /

Recovery Manager: Release 12.2.0.1.0 - Production on Sat Oct 10 22:44:49 2020

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

connected to target database: ORCL (DBID=1579011246)

RMAN>
RMAN> shutdown immediate

using target database control file instead of recovery catalog


database closed
database dismounted
Oracle instance shut down

RMAN> startup mount

connected to target database (not started)


Oracle instance started
database mounted

Total System Global Area 1157627904 bytes


Fixed Size 8619936 bytes
Variable Size 369100896 bytes
Database Buffers 771751936 bytes
Redo Buffers 8155136 bytes

RMAN>

RMAN>

FLASHBACK DATABASE TO TIME = "TO_DATE('10-10-2020 21:24:12','YYYY-MM-DD


HH24:MI:SS')";
RMAN>
RMAN>

Starting flashback at 10-OCT-20


allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 device type=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of flashback command at 10/10/2020 22:55:37
ORA-00907: missing right parenthesis

RMAN> FLASHBACK DATABASE TO TIME = "TO_DATE('2020-10-10 21:24:12','YYYY-MM-DD


HH24:MI:SS')";

Starting flashback at 10-OCT-20


using channel ORA_DISK_1

starting media recovery


media recovery failed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of flashback command at 10/10/2020 22:56:42
ORA-38795: WARNING: FLASHBACK DATABASE succeeded but OPEN RESETLOGS would fail
ORA-01196: file 1 is inconsistent due to a failed media recovery session
ORA-01110: data file 1:
'/u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_hqyfcs89_.dbf'

RMAN> alter database open resetlogs;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of sql statement command at 10/10/2020 23:00:11
ORA-01196: file 1 is inconsistent due to a failed media recovery session
ORA-01110: data file 1:
'/u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_hqyfcs89_.dbf'

RMAN> FLASHBACK DATABASE TO TIME = "TO_DATE('2020-10-10 21:25:00','YYYY-MM-DD


HH24:MI:SS')";

Starting flashback at 10-OCT-20


using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished flashback at 10-OCT-20

RMAN> alter database open resetlogs;

Statement processed

RMAN>

Go to SQLDEVELOPER AS HR:
-----------------------------

select * from employees;

select * from departments;

You might also like