DMU 以及后期flashback 回退

news/2024/11/27 2:09:57/

DMU作为数据库字符集的转换工具,在转换后可能需要回退。这时可以结合oralce的flash back database 

Step 1:
Enable Archiving( Ignore this if your database is already in archive log mode and archive log is enabled):

CONN / AS SYSDBA
ALTER SYSTEM SET log_archive_dest_1='location=/xxx/db/fast_recovery_area/' SCOPE=SPFILE;
ALTER SYSTEM SET log_archive_format='ARC%S_%R.%T' SCOPE=SPFILE;
SHUTDOWN IMMEDIATE
STARTUP MOUNT
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

Step 2:
Turn on Flashback:

CONN / AS SYSDBA
SHUTDOWN IMMEDIATE
STARTUP MOUNT EXCLUSIVE
ALTER DATABASE FLASHBACK ON;
ALTER DATABASE OPEN;

Alert log entries shows

Sat Nov 22 15:55:45 2014
ALTER DATABASE MOUNT
Successful mount of redo thread 1, with mount id 4290008961
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: ALTER DATABASE MOUNT <<<<<<<<<<
Sat Nov 22 15:55:51 2014
ALTER DATABASE FLASHBACK ON <<<<<<<<<<<<<<<<<<
Starting background process RVWR
Sat Nov 22 15:55:51 2014
RVWR started with pid=20, OS id=24951
Allocated 4194304 bytes in shared pool for flashback generation buffer
Flashback Database Enabled at SCN 1005507
Completed: ALTER DATABASE FLASHBACK ON <<<<<<<<<<<<
ALTER DATABASE OPEN <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Sat Nov 22 15:55:57 2014
LGWR: STARTING ARCH PROCESSES
...
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Database Characterset is WE8MSWIN1252 <<<<<<<<<<<<<<<<<<<<<<<
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Sat Nov 22 15:55:59 2014 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
QMNC started with pid=25, OS id=24961
Completed: ALTER DATABASE OPEN <<<<<<<<<<<<<<< Sat Nov 22 15:55:59 2014

Step 3:
create new user and data for testing flashback:

conn / as sysdba
grant connect,resource to test identified by test;

CONN test/test

CREATE TABLE flash_test (
id NUMBER(10)
);
insert into flash_test values(5);
commit;

Step 4:
check the character set (in our example: WE8MSWIN1252)

select parameter,value from NLS_DATABASE_PARAMETERS where parameter='NLS_CHARACTERSET';

This shows:
NLS_CHARACTERSET WE8MSWIN1252

select distinct(nls_charset_name(charsetid)) CHARACTERSET,
decode(type#, 1, decode(charsetform, 1, 'VARCHAR2', 2, 'NVARCHAR2','UNKNOWN'),
9, decode(charsetform, 1, 'VARCHAR', 2, 'NCHAR VARYING', 'UNKNOWN'),
96, decode(charsetform, 1, 'CHAR', 2, 'NCHAR', 'UNKNOWN'),
8, decode(charsetform, 1, 'LONG', 'UNKNOWN'),
112, decode(charsetform, 1, 'CLOB', 2, 'NCLOB', 'UNKNOWN')) TYPES_USED_IN
from sys.col$ where charsetform in (1,2) and type# in (1, 8, 9, 96, 112)
order by CHARACTERSET, TYPES_USED_IN;

CHARACTERSET TYPES_USED_IN
---------------------------------------- -------------
AL16UTF16 NCHAR
AL16UTF16 NCLOB
AL16UTF16 NVARCHAR2
WE8MSWIN1252 CHAR
WE8MSWIN1252 CLOB
WE8MSWIN1252 LONG
WE8MSWIN1252 VARCHAR2

Step 5:
Again connect in other session and check the data

CONN test/test
select * from flash_test;

ID
----
5

Step 6:
create restore point as name before_change:

conn / as sysdba
CREATE RESTORE POINT before_change;

SQL> select SCN, NAME from V$RESTORE_POINT;

SCN NAME
---------- --------------------
1005826 BEFORE_CHANGE

or use below query
select SCN, DATABASE_INCARNATION#, RESTORE_POINT_TIME,NAME from V$RESTORE_POINT;

