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