0

Truncate table tablename;

How to recover it back in dbeaver

Ramesh
  • 251
  • 2
  • 4
  • 12

2 Answers2

1

You cannot. See doc: http://www.postgresql.org/docs/9.1/static/sql-truncate.html

It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables.

The space is returned to OS, it could be occupied by new data etc.

rouen
  • 5,003
  • 2
  • 25
  • 48
  • If you're desperate enough you could attempt standard deleted file recovery techniques. If you were able to recover the file, you could try "plumbing it back into" the catalog and you might be able to read most of it, depending on how much had recovered as well as some other considerations. – Jim Nasby May 16 '16 at 17:13
1

Tuncate uses file-level operations to delete the data, and this has a number of implications:

  1. On commit you cannot recover
  2. This is not MVCC safe. In other words, other concurrent transactions see the table as empty despite transaction isolation levels that should let them see the old rows.

This means you basically have to recover from backup and this is a great case to use to warn that backups are about more than hardware failure. They are also there in case of administrator error (and that is why replication is not a backup).

Chris Travers
  • 25,424
  • 6
  • 65
  • 182