0

I am using Postgres. It seems very easy to accidentally delete all of a table's data.

For example, I tried to delete one table row and accidentally deleted the whole table contents. This is no problem; the table contained mock data. However, the tables that I create in the future will contain important data.

Example of very easy deletion:

polls_db=# DELETE from polls_choice;
DELETE 8

Is there an easy way in Postgres to restore table data, or to soft delete table data whereby the data can be easily restored?

4
  • 3
    You can create a role on db server with NO permission to delete operations and assign that role to a user and use that user only to perform actions. Commented Apr 23, 2019 at 16:11
  • Another thing that will help is not to run SQL statements by hand. Commented Apr 23, 2019 at 16:46
  • 3
    Make it a habit to always run begin; before running any dml statements directly Commented Apr 23, 2019 at 16:58
  • Related: How to rollback an update in PostgreSQL Commented Apr 23, 2019 at 17:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.