我截断了一张桌子。如何取回数据? [英] I TRUNCATEd a table. How do I get the data back?

查看:79
本文介绍了我截断了一张桌子。如何取回数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,在我的postgesql数据库中,我截断了该表 mail_group ,并且该表已从数据库中删除,我该如何找回该表。

In my postgesql database, unfortunately I truncate this table mail_group, and the table is delete from the database, how to I get back this table.

请帮助我,等待回复。

谢谢

推荐答案




在相同情况下的任何其他人:立即使用 pg_ctl stop停止数据库-m立即立即很重要,您需要模拟崩溃并阻止检查点),然后不要重新启动它。。如果并发事务仍在进行中,您可能会很幸运,而PostgreSQL可能尚未为该表取消链接备份文件,因此它可以恢复。


Anyone else in the same situation: immediately stop your database with pg_ctl stop -m immediate (the immediate is important, you need to simulate a crash and prevent a checkpoint) then do not restart it.. If you had concurrent transactions still in progress you might be really lucky and PostgreSQL might not have unlinked the backing files for the table yet, so it could maybe be recoverable.

您很可能无法取回数据,因此将其删除。从备份中还原。

You very likely can't get the data back, you deleted it. Restore from a backup.

PostgreSQL中的常规 DELETE 将行标记为已删除,但实际上并未擦除数据立即,因此如果您立即停止数据库并且不向表中写入其他任何内容,通常可以将其恢复。

A normal DELETE in PostgreSQL marks the rows as deleted but does not actually erase the data immediately, so it can often be recovered if you promptly stop the database and you don't write anything else to the table.

TRUNCATE 并非如此。 TRUNCATE 从文件系统中删除代表数据库表的基础文件。

This is not the case for TRUNCATE. TRUNCATE deletes the underlying files that represent the database table from the file system.

在可能的情况下恢复数据所有这些都需要对您的硬盘进行取证分析。如果数据确实很重要,请立即关闭计算机电源,然后获取硬盘驱动器的磁盘映像。如果可能的话,预计恢复工作将花费数千美元,因为您将需要知道(a)文件系统内部知识和(b)PostgreSQL内部知识的人员。我能想到的唯一一个知道自己有能力做到这一点的人,这种工作所需的时间大概花费5000到10000欧元。 (不是我)。

Recovering the data, if possible at all, would require forensic analysis of your hard drive. If the data is truly important then power the computer off now and take a disk image of the hard drive. Expect recover work to cost multiple thousand dollars, if it is possible at all, since you will need someone who knows both (a) file system internals and (b) PostgreSQL internals. The only person I can think of who I know has the skills to possibly be able to do this would probably cost about €5000 to €10000 for the time required for this sort of work. (It isn't me).

如果您没有备份,那么您刚刚学到了非常昂贵的一课。

If you didn't have backups you have just learned a very expensive lesson.

如果其他人正在阅读此内容并删除 d行,请立即按照腐败,因为最初的恢复步骤是相同的​​。如果您运行 TRUNCATE

If someone else is reading this and DELETEd rows, please immediately follow the instructions in corruption since the first recovery steps are the same. This will not help if you ran TRUNCATE.

这篇关于我截断了一张桌子。如何取回数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