Restore tablespace USERS doesn't work. Oracle backup

余生颓废 提交于 2020-12-15 03:53:04

问题


I created a schema and my_table_test;

ALTER SESSION SET CURRENT_SCHEMA=c##wojtek_admin; 

CREATE TABLE my_table_test
( id_test INT 
);

Then I created a backup using: BACKUP TABLESPACE USERS FORMAT 'c:\FRA\users%u'; Then I dropped my_table_test and run below commands:

RMAN> RUN{
2> SQL 'ALTER TABLESPACE USERS OFFLINE';
3> RESTORE TABLESPACE USERS;
4> RECOVER TABLESPACE USERS;
5> SQL 'ALTER TABLESPACE USERS ONLINE';
6> }

Why my_table_test is dropped after I restored USERS TABLESPACE?


回答1:


In a multitenant database you will have several 'USERS' tablespaces. One at the CDB level and one for each PDB.

RMAN> report schema;

Report of database schema for database with db_unique_name T101N

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    960      SYSTEM               YES     +DATAC4/T101N/DATAFILE/system.500.1057688607
3    620      SYSAUX               NO      +DATAC4/T101N/DATAFILE/sysaux.498.1057688643
4    840      UNDOTBS1             YES     +DATAC4/T101N/DATAFILE/undotbs1.587.1057688657
5    310      PDB$SEED:SYSTEM      NO      +DATAC4/T101N/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.482.1057689319
6    380      PDB$SEED:SYSAUX      NO      +DATAC4/T101N/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.503.1057689319
7    5        USERS                NO      +DATAC4/T101N/DATAFILE/users.499.1057688659
8    190      PDB$SEED:UNDOTBS1    NO      +DATAC4/T101N/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.489.1057689319
9    310      PDB1:SYSTEM          YES     +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/system.405.1057690077
10   390      PDB1:SYSAUX          NO      +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/sysaux.501.1057690077
11   195      PDB1:UNDOTBS1        YES     +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/undotbs1.497.1057690077
12   5        PDB1:USERS           NO      +DATAC4/T101N/B52F60948095635FE053B506330A63CA/DATAFILE/users.566.1057690091

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    67       TEMP                 32767       +DATAC4/T101N/TEMPFILE/temp.573.1057688719
2    43       PDB$SEED:TEMP        32767       +DATAC4/T101N/B52F34797E9D6750E053B506330AE7C0/TEMPFILE/temp.481.1057689337
3    43       PDB1:TEMP            32767       +DATAC4/T101N/B52F60948095635FE053B506330A63CA/TEMPFILE/temp.496.1057690079

Note! RMAN's best feature. RMAN can actually tell you what to do in different scenarios.

# data recovery advisor (DRA)
list failure all;
advise failure;
repair failure preview;
repair failure;



回答2:


First, it's important to note that it looks like you're using a Multitenant Database but you've decided to put user data inside the root container, this is generally a bad idea - you should be using a Pluggable Database for pretty much everything (this will also mean you don't need to prefix your usernames with C##.

Your restore and recover statements will recover the tablespace up until now. If you want to recover it to before you dropped the tablespace then Oracle will also need to do some work on the system tablespace (for the data dictionary) - but you don't only want to restore and recover your USERS tablespace. You'd need to restore your backup somewhere else, recover it to the desired point, then take the USERS tablespace and put it back into your original database.

This is simply referred to as Tablespace Point In Time Recovery, Oracle has helpfully done all the hard scripting work for you, but you should read what's going on https://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmtspit.htm#BRADV89790

RECOVER TABLESPACE users
  UNTIL ?
  AUXILIARY DESTINATION '?';

(Once you've read the docs you'll see how to fill this out).

There is also the ability to do this easily at a table level, so if you want to only recover that dropped table and not revert everything else in that tablespace, you could:

RECOVER TABLE c##wojtek_admin.my_table_test
UNTIL ?
AUXILIARY DESTINATION '?'  ;

See https://oracle-base.com/articles/12c/rman-table-point-in-time-recovery-12cr1 for further details.



来源:https://stackoverflow.com/questions/65055733/restore-tablespace-users-doesnt-work-oracle-backup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!