Oracle10g中引入了闪回技术,但这并不意味着所有的表都能闪回成功,当没有足够的磁盘空间,Oracle将使用回收站中的磁盘空间,而且位图连接索引和引用完整性约束也不受回收站的保护。
recyclebin参数的设置
show parameter bin --展示是否使用了闪回技术,默认是使用闪回技术的
alter session set recyclebin=off; --在session级别修改
alter system set recyclebin=off DEFERRED; --不加DEFERRED参数是不允许修改的,但在session一级可以修改,与10g不同
显示回收站中被删除的表
show recyclebin
删除或清空回收站中的表
purge table table_name; --删除回收中的一张表
purge recyclebin; --清空回收
恢复被删除的表
flashback table table_name to before drop;
彻底删除表,不放进回收站
drop table table_name purge;
闪回错误的DML操作
在Oracle10g和11g中可以利用还原段中的数据进行恢复
设置还原段的保留时间
show parameter undo_retention --查看保留时间,默认是15分钟
alter system set undo_retention=7200; --修改保留时
下面以一个例子来进行说明
update myemp set sal=9999; --将myemp中的员工都变为9999
--通过version子句查询以往的事物操作信息,version_xid为事物号,minvalue为最小值,maxvalue为最大值
select versions_xid,empno,ename,sal from myemp versions between scn minvalue and maxvalue where empno=7900;
结果显示如下图,versions_xid为空,表明我们并未提交所做的DML操作
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXMAAABCCAIAAAAqiaF5AAAGA0lEQVR4nO2dy5HrOAxFFZcCYhzeTtUsuJlSEFNaTZUCcBDaKIQOgrPQh+AHlO1Gu1+rz6m3sGmZggDwChT9mt1ff/8Tdv4d/wsAAJ+mQ1kAwByUBQDsQVkAwB6UBQDsQVkAwB6UBQDsQVkAwB6UBQDsQVkAwB6UBQDsQVkAwB5VWfru1nW3rhunEMJy398Ozg3d9nr/199DCGEaK407vt/b3ej2jyaX9uPm4/j4UXpw7z9CCIsfsk+r/VfZjkxtdpNuT7x24ZDvI1574urZdbeuG/yyH7deWn8P0jld9GHbn6X/n7Sn0f9qata5ar/WPzxCbVxU/Z+NX4Mkb9Qss8vVYTvf4oc1Y0IIYbn3+2GyfXK343XWnmVG0ttxzK4yix9Eug/9bkPjvKeZ5/ubP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J7txiz2bJ3fT2uMmvlr7A+TbjC/3vr/Lfci34bEn7uSGvroz/HLvdxtk++TOt5r+8Wjxiru+t44/j9cXxL0EZbkmmcqILJldzJ50wIvRXm1/hExZtrfTmA2PzTz5OirInFUlieL8ArR4abF4Nl5fEfcSlOWKZGkh7kWLH45COs8kTXGeqREyZdlVoxge09j7j/XGKJWlnAft/VSmSJdFiZc2G3o2Xl8R9xKU5YLkU5J00B4j2SjDZtcp9dE0ilnPXl1vqje7XSZOa5b8Qn6BuFTjlZD4FmWBt1DPxQ05GxJz6aQqrrerHSb3z/jd+BhSPhQ8OpzmKbX2sVlPcrpfgKaz53HUMIr7CSjL5WjmRJY9TjwZPW9X8P3+lHG593HdJx8S8tlKpb1QljiT6izn/z8L6f/o57WoOfzQite6GJdqsVHc26AsV6OcCm0ru7XVRLGa+1C7xnF8nPJsZ1xFofwbq4Nf5GGjL1ed63+fVajMVXkkXrlqa/GqKYtd3BugLABgD8oCAPagLABgD8oCAPagLABgD8oCAPagLABgD8oCAPagLABgD8oCAPagLABgD8oCAPb8D7szXCCLNqb0AAAAAElFTkSuQmCC" alt="" />
commit; --提交再查询,结果如图:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYAAAABYCAIAAABzv7ceAAAHn0lEQVR4nO2dy5GzvBKGiYuAFIdD0I4gTrE6VQTgINgQwheE/gUXXejm4sFu43qemsWMRtM0rdaLLh5RhRD+1/4/AAB8nCogQABgBAIEAGYgQABgBgIEAGYgQABgBgIEAGYgQABgBgIEAGYgQABgBgIEAGYgQABgBgIEAGYgQABgBgIEAGYgQABgBgIEAGYgQABgBgIEAGaUAlRXj6p6VFXbhRCG5/xj41xTTd/PX/UzhBC6Viic8fVc7lo3/6pzuR3XL/Xjr/LKtf8XQhh8U/xWtC8y1cx9dp3uT7z3JCB2xHvPQt276lFVjR/meuOt1c+QBqeKMdyO5zr+J/3ZsD+6WhhX/dfswxGkfiHGv+i/Bkm+HgH1rhSRya3BN2NihRDC8Kzna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AZCBAAmIEAAYAZCBAAmIEAAYAZCBAAmIEAAYAZCBAAmIEAAYAZ/wHq4OMkm5P36QAAAABJRU5ErkJggg==" alt="" />
conn system/manager
select operation,START_SCN from flashback_transaction_query where xid=hextoraw('0A00020004050000'); --查找出事物随对应的SCN号
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX0AAABICAIAAACV27KsAAAFeElEQVR4nO3dQY6jOBiGYc7lA/kcaDajkWbhTYtDjFiN5APkEGw4Qm1yg78XGGyD7ZAp+LujeR/1otpFjBPZH8akoPvjT/d8Pp/P519//5DVP+O/AgD36MgdAMrIHQDayB0A2sgdANrO5o63fdf1Xdd35rEVOrMWdn3X9cZ9icjshrQwvsSPhUIRkckWCkv1dIOb88Ys/+zUaOdSsm9bsiPgcnFo2NGah7T6c7n/18ZLY1y81Z6wk2S8zG6wXmm8nModb+PYnt2QR8bo43sL7392w9JuEZH5YZKPbCv3to/brJt5Gz/BbWNve+uz+o+1tdvp7WDM2s6kPcAddv28W3On1Z8P/f9Yz5YF7XFxsj1yHC9dqFBhvJzIncOOtze8y50lLyW+z8nmL9znUTJPCa/14y5K8t1l9rlTb6e3g3Nj+IjJHdzseERMFftzsf83xkutnjfac6gwqfn28fI6dwqNjp9Odb5TnJ6lVTmTfWou5Os+quR07jTauRxGwsGE3MH94nnNuf5c7P+N8VKr5432lI7xa823j5fv585+fUea853jxkuF23zv+GlelTvhEyR3oChflxAp9udK/6+Ol1o9b7XnVe7cOl6uPM+Kr6jMM2O5H7vkhY11YrnqPGudiFlH7kDTfowUj6zF/l8bL7V63mtPPVAUxsuV68qbXSKsc8isfHbDWud+WrRtv+39VO4015XXhbfJcjEL95psly8YvziOVvt/ZbzU6nm7Pfm1ncl2++P0fePlquvo2XWow3W+0UtyXXCtYXm5KV9THNy8q+rU/Kh2HT3OVP1I7uBO2eJDfWisk45a/3el8VK4JF848J9sj+RfhVlDR2O88L1BANrIHQDayB0A2sgd4PPFdaLS0urvh9wBoI3cAaCN3AGgjdwBoI3cAaCN3AGgjdwBoI3cAaCN3AGg7Uzu7P6edfsSJOWU/x/Ka363dv6qz+G/YL4DQBu5A0AbuQNAG7kDQBu5A0AbuQNAG7kDQBu5A0AbuQNAG7kDQBu5A0AbuQNA2+vcSZ9bGh+Qah5L+fIw07Q8/Tk+XqO+/W4va0n2wOL4jGM7tesBPlHaq4/lS88/Uy6SDJbk7zm35xHvdlErb9V/hVPzneQ57ZI+Rt7bwazPkJf5Ydby2Q3bE+O9jU2vbZ9uM7shhIgfD59RaEatHuATzW7o7HTs8Omzyb1NoqFWHo7E+z8fT7aZ7Poc9EZ5o/6rfDd3nBtDZJRyx5ksL8vbH4LD2956kflh7LRUsrxzt2ZNbb/ABzvkTnr8TsddrfzMWMhfWy6v1n+db+fOvP52nzuTLUzeCtvPbjjGvHFf6waTNYMNP7zYL/DBmvOdbCJTLzd2NOkCxV4tRPLyWv3XuSB3wsjPc6freuvjVKWxfTV3lh350bgvZwY3v94v8MGOuZOvYG7z/Vr5UhgqOY6L+WHSk6lmeW2/V3k/d7J1mVA+u8G68vpO2ujy9rXzLBFnRmt762V2g7GjSdaJivsFPlgpdxKvpypxbVREkvXQ8KvSDKhWfmK/33Iqd8K61+HnJI8mm1xUys4P/fhy+/K6sogz6/rx/DDJWVutHuCDNXNnOxi3y53Z/pueH5THSK38zH6/6ez3dw7XubPr6yLxnPBwbTtEQ237Wv2S59F2ytauB/g4sfPvhkC8Ip5fz66Vi6R3Rw55sX2X5WT5i/qvwfcGAWgjdwBoI3cAaCN3AGgjdwBoI3cAaCN3AGgjdwBoI3cAaOO+X8Cvx32/RLjvF6CI+34F3PcL0MZ9v7jvF6CN+35x3y9AG/f94r5fgDbu+8V9vwBt3PeL+34BarjvV8D3BgHch9wBoI3cAaCN3AGgjdwBoI3cAaCN3AGgjdwBoO0nq0zMqyZX+GAAAAAASUVORK5CYII=" alt="" />
---不知道为什么表中显示状态为unknown,按理应该是UPDATE的。
alter table scott.myemp enable row movement; --开启表的行移动功能
flashback table scott.myemp to SCN 1996229; --恢复操作完成
也可以按照时间点恢复
flashback table scott.myemp to timestamp to_timestamp('15:36','hh24:mi');