Menu

Friday, November 13, 2020

Using Restore Points in Standard Edition (SE2)

Restore points and Flashback database are related data protection features introduced in Oracle 10g release that enable you to rewind data back in time to correct any problems caused by logical data corruption or user errors within a designated time window.

But what if you have Standard Edition database:

SQL> select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production

SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-00439: feature not enabled: Flashback Database

In Standard Edition we dont have Flashback Database feature, but you can still create restore points and perform incomplete recovery to a restore point.

For this test we need to have a backup already taken, also database must be running in archivelog mode:

SQL> create restore point RP_TEST_AFTER_BACKUP;

Restore point created.

SQL> select scn, to_char(time,'dd.mm.yyyy hh24:mi:ss') time, name from v$restore_point;

       SCN TIME 	       NAME
---------- ------------------- ------------------------------
    930727 26.08.2020 17:03:01 RP_TEST_AFTER_BACKUP

As we can see that restore point is associated with SCN of the database.

Now you can perform potentially dangerous operations like database upgrades, tablespace deletion, truncating data and so on.

In our particular case we are going to create a new tablespace:

SQL> create tablespace test_tbs datafile size 64M;

Tablespace created.

SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
TEST_TBS <<--

6 rows selected.

Let´s imagine we had some problems and want to "rewind" database to back to the restore point. On Enterprise Edition we would perform flashback database to restore point but in SE2 we will use different approach.

Shutdown database and startup mount.

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

SQL> startup mount
ORACLE instance started.

Total System Global Area 1157627168 bytes
Fixed Size		    8895776 bytes
Variable Size		  385875968 bytes
Database Buffers	  754974720 bytes
Redo Buffers		    7880704 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.8.0.0.0

Perform restore and recover database until restore point RP_TEST_AFTER_BACKUP.

[oracle@srv1 dbhome_1]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Wed Sep 2 17:09:56 2020
Version 19.8.0.0.0

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

connected to target database: STXTEST (DBID=3165137538, not open)

RMAN> list restore point all;

using target database control file instead of recovery catalog
SCN              RSP Time  Type       Time      Name
---------------- --------- ---------- --------- ----
930727                                26-AUG-20 RP_TEST_AFTER_BACKUP

RMAN> restore database until restore point RP_TEST_AFTER_BACKUP;

Starting restore at 02-SEP-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=296 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /srv/oradata/STXTEST/datafile/o1_mf_system_hndg669o_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /srv/oradata/STXTEST/datafile/o1_mf_sysaux_hndg6c8j_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /srv/oradata/STXTEST/datafile/o1_mf_undotbs1_hndg6h73_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /srv/oradata/STXTEST/datafile/o1_mf_users_hndg6r07_.dbf
channel ORA_DISK_1: reading from backup piece /srv/fra/STXTEST/backupset/2020_08_26/o1_mf_nnndf_TAG20200826T165909_hndq4x5k_.bkp
channel ORA_DISK_1: piece handle=/srv/fra/STXTEST/backupset/2020_08_26/o1_mf_nnndf_TAG20200826T165909_hndq4x5k_.bkp tag=TAG20200826T165909
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 02-SEP-20

RMAN> recover database until restore point RP_TEST_AFTER_BACKUP;

Starting recover at 02-SEP-20
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 19 is already on disk as file /srv/fra/STXTEST/archivelog/2020_08_26/o1_mf_1_19_hndq5pdq_.arc
archived log for thread 1 with sequence 20 is already on disk as file /srv/fra/STXTEST/archivelog/2020_08_26/o1_mf_1_20_hndqh2yg_.arc
archived log file name=/srv/fra/STXTEST/archivelog/2020_08_26/o1_mf_1_19_hndq5pdq_.arc thread=1 sequence=19
archived log file name=/srv/fra/STXTEST/archivelog/2020_08_26/o1_mf_1_20_hndqh2yg_.arc thread=1 sequence=20
media recovery complete, elapsed time: 00:00:00
Finished recover at 02-SEP-20

We have to open the database with resetlogs option.

RMAN> alter database open resetlogs;

Statement processed

RMAN> exit

Recovery Manager complete.

Final check.

SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS

We put back database to state that existed before RP_TEST_AFTER_BACKUP restore point is created. This is an example of incomplete recovery and a restore point was used just to choose a point in time.

No comments:

Post a Comment