Step 7:
Drop table: So after creating restore point we are dropping the table, so when you flashback to the restore point you will get back the table and data

SQL> conn test/test
Connected.
SQL> select * from flash_test;

ID
----------
5

SQL> drop table flash_test;

Table dropped.

SQL> select * from flash_test;
select * from flash_test
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> desc flash_test;
ERROR:
ORA-04043: object flash_test does not exist


SQL> show user
USER is "TEST"
SQL> 

Step 8:
Now you can change the characterset using DMU to AL32UTF8:
Note 1272374.1  The Database Migration Assistant for Unicode (DMU) Tool

Once you have completed the characterset conversion to AL32UTF8 using DMU tool, then run

select parameter,value from NLS_DATABASE_PARAMETERS;

This now shows:
NLS_CHARACTERSET AL32UTF8

select distinct(nls_charset_name(charsetid)) CHARACTERSET,
decode(type#, 1, decode(charsetform, 1, 'VARCHAR2', 2, 'NVARCHAR2','UNKNOWN'),
9, decode(charsetform, 1, 'VARCHAR', 2, 'NCHAR VARYING', 'UNKNOWN'),
96, decode(charsetform, 1, 'CHAR', 2, 'NCHAR', 'UNKNOWN'),
8, decode(charsetform, 1, 'LONG', 'UNKNOWN'),
112, decode(charsetform, 1, 'CLOB', 2, 'NCLOB', 'UNKNOWN')) TYPES_USED_IN
from sys.col$ where charsetform in (1,2) and type# in (1, 8, 9, 96, 112)
order by CHARACTERSET, TYPES_USED_IN;

CHARACTERSET TYPES_USED_IN
---------------------------------------- -------------
AL16UTF16 NCHAR
AL16UTF16 NCLOB
AL16UTF16 NVARCHAR2
AL32UTF8 CHAR
AL32UTF8 CLOB
AL32UTF8 LONG
AL32UTF8 VARCHAR2

 In the alert log for the DMU we see

Sat Nov 22 16:39:57 2014
Updating character set in controlfile to AL32UTF8 
Synchronizing connection with database character set information 
Refreshing type attributes with new character set information 
Sat Nov 22 16:40:07 2014

==================

Step 9:

Now if you wanted to go back to the previous character set

WarningThis will make your database go back to restore point "before_change" and any change done after that will be lost, DO NOT PERFORM below steps if you wanted to character set conversion to AL32UTF8 (or Unicode), below steps are for reverting this characterset conversion back to before_change.


Flashback to restore point before_change: 

CONN / AS SYSDBA
SHUTDOWN IMMEDIATE
STARTUP MOUNT EXCLUSIVE <<<<<<<<<<<<<<<<<<<< Do not Miss this
FLASHBACK DATABASE TO RESTORE POINT before_change; <<<<< Do not Miss this
ALTER DATABASE OPEN RESETLOGS; <<<<<< Do not Miss this

Alert log entries shows:

