ORACLE数据库灾难恢复

一:RMAN恢复

.1 创建测试用户,授权,分配测试表空间,给测试数据
–创建测试用户:
SQL> alter session set container=PRODPDB;

Session altered.

SQL>
SQL> show con_name;

CON_NAME

PRODPDB

SQL> create user pdbwjh identified by pdbwjh;

User created.

–授权:

参考

https://blog.51cto.com/u_13631369/6252422

二:Expdp逻辑恢复

三:闪回恢复

3.1 查看闪回区状态及信息

archive log list;
select open_mode,flashback_on from v$database; 查看是否开启归档
show parameter db_recovery;
show parameter flashback; 查看闪回区信息

ORACLE数据库灾难恢复_第1张图片

修改归档路径和归档大小

SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flashback_area' scope =both;
System altered.
SQL> alter system set db_recovery_file_dest_size=30g scope=spfile;
System altered.
SQL> alter system set db_flashback_retention_target=10080 scope=both;
System altered.

检查flash recovery area的使用情况,查看archivelog

SQL> set linesize 200
SQL> set pagesize 80
SQL> 
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;

FILE_TYPE        PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES     CON_ID
----------------------- ------------------ ------------------------- --------------- ----------
CONTROL FILE                 0               0           0          0
REDO LOG                 0               0           0          0
ARCHIVED LOG                 0               0           0          0
BACKUP PIECE                   .06               0           1          0
IMAGE COPY                 0               0           0          0
FLASHBACK LOG                   1.3               0           2          0
FOREIGN ARCHIVED LOG             0               0           0          0
AUXILIARY DATAFILE COPY          0               0           0          0

8 rows selected.

ORACLE数据库灾难恢复_第2张图片

3.2 根据时间闪回

3.21创建测试表

创建工资表
create table salgrade(
	grade numeric,
	losal numeric,
	hisal numeric
);

插入数据
insert into salgrade values(1,700,1200);
insert into salgrade values (2, 1201, 1400);
insert into salgrade values (3, 1401, 2000);
insert into salgrade values (4, 2001, 3000);
insert into salgrade values (5, 3001, 9999);

创建emp员工表
CREATE TABLE EMP(
	EMPNO NUMBER(4) NOT NULL,
	ENAME VARCHAR2(10),
	JOB VARCHAR2(9),
	MGR NUMBER(4),
	HIREDATE DATE,
	SAL NUMBER(7, 2),
	COMM NUMBER(7, 2),
	DEPTNO NUMBER(2)
);
插入数据INSERT INTO EMP VALUES (7369, 'SMITH', 'CLERK', 7902,
'17-12月-1980', 800, NULL, 20);
INSERT INTO EMP VALUES (7499, 'ALLEN', 'SALESMAN', 7698,
'20-2月-1981', 1600, 300, 30);
INSERT INTO EMP VALUES (7521, 'WARD', 'SALESMAN', 7698,
'22-2月-1981',  1250, 500, 30);
INSERT INTO EMP VALUES (7566, 'JONES', 'MANAGER', 7839,
'2-4月-1981', 2975, NULL, 20);
INSERT INTO EMP VALUES (7654, 'MARTIN', 'SALESMAN', 7698,
'28-9月-1981',  1250, 1400, 30);
INSERT INTO EMP VALUES (7698, 'BLAKE', 'MANAGER', 7839,
'1-5月-1981', 2850, NULL, 30);
INSERT INTO EMP VALUES (7782, 'CLARK', 'MANAGER', 7839,
'9-6月-1981',  2450, NULL, 10);
INSERT INTO EMP VALUES (7788, 'SCOTT', 'ANALYST', 7566,
'09-12月-1982',  3000, NULL, 20);
INSERT INTO EMP VALUES (7839, 'KING', 'PRESIDENT', NULL,
'17-11月-1981',5000, NULL, 10);
INSERT INTO EMP VALUES (7844, 'TURNER', 'SALESMAN', 7698,
'8-9月-1981',  1500, 0, 30);
INSERT INTO EMP VALUES (7876, 'ADAMS', 'CLERK', 7788,
'12-1月-1983',  1100, NULL, 20);
INSERT INTO EMP VALUES (7900, 'JAMES', 'CLERK', 7698,
'3-12月-1981', 950, NULL, 30);
INSERT INTO EMP VALUES (7902, 'FORD', 'ANALYST', 7566,
'3-12月-1981', 3000, NULL, 20);
INSERT INTO EMP VALUES (7934, 'MILLER', 'CLERK', 7782,
'23-1月-1982', 1300, NULL, 10);

闪回报错
ERROR at line 1:
ORA-08189: 因为未启用行移动功能, 不能闪回表
解决
alter table salgrade enable row movement;

3.3 根据SCN号闪回

参考

https://www.modb.pro/db/454178
https://www.cnblogs.com/Memory-Python/p/10837023.html
https://blog.csdn.net/wanghui5767260/article/details/20993843
https://www.cnblogs.com/CHLL55/p/13674330.html

你可能感兴趣的:(oracle,数据库)