Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore deleted records in PostgreSQL

I accidentally deleted all the records from 3 tables in PostgreSQL. How can i restore the data?

like image 409
v0ld3m0rt Avatar asked Nov 21 '13 05:11

v0ld3m0rt


People also ask

How do I undo a delete in PostgreSQL?

PostgreSQL ROLLBACK command is used to undo the changes done in transactions.

How do I undo in PostgreSQL?

The ROLLBACK command is the transactional command used to undo transactions that have not already been saved to the database. The ROLLBACK command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued.

What is Pg_restore in Postgres?

pg_restore is a utility for restoring a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats. It will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved.


1 Answers

This is a similar problem as discussed here:

Can I rollback a transaction I've already committed? (data loss)

Basically, restore from backup. If you can't, you might be able to recover with pg_dirtyread.

If you don't have backups, stop the whole server, take a disk image of the drive, and contact a $lots data recovery expert.

like image 181
Craig Ringer Avatar answered Sep 21 '22 16:09

Craig Ringer