Sat Nov 22 16:43:58 2014
Shutting down instance (immediate)
...
Completed: ALTER DATABASE CLOSE NORMAL
ALTER DATABASE DISMOUNT
...
Sat Nov 22 16:44:17 2014
Instance shutdown complete <<<<<<<<<<<<<<<<<<<
Sat Nov 22 16:44:23 2014
Starting ORACLE instance (normal)
Completed: ALTER DATABASE MOUNT <<<<<<<<<<<<<<<
Sat Nov 22 16:44:37 2014
FLASHBACK DATABASE TO RESTORE POINT before_change <<<<<<<<<
Flashback Restore Start
Flashback Restore Complete
Flashback Media Recovery Start
Serial Media Recovery started
Flashback Media Recovery Log /xxx/db/fast_recovery_area/ARC0000000002_0864316335.0001
Incomplete Recovery applied until change 1005827 time 11/22/2014 15:58:24
Flashback Media Recovery Complete
Completed: FLASHBACK DATABASE TO RESTORE POINT before_change <<<<<<<<<<<<<<<
Sat Nov 22 16:44:51 2014
ALTER DATABASE OPEN RESETLOGS
RESETLOGS after incomplete recovery UNTIL CHANGE 1005827
Archived Log entry 5 added for thread 1 sequence 4 ID 0xffb3bdae dest 1:
Archived Log entry 6 added for thread 1 sequence 5 ID 0xffb3bdae dest 1:
Archived Log entry 7 added for thread 1 sequence 6 ID 0xffb3bdae dest 1:
Clearing online redo logfile 1 /xxx/db/oradata/xxx/redo01.log
Clearing online log 1 of thread 1 sequence number 4
Sat Nov 22 16:44:55 2014
Time drift detected. Please check VKTM trace file for more details.
Clearing online redo logfile 1 complete
Clearing online redo logfile 2 /xxx/db/oradata/xxx/redo02.log
Clearing online log 2 of thread 1 sequence number 5
Clearing online redo logfile 2 complete
Clearing online redo logfile 3 /xxx/db/oradata/xxx/redo03.log
Clearing online log 3 of thread 1 sequence number 6
Clearing online redo logfile 3 complete
Resetting resetlogs activation ID 4289969582 (0xffb3bdae)
Online log /xxx/db/oradata/xxx/redo01.log: Thread 1 Group 1 was previously cleared
Online log /xxx/db/oradata/xxx/redo02.log: Thread 1 Group 2 was previously cleared
Online log /xxx/db/oradata/xxx/redo03.log: Thread 1 Group 3 was previously cleared
Sat Nov 22 16:44:57 2014
Setting recovery target incarnation to 3
Sat Nov 22 16:44:57 2014
Assigning activation ID 4290005226 (0xffb448ea)
LGWR: STARTING ARCH PROCESSES
Sat Nov 22 16:44:57 2014
ARC0 started with pid=21, OS id=25323
ARC0: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC0: STARTING ARCH PROCESSES
Sat Nov 22 16:44:58 2014
ARC1 started with pid=22, OS id=25325
Thread 1 opened at log sequence 1
Current log# 1 seq# 1 mem# 0: /xxx/db/oradata/xxx/redo01.log
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Sat Nov 22 16:44:58 2014
SMON: enabling cache recovery
Sat Nov 22 16:44:58 2014
ARC2 started with pid=23, OS id=25327
ARC1: Archival started
ARC2: Archival started
ARC1: Becoming the 'no FAL' ARCH
ARC1: Becoming the 'no SRL' ARCH
ARC2: Becoming the heartbeat ARCH
Sat Nov 22 16:44:58 2014
ARC3 started with pid=24, OS id=25329
[25321] Successfully onlined Undo Tablespace 2.
Undo initialization finished serial:0 start:612338964 end:612339324 diff:360 (3 seconds)
Dictionary check beginning
Dictionary check complete
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Updating character set in controlfile to WE8MSWIN1252 <<<<<< ALTER DATABASE OPEN RESETLOGS checks and corrects the cf to WE8MSWIN1252
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
LOGSTDBY: Validating controlfile with logical metadata
LOGSTDBY: Validation complete
ARC3: Archival started
ARC0: STARTING ARCH PROCESSES COMPLETE
Sat Nov 22 16:45:01 2014
Completed: ALTER DATABASE OPEN RESETLOGS <<<<<<<<<<<<

Now the database is opened with  WE8MSWIN1252 character set

Step 10:
check the data for the flashback user testing, which we actually dropped the table after the restore point, now it should show the data:

SQL> conn test/test
Connected.
SQL> select * from flash_test;

ID
----------
5

Step 11:
check the characterset should have been changed to old WE8MSWIN1252
and then run

conn / as sysdba
select parameter,value from NLS_DATABASE_PARAMETERS;

This now shows:
NLS_CHARACTERSET WE8MSWIN1252

select distinct(nls_charset_name(charsetid)) CHARACTERSET,
decode(type#, 1, decode(charsetform, 1, 'VARCHAR2', 2, 'NVARCHAR2','UNKNOWN'),
9, decode(charsetform, 1, 'VARCHAR', 2, 'NCHAR VARYING', 'UNKNOWN'),
96, decode(charsetform, 1, 'CHAR', 2, 'NCHAR', 'UNKNOWN'),
8, decode(charsetform, 1, 'LONG', 'UNKNOWN'),
112, decode(charsetform, 1, 'CLOB', 2, 'NCLOB', 'UNKNOWN')) TYPES_USED_IN
from sys.col$ where charsetform in (1,2) and type# in (1, 8, 9, 96, 112)
order by CHARACTERSET, TYPES_USED_IN;

