在oracle10G之后;oracle提供一种回收站的机制;即闪回技术。闪回技术通常用于快速简单恢复数据库中出现的认为误操作等逻辑错误。发展到11G之后;回收站更加完善;对在可闪回时间内;数据库级别的恢复。
 
      postgresql本身未支持闪回技术的;目前没有像oracle闪回技术的功能;目前postgresql实现这种功能原理是:在drop table时;创建一个名为Trash的schema, 然后将被删除的表移动到这个schema下面.     
 
安装操作
su - root
git clone https://github.com/petere/pgtrashcan
cd pgtrashcan/
export PATH=/opt/pgsql/bin:$PATH             --根据环境来设定
make
make install

修改postgresql.conf文件

shared_preload_libraries = 'pgtrashcan'

在重新启动postgresql数据库

 
1.  drop table操作验证

mydb=> drop table t;
DROP TABLE
mydb=> \dn
  List of schemas
  Name  |  Owner
--------+----------
 Trash  | lottu
 public | postgres
(2 rows)

mydb=> \dt+ "Trash".t;
                    List of relations
 Schema | Name | Type  | Owner |    Size    | Description
--------+------+-------+-------+------------+-------------
 Trash  | t    | table | lottu | 8192 bytes |
(1 row)

mydb=> select * from "Trash".t;
 generate_series
-----------------
               1
               2
               3
               4
               5
               6
               7
               8
               9
              10
(10 rows)
可以看到;表T在被drop掉;postgres会新建一个Trash的模式;把表T移到这里。 假如环境配有hot standby;备库也会跟主库保持一致。
这样可以保证数据在被drop掉;在Trash下面有个复制。可以保证数据及时回复。
 
2. 清理回收站
   我们知道一个方案下;不能存放两个名字相同的表名;在确定里面其中表不需要恢复情况下。可以进行清理。

mydb=> \dt "Trash".*;
       List of relations
 Schema | Name | Type  | Owner
--------+------+-------+-------
 Trash  | t    | table | lottu
 Trash  | t8   | table | lottu
 Trash  | test | table | lottu
(3 rows)

--清理一个表;
mydb=> drop table "Trash".t;
DROP TABLE
mydb=> \dt "Trash".*;
       List of relations
 Schema | Name | Type  | Owner
--------+------+-------+-------
 Trash  | t8   | table | lottu
 Trash  | test | table | lottu
(2 rows)

--若确定所有表不需要恢复
mydb=> drop schema "Trash" cascade;
NOTICE:  drop cascades to 2 other objects
DETAIL:  drop cascades to table "Trash".t8
drop cascades to table "Trash".test
DROP SCHEMA

最新文章

  1. [bzoj3694]最短路
  2. Java开发中经典的小实例-(比较输入数值的最大值、最小值和平均值)
  3. Chart控件,把Y轴设置成百分比
  4. CSS Devices可以让你在线直接获取使用CSS写的Mobile外形。
  5. vs2010的11个调试技巧和方法
  6. Delegate 委托复习(-) 委托的基本概念
  7. JQuery验证工具
  8. 我是如何理解Java抽象类和接口的
  9. 使用apktool解包和打包apk
  10. java之集合类特性对比分析列表
  11. 【Python爬虫实战--3】html写正则表达式
  12. [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four
  13. win10 uwp 横向 AppBarButton
  14. 基于BootstarbTable实现加载更多的方式
  15. JavaScript中的this所引用的对象和如何改变这个引用
  16. k8s集群安装
  17. inode满处理
  18. 解决ERROR 1130: Host '192.168.11.1' is not allowed to connect to this MySQL
  19. 15LaTeX学习系列之---LaTeX里插入数学公式
  20. Linksys E 刷Tomato shibby

热门文章

  1. android-Activity(四大组件之一)
  2. JS分页方法
  3. Ajax请求中的Redirect()
  4. 利用logminer恢复delete误删除操作的数据
  5. sql语句的各种模糊查询
  6. iOS 导入第三方文件夹时右侧出现问号
  7. Android课程---寄存器与存储器的区别
  8. IOS彩票第二天设置界面(2)
  9. 关于JAVA中的String的使用与连接(转)
  10. angularjs - 415 (Unsupported Media Type)