I TRUNCATEd a table. How do I get the data back?

馋奶兔 提交于 2019-12-24 04:51:15

问题


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.

Kindly help me, waiting for reply.

Thanks


回答1:



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.

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.

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

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.


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.



来源:https://stackoverflow.com/questions/28321999/i-truncated-a-table-how-do-i-get-the-data-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!