CHARACTERSET TYPES_USED_IN
---------------------------------------- -------------
AL16UTF16 NCHAR
AL16UTF16 NCLOB
AL16UTF16 NVARCHAR2
WE8MSWIN1252 CHAR
WE8MSWIN1252 CLOB
WE8MSWIN1252 LONG
WE8MSWIN1252 VARCHAR2

======

Step 12:
to drop restore point:

SQL> select SCN, NAME from V$RESTORE_POINT;

SCN NAME
---------- --------------------
1005826 BEFORE_CHANGE

or use below query
select SCN, DATABASE_INCARNATION#, RESTORE_POINT_TIME,NAME from V$RESTORE_POINT;

and then drop 
DROP RESTORE POINT before_change;


http://www.ppmy.cn/news/61897.html

相关文章

Java设计模式-代理模式

简介 代理模式是一种结构型设计模式&#xff0c;它可以让我们通过一个代理对象来访问一个真实的目标对象&#xff0c;从而实现对目标对象的功能扩展或保护。代理模式的主要角色有三个&#xff1a; 抽象主题&#xff08;Subject&#xff09;&#xff1a;定义了真实主题和代理主…

工地烟火AI监控识别分析系统 yolov7

工地烟火AI监控识别分析系统通过yolov7网络模型技术&#xff0c;工地烟火AI监控识别分析系统对工地或者厂区现场监控区域内的烟火进行实时分析报警。YOLOv7 的发展方向与当前主流的实时目标检测器不同&#xff0c;研究团队希望它能够同时支持移动 GPU 和从边缘到云端的 GPU 设备…

惩治标题党,vue2监听父组件传过来的值,el-tree一键全选多个树形

vue2监听父组件传过来的值 父组件使用的动态组件&#xff0c;然后父传子 <component :is"checkedIt" :riskQuarterriskQuarter :riskYearriskYear></component> 子组件打印 console.log(riskQuarter :>> , this.$props.riskQuarter); 监听 pr…

vue前端开发100问(持续更新)

1.export default的作用是 export主要用于对外输出本模块变量的接口&#xff0c;一个文件就可以被理解为一个模块。export就是导出。 import就是在一个模块中加载另一个含有export接口的模块&#xff0c; import就是导入。 2.什么样的内容需要放在export default里面&#xf…

操作系统基础知识介绍之并行技术(包括指令级并行和数据级并行以及线程级并行和请求级并行)

一、相关概念 1.1 指令级并行 指令级并行是指在一个处理器内部&#xff0c;利用流水线、超标量、乱序执行等技术&#xff0c;使得多条指令可以同时或部分重叠地执行&#xff0c;从而提高指令的执行速度。比如&#xff0c;一个四级流水线可以同时执行四条指令的不同阶段&#…

const、指针、引用

一、const和指针&#xff1a; 分类&#xff1a; 1.1 指向常量的指针 上面的两种形式所表示的含义为&#xff1a;pt的指向可以随便修改&#xff0c;但pt所 指向的东西不得通过pt修改。 1.2 指向变量的常指针 指针的指向不允许改动&#xff0c;但指向的东西可以修改。&#…

【LeetCode】674. 最长连续递增序列

1. 问题 给定一个未经排序的整数数组&#xff0c;找到最长且连续递增的子序列&#xff0c;并返回该序列的长度。 连续递增的子序列 可以由两个下标 l 和 r&#xff08;l < r&#xff09;确定&#xff0c;如果对于每个 l < i < r&#xff0c;都有 nums[i] < nums[…

【R语言】鉴于计算10亿以内训练模型记录for循环的加速

文章目录 1 前言2 几个循环2.1 100以内的和2.2 100以内奇数和/偶数和 3 多重循环3.1 向量化3.2 合并循环3.3 apply函数3.4 矩阵运算3.5 foreach分解任务 4 讨论 1 前言 笔者主力机是MBAM1芯片&#xff08;8256&#xff09;&#xff0c;某个下午巩固循环突然思考到个问题&#…