ORACLE如何查看用户管理备份与恢复的记录
在Oracle数据库中,如果我们使用用户管理备份与恢复(User-Managed Backup and Recovery)方式去备份还原数据库的话,如何获取用户管理备份与恢复的记录信息呢?例如,我要查看某个数据库实例做用户管理备份的记录。一般使用下面脚本。似乎用户管理备份比较“简单”,目前我查了相关资料,只看到v$backup记录相关信息。而且这个系统试图只能查看最后一次用户管理备份的记录信息。看不到相关历史记录信息。可能是这种备份与还原方式较少使用的缘故。
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
set linesize 640;
set pagesize 60;
col change# for 999999999999999999;
select * from v$backup;
在测试环境,我使用用户管理备份与恢复这种方式还原了整个数据库,然后我查看用户管理备份的还原记录信息如下所示:
SQL> COL resetlogs_change# FOR 999999999999999;
SQL> SELECT incarnation#
2 ,resetlogs_change#
3 ,TO_CHAR(resetlogs_time, 'yyyy-mm-dd hh24:mi:ss') db_restored_time
4 ,resetlogs_change#
5 --,scn_to_timestamp(resetlogs_change#) db_recovery_till_time
6 FROM v$database_incarnation
7 WHERE resetlogs_change# !=
8 (SELECT MIN(resetlogs_change#) FROM v$database_incarnation
9 );
INCARNATION# RESETLOGS_CHANGE# DB_RESTORED_TIME RESETLOGS_CHANGE#
------------ ----------------- ------------------- -----------------
2 1018536 2022-03-24 14:17:37 1018536
3 15765877865306 2023-04-07 08:59:51 15765877865306
SQL> SELECT incarnation#
2 ,resetlogs_change#
3 ,TO_CHAR(resetlogs_time, 'yyyy-mm-dd hh24:mi:ss') db_restored_time
4 ,scn_to_timestamp(resetlogs_change#) db_recovery_till_time
5 FROM v$database_incarnation
6 WHERE resetlogs_change# !=
7 (SELECT MIN(resetlogs_change#) FROM v$database_incarnation
8 );
,scn_to_timestamp(resetlogs_change#) db_recovery_till_time
*
ERROR at line 4:
ORA-08181: specified number is not a valid system change number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1
SQL>
如上所示,虽然可以看到用户管理的还原的时间点,但是查看还原那个时间点是报ORA-08181错误。我是使用下面脚本恢复的。
recover database using backup controlfile until time '2023-03-29 15:59:05';
其实我们可以用下面脚本查询用户管理备份/还原的记录,如下所示:
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> set linesize 640;
SQL> set pagesize 60;
SQL> col units for a30;
SQL> col item for a24;
SQL> col type for a16;
SQL> col units for a12;
SQL> col comments for a16;
SQL> col con_id for 999999;
SQL> select * from v$recovery_progress;
START_TIME TYPE ITEM UNITS SOFAR TOTAL TIMESTAMP COMMENTS CON_ID
------------------- ---------------- ------------------------ ------------ ---------- ---------- ------------------- ---------------- -------
2023-04-07 08:56:39 Media Recovery Log Files Files 9 9 0
2023-04-07 08:56:39 Media Recovery Active Apply Rate KB/sec 3196 3196 0
2023-04-07 08:56:39 Media Recovery Average Apply Rate KB/sec 3582 3582 0
2023-04-07 08:56:39 Media Recovery Maximum Apply Rate KB/sec 4531 4531 0
2023-04-07 08:56:39 Media Recovery Redo Applied Megabytes 664 664 0
2023-04-07 08:56:39 Media Recovery Recovery ID RCVID 0 0 RCVID: 0
2023-04-07 08:56:39 Media Recovery Last Applied Redo SCN+Time 0 0 2023-03-29 15:59:05 SCN: 15765877865 0
305
2023-04-07 08:56:39 Media Recovery Active Time Seconds 186 186 0
2023-04-07 08:56:39 Media Recovery Apply Time per Log Seconds 12 12 0
2023-04-07 08:56:39 Media Recovery Checkpoint Time per Log Seconds 8 8 0
2023-04-07 08:56:39 Media Recovery Elapsed Time Seconds 190 190 0
11 rows selected.
SQL>